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

Re: Automatically importing a subroutine for a particular namespace

by Joost (Canon)
on Jul 04, 2008 at 18:56 UTC ( [id://695623]=note: print w/replies, xml ) Need Help??


in reply to Automatically importing a subroutine for a particular namespace

AFAIK fatalsToBrowser is not an exported subroutine, but a hook that installs a process-wide DIE handler. IOW you generally only want to call fatalsToBrowser once, at some place that easy to find so you can remove it when deploying your code in production.

In the general case of importing modules/variables in lots of modules, I prefer to import everything I want into some package and automatically export them from there:

package My::Tools; use Something qw(foo bar); use Other qw(blip blob); use Exporter; our @ISA = 'Exporter'; our @EXPORT = qw(foo bar blip blob);
Note that this package does not have to be a base class of anything. You only have to use it wherever it's needed:

package Foo::Bar::Asdf; use My::Tools;

Replies are listed 'Best First'.
Re^2: Automatically importing a subroutine for a particular namespace
by jacques (Priest) on Jul 04, 2008 at 19:24 UTC
    Note that this package does not have to be a base class of anything. You only have to use it wherever it's needed

    That's what I am trying to get away from... How can I tell perl to use something under a particular package without declaring it under that package? (I want to be lazy ...)

    Basically, I want to tell perl: "Hey, see that package name? For any package name you find like that, go ahead and make use of this...".

        That looks like exactly what I wanted. Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-03-28 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found