#!/usr/bin/perl use strict; use warnings; use EndRunner qw( foo ); sub foo_one { print "Foo one called!\n"; } sub foo_two { print "Foo two called\n"; } sub foo_dies { die "Aieee!\n"; } our $foo_bad_example = "no problem here"; __END__ ## This would go in EndRunner.pm package EndRunner; use strict; use warnings; our @ISA = qw( Exporter ); require Exporter; my @packages_to_run; sub import { my( $package, @args ) = @_; my $caller_package = ( caller( 1 ) )[0]; for my $prefix ( @args ) { push @packages_to_run, [ $caller_package, $prefix ]; } return; } END { no strict 'refs'; for my $items ( @packages_to_run ) { my( $package, $prefix ) = @{ $items }; for my $sub ( grep /^${prefix}_/, keys %{ $package . "::" } ) { my $sub_ref = *{"${package}::$sub"}{CODE}; next unless defined $sub_ref; eval { $sub_ref->(); }; if( $@ ) { warn "EndRunner: problem calling '$sub' in $package: $@\n"; } } } } 1; __END__