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 | 9 | no warnings 'deprecated'; |
f37b842a | 10 | plan 22; |
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 } | |
18f70389 | 19 | is foo, 42, 'calling our sub from another package'; |
39075fb1 | 20 | is &foo, 42, 'calling our sub from another package (amper)'; |
4b473a5a | 21 | is do foo(), 42, 'calling our sub from another package (do)'; |
c07656ed FC |
22 | } |
23 | package bar; | |
39075fb1 FC |
24 | is foo, 43, 'our sub falling out of scope'; |
25 | is &foo, 43, 'our sub falling out of scope (called via amper)'; | |
4b473a5a | 26 | is do foo(), 43, 'our sub falling out of scope (called via amper)'; |
c07656ed FC |
27 | package main; |
28 | { | |
29 | sub bar::a { 43 } | |
30 | our sub a { | |
31 | if (shift) { | |
32 | package bar; | |
39075fb1 FC |
33 | is a, 43, 'our sub invisible inside itself'; |
34 | is &a, 43, 'our sub invisible inside itself (called via amper)'; | |
4b473a5a | 35 | is do a(), 43, 'our sub invisible inside itself (called via do)'; |
c07656ed FC |
36 | } |
37 | 42 | |
38 | } | |
39 | a(1); | |
40 | sub bar::b { 43 } | |
41 | our sub b; | |
42 | our sub b { | |
43 | if (shift) { | |
44 | package bar; | |
18f70389 | 45 | is b, 42, 'our sub visible inside itself after decl'; |
39075fb1 | 46 | is &b, 42, 'our sub visible inside itself after decl (amper)'; |
4b473a5a | 47 | is do b(), 42, 'our sub visible inside itself after decl (do)'; |
c07656ed FC |
48 | } |
49 | 42 | |
50 | } | |
51 | b(1) | |
52 | } | |
53 | sub c { 42 } | |
54 | sub bar::c { 43 } | |
55 | { | |
56 | our sub c; | |
57 | package bar; | |
18f70389 | 58 | is c, 42, 'our sub foo; makes lex alias for existing sub'; |
39075fb1 | 59 | is &c, 42, 'our sub foo; makes lex alias for existing sub (amper)'; |
4b473a5a | 60 | is do c(), 42, 'our sub foo; makes lex alias for existing sub (do)'; |
c07656ed FC |
61 | } |
62 | { | |
63 | our sub d; | |
c07656ed FC |
64 | sub bar::d { 'd43' } |
65 | package bar; | |
945534e1 | 66 | sub d { 'd42' } |
4210d3f1 | 67 | is eval ::d, 'd42', 'our sub foo; applies to subsequent sub foo {}'; |
c07656ed | 68 | } |
60ac52eb FC |
69 | { |
70 | our sub e ($); | |
71 | is prototype "::e", '$', 'our sub with proto'; | |
72 | } | |
18f70389 | 73 | { |
18f70389 FC |
74 | our sub if() { 42 } |
75 | my $x = if if if; | |
f37b842a FC |
76 | is $x, 42, 'lexical subs (even our) override all keywords'; |
77 | package bar; | |
78 | my $y = if if if; | |
79 | is $y, 42, 'our subs from other packages override all keywords'; | |
18f70389 | 80 | } |