Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

global function decleration

by Anonymous Monk
on Jan 06, 2005 at 11:56 UTC ( [id://419871]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks how do we declare functions written in a .pm file globally to be available in all other .pm and the .pl files. These functions should not be noted by use strict module.

Replies are listed 'Best First'.
Re: global function decleration
by gaal (Parson) on Jan 06, 2005 at 12:32 UTC
    1. If by "available" you just mean "callable", you can simply use the function's fully-qualified name:

      package SomePM; use OtherPackage; OtherPackege::some_func(); # works

      I sometimes do this in my projects for debugging:

      sub ::D { require Data::Dumper; return Data::Dumper::Dumper(@_) } sub ::DD { require Carp; Carp::confess(::D(@_)) } # later, call it like this: print ::D({ current_state => $state }); # debug print ::DD($state); # dump, stack trace, die.

    2. If you want some_func to be callable without qualification from any package... you can't do this generally and unevilly. :)

      If you have the cooperation of the other modules, have them use your module, and write an import routine to export your functions to the calling namespaces.

    3. If you don't have that cooperation, you might hook %INC (see require) to do this exploiting exporting for you. Note that unless you hook %INC early in the initialization of your program, you will probably have untreated modules already loaded in memory, and you will have to find out who they are and treat them post-fact. This of course will miss out on their BEGIN blocks.
Re: global function decleration
by Aragorn (Curate) on Jan 06, 2005 at 12:21 UTC
    You can use the standard Exporter module for this.
Re: global function decleration
by ambrus (Abbot) on Jan 06, 2005 at 21:12 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-29 13:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found