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 {} \;