1. Running as a script or module
In Python and Ruby, the introductory texts include examples of how to create program files that can be both used as a script or as a module. Being able to use a program as a module makes writing unit tests easier. Eric Wilhelm posted the something similar in a bit of code once, which demonstrates how to do it in Perl:
package main;
if($0 eq ($ENV{PAR_ARGV_0} || __FILE__)) {
bin::hello::main(@ARGV);
}
package bin::hello;
sub main {
# Whatever happens in main
}
