Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Including and Finding Custom Modules

by Cmdr Colstel (Novice)
on Sep 21, 2015 at 18:10 UTC ( [id://1142652]=perlquestion: print w/replies, xml ) Need Help??

Cmdr Colstel has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perl Monks,

I want to include an edited version of a module which is included in standard Perl. I, however, don't want Perl to search for that module in my Perl installation but maybe in the current directory where I have my script and my edited version. Does Perl automatically first search in the current directory for my module or is there a way I can have Perl look in the current directory first before it goes searching for it in my Perl installation ?

Thanks

Replies are listed 'Best First'.
Re: Including and Finding Custom Modules
by Corion (Patriarch) on Sep 21, 2015 at 18:12 UTC

    See lib and maybe perlvar on @INC.

    Also, you could simply load your module explicitly first. Perl will load one module at most once.

    You don't need to patch Perl modules, you can even give them a different filename. To prevent Perl from loading the other file, see perlvar on %INC then.

Re: Including and Finding Custom Modules
by davido (Cardinal) on Sep 21, 2015 at 18:31 UTC

    We don't know your specific use case for this, but would it be more appropriate to subclass the existing module instead of completely overriding it?


    Dave

Re: Including and Finding Custom Modules
by Anonymous Monk on Sep 21, 2015 at 18:48 UTC
    See docs about the "PERL5LIB" environment variable. Use "perl -V" uppercase V to see what the library search list currently is. (Otherwise known as "@INC".) Perl searches in that order to find anything.
Re: Including and Finding Custom Modules
by kevbot (Vicar) on Sep 22, 2015 at 04:56 UTC
    You can use the -I command line argument when invoking perl. For example, let's say that you have a script called my_test.pl in the current working directory which uses your version of the Foo::Bar module. Also, your version of the Foo::Bar module is in a subdir (in the current working directory) called lib. So, your file structure should look like this:
    ./my_test.pl ./lib/Foo/Bar.pm
    Use the following to run your script using your version of Foo::Bar
    perl -I lib/ my_test.pl
    This will work for simple pure perl modules, but you may have issues if your module is more complicated (e.g. uses XS, File::ShareDir, etc.).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-25 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found