Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: require() turns off strict?

by Gilimanjaro (Hermit)
on Jan 06, 2003 at 10:35 UTC ( [id://224590]=note: print w/replies, xml ) Need Help??


in reply to Re: require() turns off strict?
in thread require() turns off strict?

As I understand it 'use' actually does two things, both of them conditionally:

1. Perform a sort of compile-time 'require' *only if* this module hasn't been 'use'-d before. A table of what modules have already been loaded is maintained in some variable that I don't recall at the moment.

2. Call the 'import'-function (I think) *if* it is present in the 'use'-d package. This is performed on every occurence of 'use'. The import function is the one that can optionally export symbol-names (like your constants) to the calling package.

Building your own import function is a hassle, so the easy way is to use the standard Exporter package... The man-page of the Exporter package can explain everything you want to know (and a lot more) about exactly how to use it. For starters, this should do:

--file foo.pm--

package foo; use Exporter; @ISA=qw(Exporter); @EXPORT=qw($const1 $const2 $const3); # rest of package including constant data
If you'd just require'd the foo package, you would need to use $foo::const1 to access the constant.

If you'd use'd the foo package, the same would still work, but you would also have access using $const1 from the calling package.

Hope it helps...

Replies are listed 'Best First'.
Re^3: require() turns off strict?
by Aristotle (Chancellor) on Jan 06, 2003 at 13:53 UTC
    A table of what modules have already been loaded is maintained in some variable that I don't recall at the moment.
    That would be the %INC hash.
    (I think) *if* it is present in the 'use'-d package.
    Not quite. If you specify an empty import list as in use Module (); then its import() won't be called at all (not even with no parameters).

    Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2024-04-25 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found