Modules that you use can execute code
Exactly; and the code they execute may not be immediately obvious.
#!/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__
Just imagine what chaos one could foment if you changed that to (say) rot13 the prefix before picking what to run, or generated the prefix based on the phase of the moon . . . :)
The cake is a lie.
The cake is a lie.
The cake is a lie.
In reply to Re^2: Scripts with only sub-routines?
by Fletch
in thread Scripts with only sub-routines?
by kehansen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |