#!/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 #### 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; #### BEGIN { *CORE::GLOBAL::require = sub { printf "===== TRACE: req %-20s with ARGV=%s\n", $_[0], join(', ' ,@ARGV); CORE::require( $_[0] ); }; }