There's a handy module called
SelfLoader in the perl core, which lets you hide functions in the DATA section and load them on demand:
#!/usr/bin/perl
#sloader
use SelfLoader;
foobar();
__DATA__
sub foobar {
print "foobar!\n";
}
Alas, there seems to be a bug with it. If you call the script above from another script via exec and close STDIN, as in
#!/usr/bin/perl
#sloader-exec
close(STDIN);
exec "./sloader";
it fails:
main doesn't contain an __DATA__ token at ./sloader line 5
Anyone seen this before?