perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torsten Foertsch <torsten.foert...@gmx.net>
Subject Re: [MP2] possible pnotes bug?
Date Wed, 15 Mar 2006 17:55:34 GMT
On Wednesday 15 March 2006 18:23, Geoffrey Young wrote:
> > + my $foo = 123;
> > + $r->pnotes('foo' => $foo);
> > + $foo = 456;
> > + $r->pnotes('foo') # <== now 456 (in 2.0.2)
> > + $r->pnotes('foo') # <== left at 123 (in 2.0.3)
>
> actually, I'm re-thinking my stance on this.  a common use of pnotes is to
> pass objects around.  if I understand things correctly, the current
> situation is this
>
>   -- some handler
>   my $o = Foo->new;
>   $r->pnotes(foo => $o);
>
>   -- next handler
>   my $o = $r->pnotes('foo');
>   $o->set(bar => 1);          # sets $o->{_bar} = 1
>
>   -- another handler
>   my $o = $r->pnotes('foo');
>   my $bar = $o->bar;          # 1
>
> I actually thing that would be somewhat common.  and as I understand
> things, the fix would require the middle step to be
>
>   -- next handler
>   my $o = $r->pnotes('foo');
>   $o->set(bar => 1);          # sets $o->{_bar} = 1
>   $r->pnotes(foo => $o);
>
> in order for $o to maintain it's internal state.  is that right?

I don't think so. An object is a blessed reference. Hence, pnotes store only 
the reference. Your set operation in next handler modifies the object itself 
not the reference. Hence, there is no need to store it again. With normal 
hashes this can also be done:

$h{foo}=$o;
$o->set(bar=>1);
# no need to update $h{foo} here
$h{foo}->bar;    # 1

Torsten

Mime
View raw message