Re: Accessing main:: from within a package

[prev] [thread] [next] [Date index for 2005/05/27]

From: Stas Bekman
Subject: Re: Accessing main:: from within a package
Date: 03:21 on 27 May 2005
Ken Clarke wrote:
> Hi Folks,
> 
>    With the release of mod_perl 2 (all say "Yeah Stas!" :) I decided to 
> dive in.  It'll be a change of mindset for me since I've coded perl 
> scripts for mod_cgi for years.
> 
>    I have a library of perl modules which occasionally make reference to 
> package main:: (EG $main::ScriptGlobalHash{'hashkey'} or my $result = 
> &main::SomeSubroutine(\%args))  However, if my understanding of the docs 
> is correct, my "main" script now belongs to a request URL specific 
> package namespace.  How should I properly (read safely/portably) refer 
> to my "main" package?  Put another way, how should my packages refer to 
> variables, subroutines, handles etc which belong to the "top level script".

Ken, I suppose you are talking about registry scripts.

To move your code into the main:: package (which as you've noticed 
ModPerl::RegistryCooker moves into a unique-per-script namespace), all you 
need to do is declare it at the top of your script. So if you had:

   #!/usr/bin/perl
   print "Content-type: text/html\n\n";
   print "mod_perl is easy";

now it'll look like:

   #!/usr/bin/perl
   package main;
   print "Content-type: text/html\n\n";
   print "mod_perl is easy";

I haven't tried that, but I think it should do the trick.

        -- 
        __________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@xxxxxx.xxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Accessing main:: from within a package
Ken Clarke 01:30 on 27 May 2005

Re: Accessing main:: from within a package
Stas Bekman 03:21 on 27 May 2005

Re: Accessing main:: from within a package
Perrin Harkins 14:18 on 27 May 2005

Generated at 20:12 on 05 Jun 2005 by mariachi v0.52