SPUG: Confusing behaivior with exported variables

Peter Darley pdarley at kinesis-cem.com
Fri Mar 20 12:35:40 PDT 2009


Folks,

 

                It's been a long time since I've bugged y'all with a stupid
question, but I've got a new one so I'm hoping someone can help me out.

 

                The problem is with exporting variables, and having them
available to both a script that uses the module exporting the variable, and
the module it's self.  I have two modules, one on a machine at work and one
on a machine at home.  Both are doing something that looks super similar to
me.

 

                At work I have: 

 

package Neo::Web;

 

use ...

 

use CGI qw/:standard/;

use CGI::Cookie;

use Apache::DBI;

use Apache::Session::Postgres;

use Data::Dumper;

 

BEGIN 

{

                use Exporter   ();

                @ISA         = qw(Exporter);

                @EXPORT      = qw(%Session $SessionID 

                                                  &TieSession &UntieSession
... );

                

                ConnectDB(DBName=>'Sessions');

}

 

sub TieSession

{

                tie %Session, 'Apache::Session::Postgres', $SessionID,
{Handle=>$Neo::DB::Sessions, Commit=>0};

                $SessionID = $Session{_session_id};

}

 

                The scripts using this package can get at %Session, and this
module can get at %Session.  They are the same variable and have the same
contents.

 

                At home I have:

 

package Darley::Supers;

 

use ... ;

 

use Data::Dumper;

 

BEGIN 

{

                my (%CurrentUser);

                

        use Exporter   ();

        @ISA         = qw(Exporter);

        @EXPORT      = qw(%CurrentUser

                                  &Power &Challenge &GetUser &GetOrg
&GetCity);

}

 

 

sub SetCurrentOrgSetting

{

                my (%Args) = @_;

                # Args: Setting = Setting to store

                #             Value = Value to store

                

                StoreOrgSetting(OrgID=>$CurrentUser{Org}{org_id},
Setting=>$Args{Setting}, Value=>$Args{Value});

                $CurrentUser{Org}{Settings}{$Args{Setting}} = $Args{Value};

                

                return 1;

}

 

                And the script using this module can get at %CurrentUser,
but when this package uses it, it's empty.  I can't figure out why the
exported hash is the same in the first example, but has two different values
in the second.

 

Thanks for any help,

Peter

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/spug-list/attachments/20090320/b6f2173a/attachment.html>


More information about the spug-list mailing list