On 5/20/08, william <[EMAIL PROTECTED]> wrote:
> On 5/20/08, Dodger <[EMAIL PROTECTED]> wrote:
>  > 2008/5/19 Michael Peters <[EMAIL PROTECTED]>:
>  >
>  > > william wrote:
>  >  >
>  >  >> Then I would need to modify the QueryData module then,
>  >  >
>  >  > No don't do that.
>  >  >
>  >  >> by modifying
>  >  >> the standard module would it make my future maintenance more
>  >  >> complicated ?
>  >  >
>  >  > Absolutely.
>  >  >
>  >  >> Do you have any tips for me ?
>  >  >
>  >  > Wrap the object in your own package. Let's call it My::QueryData.
>  >  >
>  >  > package My::QueryData;
>  >  > use QueryData;
>  >  >
>  >  > my $query_data;
>  >  > sub create {
>  >  >  $query_data = QueryData->new(...);
>  >  > }
>  >  >
>  >  > sub get {
>  >  >  return $query_data;
>  >  > }
>  >  >
>  >
>  >
>  > For extra syntactic sugar, you could always just do it singlet style.
>  >
>  >  package My::QueryData;
>  >  use base QueryData;
>  >  our $singlet;
>  >
>  >  sub new {
>  >     return $singlet if $singlet;
>  >     return $singlet = QueryData->new(@_);
>  >  }
>  >
>  >
>  >  Of course, if you want to allow different ones for different
>  >  invocations (i.e. Pkg->new(foo => 1) and Pkg->new(foo => 2), you can
>  >  make $singlet a hashref keyed by those options, instead, and check for
>  >  the appropriate one
>  >
>
>
> Thanks, those solutions are nice.
>

Btw, I just try out that solution, it is awsome, it only takes time
while server startup. But subsequent request. it is so fast. I am new
to mod_perl, now I am in love with it. lol

Reply via email to