perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Peters <mpet...@plusthree.com>
Subject Re: Class method or Object method?
Date Fri, 30 Jan 2009 14:15:31 GMT
Mark Hedges wrote:

>> package Cart;
>> my $instance;
>> sub new { return $instance ||= bless {}, $self }
>> sub is_in_cart { ... }

> Under mod_perl, doesn't that mean that if user A is the
> first to hit an interpreter and the cart instance is created
> for them, then if user B's request is the next to be served
> by the mod_perl child, that user B will get user A's cart?

Yes. mod_perl (or any persistent Perl framework) doesn't clear out globals or package variables
when 
the request is done. And in this case, $instance is a package variable.
If that's what you want, then it's a valid way to implement it (usually called a Singleton
pattern).

-- 
Michael Peters
Plus Three, LP


Mime
View raw message