in reply to Testing a .pl script

You can do something like this:

sub main { until (should_stop()) { # code goes here } } main unless caller;
This way the main sub will be called only if the script is called directly and not if it is included in a test through require "script.pl".

Replies are listed 'Best First'.
Re^2: Test automation
by perl_help26 (Beadle) on Jul 01, 2015 at 14:46 UTC
    Suppose we are running the script from crontab, will that be considered as a caller?

      caller only knows about callers in the same perl process. So do or require will not trigger a main call, while cron, or even system "perl script.pl"; will.

        Thank you