ZlR has asked for the wisdom of the Perl Monks concerning the following question:
I'm sure it's a classic problem .
I've read Loading all modules under a directory and How to dynamically load modules but still i can't make it work .
Suppose i have a lib directory : c:\tmp\test\testlib holding two modules : mod1.pm and mod2.pm . These module are in a package called Test and each one defines a function "test1" and "test2" .
These two modules are required in another file, testlib.pm, residing in the same directory
This testlib.pm is in turn used by a script run.pl that is in c:\tmp\test\script\ :
In testlib.pm, if i do :use lib 'c:/tmp/test/' ; use testlib::testlib; Test::test() ;
... Everything works fine .require testlib::mod1 ; require testlib::mod2 ;
But this implies that i add every new module manualy, so i tried to dynamically require the module files.
It breaks with "undefined subroutine" in run.pl as if the modules were not required :
I do this in testlib.pm instead of the two requires. I tried many variations like keeping the .pm or using instead or requiring or specifying full path in the require instead of the :: style, everything fails .foreach ( <*.pm> ) { next if /testlib/ ; $_ =~ s/\.pm// ; my $val = "testlib::" . $_ ; eval "require $val" ; }
Can anyone explain what's hapenning ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Require all modules in lib ?
by tlm (Prior) on Jun 07, 2005 at 10:38 UTC | |
by ZlR (Chaplain) on Jun 07, 2005 at 12:07 UTC | |
by tlm (Prior) on Jun 07, 2005 at 12:44 UTC | |
by ZlR (Chaplain) on Jun 07, 2005 at 13:17 UTC |