Commit | Line | Data |
---|---|---|
446db2c1 RGS |
1 | #!./perl -w |
2 | ||
3 | BEGIN { | |
4 | chdir 't' if -d 't'; | |
446db2c1 | 5 | require './test.pl'; |
624c42e2 | 6 | set_up_inc('../lib'); |
446db2c1 RGS |
7 | } |
8 | ||
624c42e2 N |
9 | plan( tests => 8 ); |
10 | ||
446db2c1 RGS |
11 | use strict; |
12 | ||
13 | # first, with delete | |
14 | # simple removal | |
15 | sub removed { 23 } | |
16 | sub bound { removed() } | |
17 | delete $main::{removed}; | |
18 | is( bound(), 23, 'function still bound' ); | |
19 | ok( !main->can('removed'), 'function not available as method' ); | |
20 | ||
21 | # replacement | |
22 | sub replaced { 'func' } | |
23 | is( replaced(), 'func', 'original function still bound' ); | |
24 | is( main->replaced, 'meth', 'method is replaced function' ); | |
25 | BEGIN { delete $main::{replaced} } | |
26 | sub replaced { 'meth' } | |
27 | ||
28 | # and now with undef | |
29 | # simple removal | |
30 | sub removed2 { 24 } | |
31 | sub bound2 { removed2() } | |
a65cc145 | 32 | { no strict; undef *{"removed2"} } |
446db2c1 RGS |
33 | eval { bound2() }; |
34 | like( $@, qr/Undefined subroutine &main::removed2 called/, | |
35 | 'function not bound' ); | |
36 | ok( !main->can('removed2'), 'function not available as method' ); | |
37 | ||
38 | # replacement | |
39 | sub replaced2 { 'func' } | |
40 | is( replaced2(), 'meth', 'original function not bound, was replaced' ); | |
41 | ok( main->replaced2 eq 'meth', 'method is replaced function' ); | |
42 | BEGIN { undef $main::{replaced2} } | |
43 | sub replaced2 { 'meth' } |