[cgiapp] code reuse.

James.Q.L shijialeee at yahoo.com
Mon Mar 17 16:00:02 EDT 2008


--- Mark Fuller <azfuller at gmail.com> wrote:

> On Mon, Mar 17, 2008 at 7:05 AM, James.Q.L <shijialeee at yahoo.com> wrote:
> >  > I might be missing the point, but what's wrong with storing $uuid in
> >  > Company::Util as an "our" variable and accessing it from anywhere as
> >  > $Company::Util::uuid ?
> >
> >  correct me if i am wrong. that won't work under mod_perl. because our $uuid is a global
> > package  variable and shared by all instances.
> 
> I don't understand how that works. If I have a simple script (in
> mod_perl) and "require Some::Module.pm," is it being compiled into a
> standalone package? If 14 other scripts require it they all get the
> same compiled package (in whatever state the others left it)?
> 
> I thought it was unique to the script that required it. It seems like
> it would create bottlenecks if Some::Module.pm did a lot of
> processing, blocking other scripts that required it (and share it?)
> and are now calling it.
> 
> If you (or anyone) can confirm that's how it works I'd appreciate it.
> 

i think you are right. it is fine as long as the global variable is explicitly initialized.

sorry i misled you.

> >  what i want is to setup $uuid and $dbh for the Company:: modules so that i can do
> >
> >  use base 'CGI::Application';
> >  use Company::CAP::EventLogging; # a plugin for CGI::Application
> >
> >  sub cgiapp_init {
> >   # init Company::Base
> >   $company = Company::Base->new();
> >   $company->dbh( MyApp::DB->dbh );
> >   $company->user($ENV{REMOTE_USER});
> >   # then somehow all my Company:: can start to use the $dbh etc..
> >  }
> >
> >  sub method {
> >   shift->elog("log this");
> >  }
> 
> You're calling "elog" as a method? In that case you could store $dbh
> (etc.) in C::A's param method. Then elog (etc.) can retrieve it using
> the param method?
> 

i have asked a question on perlmonks with a better example. see
http://perlmonks.org/?node_id=674601

> Mark
> 

thanks,

James.


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs


More information about the cgiapp mailing list