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