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

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:

Hi,

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 myscript.pl
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.

Thanks.

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

Comment on Modulino, perl -d question.
Select or Download Code
Re: Modulino, perl -d question. ($0, __FILE__)
by tye (Cardinal) on Feb 20, 2012 at 17:21 UTC
Re: Modulino, perl -d question.
by choroba (Abbot) on Feb 20, 2012 at 17:24 UTC
    What value does caller return when run with perl -d?
Re: Modulino, perl -d question.
by LanX (Canon) 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 t3.pl #!/usr/bin/perl use warnings; use strict; sub main { warn "called main" } main() unless caller(); $ perl -e ' do "t3.pl" ' $ perl -e ' require "t3.pl" ' $ ./t3.pl called main at ./t3.pl line 6. $ perl -d t3.pl Loading DB routines from perl5db.pl version 1.3 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(t3.pl:7): main() unless caller(); DB<1> c called main at t3.pl line 6. at t3.pl line 6 main::main() called at t3.pl 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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-08-28 01:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (255 votes), past polls