Yitzchak Scott-Thoennes wrote:
I'd make that just:
sub main { ...the program using the functions below... }
main() unless caller;
sub some_function { ... }
sub some_other_function { ... }
Nice trick. I just tested it.
[EMAIL PROTECTED] ~/test] cat foo.pl #!/usr/bin/perl -w use strict;
my @caller = caller(); print @caller . "caller='@caller'\n";
main() unless caller;
sub main { print "main!\n"; print "2 + 2 = " . add( 2, 2 ), "\n"; }
sub add { return $_[0] + $_[1]; }
[EMAIL PROTECTED] ~/test] cat bar.pl #!/usr/bin/perl -w use strict;
do "foo.pl";
print "4 + 4 = " . add( 4, 4 ), "\n";
[EMAIL PROTECTED] ~/test] ./foo.pl 0caller='' main! 2 + 2 = 4 [EMAIL PROTECTED] ~/test] ./bar.pl 3caller='main ./bar.pl 5' 4 + 4 = 8
In other words, caller does work the way you claim in code execute with 'do'. And "main() unless caller" as an idiom definitely feels right. Good! I can finally abandon this silly notion of executable modules. Would have just confused my co-workers.
Tangentially... is this a bug:
[EMAIL PROTECTED] ~/cpan/Parallel-Simple] prove t/
t/Parallel-Simple....Undefined subroutine &main::prun called at t/Parallel-Simple.t line 22.
# Looks like your test died before it could output anything.
t/Parallel-Simple....dubious
Test returned status 255 (wstat 65280, 0xff00) DIED. FAILED test 1 Failed 1/1 tests, 0.00% okay Failed Test Stat Wstat Total Fail Failed List of Failed ------------------------------------------------------------------------------- t/Parallel-Simple.t 255 65280 1 2 200.00% 1 Failed 1/1 test scripts, 0.00% okay. 1/1 subtests failed, 0.00% okay.
I know what I did wrong. I forgot -l, so it wasn't finding and loading my Parallel::Simple module properly. I fixed that already. What strikes me as a possible bug is the fact that Test::Harness reports 1 total test, but 2 failures - hence 200% failed.
Lastly, how come use_ok( 'Parallel::Simple' ) didn't bitch at me?
-ofer