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

Reply via email to