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