]> git.vpit.fr Git - perl/modules/with.git/blob - t/10-with.t
Importing with-0.01
[perl/modules/with.git] / t / 10-with.t
1 #!perl -T
2
3 package main;
4
5 use strict;
6 use warnings;
7
8 use Test::More 'no_plan';
9
10 use lib 't/lib';
11 use with::TestClass;
12
13 my $tc;
14 BEGIN { $tc = 'with::TestClass' }
15
16 sub foo { is($_[0], __PACKAGE__, __PACKAGE__ . '::foo was called'); }
17 sub baz { is($_[0], __PACKAGE__, __PACKAGE__ . '::baz was called'); }
18
19 my %cbs;
20 # "use with \with::TestClass->new(id => 2, %cbs)" forces the evaluation of %cbs
21 # at compile time for constant folding, so we must define it in a BEGIN block.
22 BEGIN { %cbs = (is => \&Test::More::is); }
23
24 my $o1 = new with::TestClass id => 1, %cbs;
25
26
27 foo 'main', 0;
28 {
29  use with \$o1;
30  foo $tc, 1;
31  bar($tc, 1);
32  {
33   foo $tc, 1;
34   use with \with::TestClass->new(id => 2, %cbs);
35
36   foo
37     $tc,
38     "2";
39   bar $tc, 2;
40   main::foo 'main', 2;
41   my $ref = \&foo;
42   $ref->('main', 2);
43  
44   no with;
45   foo 'main', 0; 
46  }
47
48
49
50  foo $tc, q{1};bar $tc,
51                    '1';
52
53
54
55  baz 'main', 1;
56
57 }
58 foo 'main', 0;
59 eval { bar 'main', 0 };
60 ok($@, 'wrong call croaks');