[tpm] Detect a module's directory

J Z Tam jztam at yahoo.com
Mon Feb 22 12:15:11 PST 2010

hey Madi, 
  During dev, under Windoze, I would invoke testApp.pl with:
1.  Finding out which major rev of perl I am currently calling:
perl -V  
1.1 But double check the eventual runner's path/shell/profile/mounts/permissions, and @INC

2. then, debug it:  this would reveal the pathspec on Windows at runtime.
perl -d testLDAP.pl

2.1 For instance, to query the runtime location of 'which' Net::LDAP  is being called at runtime,  I n)ext  through the debugging, and use the 
'n'   command, 
until I hit the entry point into 'bind' in Net::LDAP

2.2  Once testLDAP.pl is About to interpret 'Net::LDAP::bind', method/call from Net::LDAP, I switch to the 
's'  command,
alias s)tep INTO  the LDAP.pm::bind code.  
The debugger shows the pathspec/\filespec/\lineNumber.


D:\home\itjdt\src\perl\  perl -d testLDAP.pl jordan

Loading DB routines from perl5db.pl version 1.3
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.
main::(testLDAP.pl:5):     my $cn =$ARGV[0];
  DB<1> n
main::(testLDAP.pl:6):     my $ldap;
main::(testLDAP.pl:7):     my $mesg;
main::(testLDAP.pl:8):     my $entry;
main::(testLDAP.pl:9):     my $pw;
main::(testLDAP.pl:12):    my $shortid = $ENV{ USERNAME };
main::(testLDAP.pl:17):    open(PASSFILE, "<$passfile");
  DB<4> n
main::(testLDAP.pl:18):    $pw = <PASSFILE>;
main::(testLDAP.pl:19):    chomp($pw);
main::(testLDAP.pl:21):    $ldap = Net::LDAP->new( 'domaincontroller001.foobar.com' ) or die "$@";
main::(testLDAP.pl:27):     $mesg = $ldap->bind ( "$shortid\@foobar.com", password =>
 "$pw", version =>3 ) ;

  DB<4> s
332:      my $ldap = shift;

--- On Mon, 2/22/10, Digimer <linux at alteeve.com> wrote:

> From: Digimer <linux at alteeve.com>
> Subject: [tpm] Detect a module's directory
> To: "Toronto Perl Mongers" <tpm at to.pm.org>
> Received: Monday, February 22, 2010, 2:28 PM
> Hi all,
>   Possibly stupid question time...
>   Is there a reliable* way to detect or read the
> directory that a perl module is in? '$ENV{PWD}' returns the
> directory of the script loading the module, not of the
> module itself. My Google-fu is failing me as finding a
> solution, too.
>   The reason I need this is that my core module reads
> in a configuration file from the root of the module's
> directory. I could hard-code it, but I would rather it be
> flexible in case it gets moved down the road.
> Thanks!
> Madi
> *Reliable in that it'd work when run from cron, work
> if/when the module is moved, etc.
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm

Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know at http://ca.answers.yahoo.com

More information about the toronto-pm mailing list