Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: debugging during compile

by Perlbotics (Archbishop)
on Aug 17, 2011 at 22:02 UTC ( [id://920807]=note: print w/replies, xml ) Need Help??


in reply to debugging during compile

You can avoid editing all those modules by adding a hook into @INC as documented in require:

#!/usr/bin/perl -w -T # install a 'hook' into @INC / see: perldoc -f require BEGIN { unshift @INC, '.'; # replaces 'use lib(.);' unshift @INC, sub { printf "***** TRACE: use %-20s with ARGV=%s\n", $_[1], join(', ', @ARGV); return; }; } BEGIN { print 'before using my module: '.join(', ',@ARGV)."\n" } #use lib qw(.); # removed: would shift hook to 2nd position, disabling + tracing use Module; # modified: sub import { shift @ARGV; } use Module2; # just a copy of the unmodified Module.pm BEGIN { print 'after using my module: '.join(', ',@ARGV)."\n" } __END__ > ./script.pl a b c before using my module: a, b, c ***** TRACE: use Module.pm with ARGV=a, b, c beginning my module1: a, b, c ending my module1: a, b, c ***** TRACE: use Module2.pm with ARGV=b, c beginning my module2: b, c ending my module2: b, c after using my module: b, c

If you have several modules, you could at least narrow the problem down to two candidates. Then, you can add debugging code to those modules. Hopefully, no other module fiddles with @INC at the same time... Good luck!

Update: OK, here are sample modules Module.pm and Module2.pm:

package Module; BEGIN { print 'beginning my module1: ' . join(', ',@ARGV)."\n" } # do lots of stuff sub import { shift @ARGV ; } BEGIN { print 'ending my module1: ' . join(', ',@ARGV)."\n" } 1;
package Module2; BEGIN { print 'beginning my module2: ' . join(', ',@ARGV)."\n" } # do lots of stuff BEGIN { print 'ending my module2: ' . join(', ',@ARGV)."\n" } 1;

Update2: In case the approach described above does not work:

BEGIN { *CORE::GLOBAL::require = sub { printf "===== TRACE: req %-20s with +ARGV=%s\n", $_[0], join(', ' ,@ARGV); CORE::require( $_[0] ); }; }

Update3: Trivial, but might also help to narrow down candidate modules:
     find my/modules -name \*.pm -exec egrep -l @ARGV {} \;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://920807]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-03-28 18:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found