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