Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Export from module in subdirectory

by tobyink (Abbot)
on Oct 11, 2012 at 12:56 UTC ( #998439=note: print w/ replies, xml ) Need Help??


in reply to Re: Export from module in subdirectory
in thread Export from module in subdirectory

You're looking at it backwards. Don't decide on the code because of the filenames; decide on the filenames because of the code.

Choose a meaningful package name, like "Quux::Enhancer", and declare the package name in the module (somewhere near the top - the only things it makes sense to put before the package declaration are lexical pragma like use strict; use warnings; use 5.010;) using:

package Quux::Enhancer;

Now decide on which lib dir it's going to live inside. Often this will be a directory which is in perl's default @INC list. Within that directory create a subdirectory called Quux, and within that save your module as Enhancer.pm.

Then in your script, if that lib dir is not in perl's default @INC, include this:

use lib '/path/to/lib'; ## not including 'Quux'!!

And then in the script load the module like this:

use Quux::Enhancer;

If you ever need to move the file, then that's fine; no need to change anything within the module; just make sure it's always called Enhancer.pm, and always kept in a directory called Quux. Then use lib to tell your Perl script where to find it.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'


Comment on Re^2: Export from module in subdirectory
Select or Download Code
Re^3: Export from module in subdirectory
by Don Coyote (Monk) on Oct 11, 2012 at 13:24 UTC

    Thanks tobyink, this helps explain why I don't need to declare the package all the way back to some random path separator. I shall have to have a bit of a play around with some self constructed modules and directories. This should help me appreciate the way use is working, and some of the other replies in this thread.

    Coyote

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998439]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2014-08-23 20:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (178 votes), past polls