Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Exporter behavior

by dymium (Initiate)
on Feb 20, 2013 at 15:35 UTC ( #1019797=perlquestion: print w/replies, xml ) Need Help??
dymium has asked for the wisdom of the Perl Monks concerning the following question:

My system is set up with several core object classes, a 'core' class, and a separate module that handles login and privilege granting. Let's call the core package 'BDB::PPA', the login/privilege module 'BDB::PPALogin', and one of the core objects 'BDB::pinfo'.

The PPALogin class exports several functions, the most important to me are isSuper() and has_priv(), which I use all over the other packages to check for appropriate permissions before running code. The top of my PPALogin package looks like this:

package BDB::PPALogin; use strict; BEGIN { require Exporter; our @ISA = qw (Exporter); our @EXPORT = qw ( isSuper has_priv [...] ); }

This should have lead to the ability for my other modules, namely BDB::pinfo, to call isSuper() anywhere in code without the package prefix. It was working until two days ago, when for some reason it ceased to function as expected, and required me to prefix all of those function calls with the package. I know there are some circular references between the modules, but my understanding is those should be resolved appropriately by using the BEGIN {} block in PPALogin. To be verbose:

package BDB::pinfo; [ other code / use statements ] sub canSeeMe { eval { if ( isSuper() ) { # This used to work, but now fails } } eval { if ( BDB::PPALogin::isSuper() ) { # This has always worked, but I *really* don't want to +type the package name in code every time... } } }

Any advice on where to look or what additional code I can add to ensure / force the functions from PPALogin to export before any other module needs them?

For reference, I'm running Perl 5.10.1 on a LAMP box with mod_perl.


Replies are listed 'Best First'.
Re: Exporter behavior
by Anonymous Monk on Feb 21, 2013 at 04:49 UTC

    should be resolved appropriately by using the BEGIN

    not so

    The appropriate resolution is to break the circular dependency

    Relying on BEGIN "tricks" is the workaround, and IMHO, if you can't figure it out yourself, that is a giant hint that you should break the circle

    anyway, Mini-Tutorial: Mutual Use of Exporting Modules

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1019797]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2018-05-27 06:04 GMT
Find Nodes?
    Voting Booth?