perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geoffrey Young <>
Subject [Fwd: [ #30061] $r->pnotes stores aliases not copies so is subject to action at a distance]
Date Tue, 06 Nov 2007 16:47:46 GMT
so, I've been thinking a bit about this and I think I recall the
original reasoning way back when...

  my $obj = $class->new();
  $r->pnotes(OBJ => $obj);

I am almost certain that this was the original use case for pnotes as I
dig into my mind and recall the time on the list where folks were like
"wow!  we can pass a perl scalar around the request."  what this, um,
feature allows users to do is alter the underlying object without
re-storing it along the way:

  # next guy to pull it from pnotes gets the current state

over the years I think we will find that people do that kind of thing
_all the time_ with pnotes.

anyway, I'm not arguing here, but I was trying to figure out why it was
done this way in the first place - doug didn't just do stuff at random,
but tended to add features that were dwimmy for the use-cases of the
dot-com era :)


-------- Original Message --------
Subject: [ #30061] $r->pnotes stores aliases not copies so is
subject to action at a distance
Date: Tue, 06 Nov 2007 11:31:51 -0500
From: Tim_Bunce via RT <>
To: undisclosed-recipients:;
References: <>

       Queue: mod_perl
 Ticket <URL: >

I've just been bitten by this bug again!

What's wrong with this code:

sub foo {
    my ($r, $status, $why) = @_;
    $r->pnotes('foo', ($why) ? "$status:$why" : $status);

Nothing, except it doesn't work as expected due to this pnotes bug: If
the same code is
called in a sub-request then the pnote of $r->prev is magically updated
at a distance to the
same value!

Try explain why that is to anyone not deeply familar with perl internals!

The fix is to avoid pnotes taking a ref to the invisible op_targ
embededed in the code by
passing a simple lexical variable as the actual argument. That can be
done in-line like this:

sub mark_as_internally_redirected {
    my ($r, $status, $why) = @_;
    $r->pnotes('foo', my $tmp = (($why) ? "$status:$why" : $status));

At the very least the docs need a big warning that the second argument
to the pnotes
method should only be a simple lexical variable.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message