How to write a test in Perl to check if my file was run directly or imported from another source? I would like to do this to make it easier to combine everything into one file, but still write unit tests against functions. My idea is to have something like this:
if (running_directly()) {
main();
}
def main {
this();
that();
}
def this {
}
def that {
}
Then, in a separate perl script, I can load the source file and call it as unit tests.
I remember how it was done before, but I don’t remember how to do it. I would like to avoid checking $ 0 for some known value, because this means that the user cannot rename the script.
source
share