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