# in Alpha.pm sub sayhowdy { my $self = shift; my $string = q{}; open my $fh, ">", \$string; print $fh "Howdy, alpha\n"; close $fh; return $string; } # in Beta.pm sub sayhowdy { my $self = shift; my $string = q{}; open my $fh, ">", \$string; print $fh "Howdy, beta\n"; close $fh; return $string; } #### *Alpha::sayhowdy = \&sayhowdy if ! defined &Alpha::sayhowdy; #### use Test::More qw( no_plan); use_ok( q{Alpha} ); my $class = q{Alpha}; my $self = $class->new(); isa_ok($self, $class); can_ok($class, q{sayhowdy} ); is($self->sayhowdy(), qq{Howdy, alpha\n}, "alpha sayhowdy okay"); undef &Alpha::sayhowdy; eval { $self->sayhowdy(); }; like($@, qr/^Undefined subroutine &Alpha::sayhowdy called/, "Alpha::sayhowdy() is now undefined"); require_ok('Beta'); is($self->sayhowdy(), qq{Howdy, beta\n}, "Beta::sayhowdy is now Alpha::sayhowdy"); #### [Alpha] 539 $ prove -vb t/03_gamma.t t/03_gamma....ok 1 - use Alpha; ok 2 - The object isa Alpha ok 3 - Alpha->can('sayhowdy') ok 4 - alpha sayhowdy okay ok 5 - Alpha::sayhowdy() is now undefined ok 6 - require Beta; ok 7 - Beta::sayhowdy is now Alpha::sayhowdy 1..7 ok All tests successful. Files=1, Tests=7, 0 wallclock secs #### $ cover -delete $ make test HARNESS_PERL_SWITCHES=1 $ cover cover_db --report=txt > coverage.txt # in the section of coverage.txt reporting on lib/Beta.pm: # (for simplicity, displaying only statement coverage) blib/lib/Beta.pm line err stmt code 1 package Beta; 2 #$Id# 3 2 use strict; # [snip] 16 2 print $fh "Howdy, beta\n"; 17 2 close $fh; 18 2 return $string; 19 } 20 21 *Alpha::sayhowdy = \&sayhowdy if ! defined &Alpha::sayhowdy; 22 23 1;