Commit | Line | Data |
---|---|---|
c07656ed FC |
1 | #!perl |
2 | ||
39075fb1 FC |
3 | BEGIN { |
4 | chdir 't'; | |
4b473a5a | 5 | @INC = '../lib'; |
39075fb1 FC |
6 | require './test.pl'; |
7 | *bar::is = *is; | |
8 | } | |
4b473a5a FC |
9 | no warnings 'deprecated'; |
10 | plan 19; | |
c07656ed FC |
11 | |
12 | { | |
13 | our sub foo { 42 } | |
39075fb1 FC |
14 | is foo, 42, 'calling our sub from same package'; |
15 | is &foo, 42, 'calling our sub from same package (amper)'; | |
4b473a5a | 16 | is do foo(), 42, 'calling our sub from same package (do)'; |
c07656ed FC |
17 | package bar; |
18 | sub bar::foo { 43 } | |
39075fb1 FC |
19 | { local $::TODO = ' '; |
20 | is foo, 42, 'calling our sub from another package'; | |
21 | } | |
22 | is &foo, 42, 'calling our sub from another package (amper)'; | |
4b473a5a | 23 | is do foo(), 42, 'calling our sub from another package (do)'; |
c07656ed FC |
24 | } |
25 | package bar; | |
39075fb1 FC |
26 | is foo, 43, 'our sub falling out of scope'; |
27 | is &foo, 43, 'our sub falling out of scope (called via amper)'; | |
4b473a5a | 28 | is do foo(), 43, 'our sub falling out of scope (called via amper)'; |
c07656ed FC |
29 | package main; |
30 | { | |
31 | sub bar::a { 43 } | |
32 | our sub a { | |
33 | if (shift) { | |
34 | package bar; | |
39075fb1 FC |
35 | is a, 43, 'our sub invisible inside itself'; |
36 | is &a, 43, 'our sub invisible inside itself (called via amper)'; | |
4b473a5a | 37 | is do a(), 43, 'our sub invisible inside itself (called via do)'; |
c07656ed FC |
38 | } |
39 | 42 | |
40 | } | |
41 | a(1); | |
42 | sub bar::b { 43 } | |
43 | our sub b; | |
44 | our sub b { | |
45 | if (shift) { | |
46 | package bar; | |
39075fb1 FC |
47 | { local $::TODO = ' '; |
48 | is b, 42, 'our sub visible inside itself after decl'; | |
49 | } | |
50 | is &b, 42, 'our sub visible inside itself after decl (amper)'; | |
4b473a5a | 51 | is do b(), 42, 'our sub visible inside itself after decl (do)'; |
c07656ed FC |
52 | } |
53 | 42 | |
54 | } | |
55 | b(1) | |
56 | } | |
57 | sub c { 42 } | |
58 | sub bar::c { 43 } | |
59 | { | |
60 | our sub c; | |
61 | package bar; | |
39075fb1 FC |
62 | { local $::TODO = ' '; |
63 | is c, 42, 'our sub foo; makes lex alias for existing sub'; | |
64 | } | |
65 | is &c, 42, 'our sub foo; makes lex alias for existing sub (amper)'; | |
4b473a5a | 66 | is do c(), 42, 'our sub foo; makes lex alias for existing sub (do)'; |
c07656ed FC |
67 | } |
68 | { | |
69 | our sub d; | |
c07656ed FC |
70 | sub bar::d { 'd43' } |
71 | package bar; | |
945534e1 | 72 | sub d { 'd42' } |
39075fb1 | 73 | { local $::TODO = ' '; |
945534e1 | 74 | is eval { ::d },'d42', 'our sub foo; applies to subsequent sub foo {}'; |
39075fb1 | 75 | } |
c07656ed | 76 | } |