Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Modulino, perl -d question.

by lwicks (Pilgrim)
on Feb 20, 2012 at 17:10 UTC ( #955101=perlquestion: print w/replies, xml ) Need Help??

lwicks has asked for the wisdom of the Perl Monks concerning the following question:


I have some scripts that I have started unit-testing using the "modulino" idea. I have encountered a problem in that when the script is called with "perl -d" the script does not run as caller() returns a true value.

I have the main body of the script wrapped in a main() and some subroutines being slowly pulled out of the main() into their own subroutines.

At the top of the script I have:

main(@ARGS) unless caller();
When called in .t tests it works as I want, not running main() so I can test the subroutines. When I call the script from CLI it works great calling main().

The problem occurs when I call it from the CLI with:

perl -d
At this stage caller returns a valid value (rather than undef) and main is not called. :-(

Suggestions would be much appreciated about how to approach this one.


Kia Kaha, Kia Toa, Kia Manawanui!
Be Strong, Be Brave, Be perservering!

Replies are listed 'Best First'.
Re: Modulino, perl -d question. ($0, __FILE__)
by tye (Sage) on Feb 20, 2012 at 17:21 UTC
Re: Modulino, perl -d question.
by LanX (Sage) on Feb 20, 2012 at 18:35 UTC
    >At this stage caller returns a valid value (rather than undef) and main is not called. :-(

    Not reproducable, for me caller is equally false, when run under the debugger.

    I'm not sure what you want to debug ... main() or your test suite?

    IMHO there are good reasons for both cases.

    So maybe you should explicitly check if you are running under the debugger, eg. by checking if &DB::DB is defined.

    like that you can provide a run argument to decide which branch exactly should be debugged.

    Cheers Rolf

Re: Modulino, perl -d question.
by repellent (Priest) on Feb 20, 2012 at 18:43 UTC
    main() is still called for me under perl -d:
    $ cat #!/usr/bin/perl use warnings; use strict; sub main { warn "called main" } main() unless caller(); $ perl -e ' do "" ' $ perl -e ' require "" ' $ ./ called main at ./ line 6. $ perl -d Loading DB routines from version 1.3 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::( main() unless caller(); DB<1> c called main at line 6. at line 6 main::main() called at line 7 Debugged program terminated. Use q to quit or R to restart, use o inhibit_exit to avoid stopping after program termination, h q, h R or h o to get additional info. DB<1> q
Re: Modulino, perl -d question.
by choroba (Archbishop) on Feb 20, 2012 at 17:24 UTC
    What value does caller return when run with perl -d?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://955101]
Approved by McDarren
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2021-11-28 03:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found