Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^3: Skeleton For Import to Package?

by almut (Canon)
on Jul 28, 2010 at 15:21 UTC ( #851739=note: print w/replies, xml ) Need Help??

in reply to Re^2: Skeleton For Import to Package?
in thread Skeleton For Import to Package?

How do I force the "import" to be the first executed statement?

You can't (at least not with the desired arguments), because cacher->import(...) is being called after the module has been required — at which point any code of the module outside of subroutines will already have been run. That's how use works...

Update: it's maybe worth mentioning that import is not being called at all if you say use cacher ();. If that's an issue in your case, you might want to setup %cachehash with a default directory at the time the module is being required. Then, in case import is being called, just re-initialize %cachehash with the directory specified as the argument to use.  Kind of like this:

sub import { ... setup_cachehash($dir) if $dir; } sub setup_cachehash { ... } setup_cachehash("/tmp"); # default

(From a performance point of view, doing things twice is of course suboptimal...)

P.S.: if you use Exporter in the same package, you probably want to explicitly call its import routine with the appropriate arguments (first arg = your package name), because normally the import method will be inherited from Exporter. In other words, Exporter's import will no longer be called (automatically) when you implement import yourself...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://851739]
[shmem]: grandola, vila morena
[shmem]: LanX: ah, that one. You'll get the bug reports also :P
[Discipulus]: upvote me! i'll make pm great again! ;=)
[shmem]: Discipulus reminds me of an irish saying: "I would guess a tomorrow can wait 'til this day is done" :-)

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2017-04-29 22:51 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (534 votes). Check out past polls.