http://www.perlmonks.org?node_id=664612


in reply to conditional self-execution

What you're describing sounds to me like a modulino.

Update: In a nutshell, the way it's done is something like this:

package Foo; _run( @ARGV ) if ! caller; sub _run { # Do stuff as a program }

It's using caller to tell whether it's being executed "at the top level". If you search for modulino on CPAN, there are a few examples to look at.