]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/33-code.t
Importing Variable-Magic-0.04.tar.gz
[perl/modules/Variable-Magic.git] / t / 33-code.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 10;
7
8 use Variable::Magic qw/wizard cast dispell/;
9
10 my @c = (0) x 5;
11 my @x = (0) x 5;
12
13 sub check {
14  for (0 .. 4) { return 0 unless $c[$_] == $x[$_]; }
15  return 1;
16 }
17
18 my $i = -1;
19 my $wiz = wizard get   => sub { ++$c[0] },
20                  set   => sub { ++$c[1] },
21                  len   => sub { ++$c[2] },
22                  clear => sub { ++$c[3] },
23                  free  => sub { ++$c[4] };
24 ok(check(), 'code : create wizard');
25
26 my $x = 0;
27 my $n = sub { ++$x };
28 my $a = $n;
29
30 cast $a, $wiz;
31 ok(check(), 'code : cast');
32
33 my $b = $a;
34 ++$x[0];
35 ok(check(), 'code : assign to');
36
37 $b = "X${a}Y";
38 ++$x[0];
39 ok(check(), 'code : interpolate');
40
41 $b = \$a;
42 ok(check(), 'code : reference');
43
44 $a = $n;
45 ++$x[1];
46 ok(check(), 'code : assign');
47
48 $a->();
49 ok(check(), 'code : call');
50
51 {
52  my $b = $n;
53  cast $b, $wiz;
54 }
55 ++$x[4];
56 ok(check(), 'code : scope end');
57
58 undef $a;
59 ++$x[1];
60 ok(check(), 'code : undef');
61
62 dispell $a, $wiz;
63 ok(check(), 'code : dispell');