rschupp / PAR-Packer

(perl) Generate stand-alone executables, perl scripts and PAR files https://metacpan.org/pod/PAR::Packer
Other
48 stars 13 forks source link

PAR should provide empty `caller()` to the script #51

Closed mik2 closed 3 years ago

mik2 commented 3 years ago

It is a common trick to use a module also as a script by checking caller() to be false in scalar context. Such a script when packaged with PAR will behave as a module because caller() will return PAR, which is different from running the script without packaging. A workaround is to test caller() to be empty or PAR, but this requires modification of the original script. A method used in Call::From could be used to fake the script as being run in top level (so that caller() returns an empty string).

rschupp commented 3 years ago

It is a common trick to use a module also as a script by checking caller() to be false in scalar context. Such a script when packaged with PAR will behave as a module because caller() will return PAR, which is different from running the script without packaging.

Don't do that then. Just pack a oneliner instead of the original script-or-module.