Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Common sub as method or function

by dogz007 (Scribe)
on Aug 15, 2007 at 16:35 UTC ( [id://632790]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Common sub as method or function
in thread Common sub as method or function

I've reconsidered my answer, and I wonder if is there any functional difference between:

local *main::timestamp = *Module::Base::timestamp;

and:

use Module::Base qw(timestamp);

I think I would lean towards the latter being better practice. It is what I usually do, which makes me wonder why I came up with the local method first...

Replies are listed 'Best First'.
Re^4: Common sub as method or function
by akho (Hermit) on Aug 15, 2007 at 16:50 UTC
    use Module::Base qw(timestamp);

    is functionally equivalent to

    BEGIN { require Module::Base; Module::Base->import('timestamp'); }

    So it's at the very least wrapped in a BEGIN block (that is The Thing To Do when using your approach, anyway). It may actually do anything depending on how Module::Base::import was defined.

    It does what you mean when it was created by Exporter and timestamp is in @EXPORT_OK.

Re^4: Common sub as method or function
by akho (Hermit) on Aug 15, 2007 at 17:06 UTC
    Oh, and also: if you only want to import a sub into main::, you should not import the whole typeglob. Also, there is probably no need to import into main::timestamp is a rather generic name that may be used in some function/module you call, and things will soon get messy. Besides, local would be pretty much useless inside a BEGIN block (and that is very desirable). Use

    BEGIN { *Module::Derived::timestamp = \&Module::Base::timestamp; }

    or something.

    All this means that symbol table tricks should be severely incapsulated so that no living soul ever sees them Exporter.pm can help remove this mess!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found