Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How do you get around the lexical scoping of use pragmas? (import)

by tye (Sage)
on Aug 27, 2006 at 05:49 UTC ( [id://569862]=note: print w/replies, xml ) Need Help??


in reply to How do you get around the lexical scoping of use pragmas?

Note that use strict boils down to

BEGIN { require 'strict.pm'; strict->import(); }

So strict->import() actually applies to the lexical scope one step outside of from where import() was called (or something like that). So, the following actually works:

package AID; require strict; require warnings; sub import { strict->import(); goto &warnings::import; } 1;

Then:

use AID; BEGIN { print 0+""; } print $x;

Gives:

Argument "" isn't numeric in addition (+) at - line 2. Global symbol "$x" requires explicit package name at - line 3. Execution of - aborted due to compilation errors.

And diagnostics.pm isn't lexically scoped (and I'm not sure why people even use it, to be quite frank), so you can just "use diagnostics" inside your common.pm file.

- tye        

Replies are listed 'Best First'.
Re^2: How do you get around the lexical scoping of use pragmas? (import)
by aufflick (Deacon) on Aug 28, 2006 at 08:21 UTC
    Brilliant! Makes perfect sense, but I wouldn't have even followed this thought process.

    I'd recommend anyone implementing this should document it heavily!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-19 12:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found