Problems with Perl -d and modulino

I have some scripts that I started with unit testing using the idea of โ€‹โ€‹"modulino". I ran into a problem in that when the script is called with "perl -d" the script is not executed, since caller () returns the true value.

I have the main part of the script wrapped in main (), and some routines are slowly pulled from main () into their own routines.

At the top of the script, I have:

main(@ARGS) unless caller(); 

When called in .t tests, it works the way I want, and main () does not work, so I can test the routines. When I call a script from the CLI, it works fine with a call to main ().

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

 perl -d myscript.pl 

At this point, the caller returns a valid value (rather than undef), and main is not called.

Suggestions would be greatly appreciated on how to approach this.

+8
debugging perl modulino
source share
1 answer

The situation with the -d switch is similar to the testing situation - your code is executed by something else, in this case the debugger.

You can run main yourself by calling it in the debugger manually or you need to determine if caller debugger. Something like:

 main(@ARGS) if !caller() || (caller)[0] eq 'DB'; 
+8
source share

All Articles