You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Dan Rench <dr...@i-works.com> on 2000/07/24 20:24:08 UTC

Unexpected pnotes() behavior

I had a situation where a pnotes() key set in one phase had a value I
did not expect in a later phase.  Here's a small module that I wrote
as a HeaderParserHandler to illustrate:

package Ii::Apache::pnotes;
use Apache::Constants 'OK';

sub handler {
    my $r = shift;
    $r->push_handlers('PerlFixupHandler' => \&other_phase);
    my $n = 'I set this during the '.$r->current_callback." phase\n";
    $r->notes('sample_note', $n);
    printf STDERR '%s: %s', $r->current_callback(), $n;
    $n = "I set this to something else before returning.\n";
    return OK;
}

sub other_phase {
    my $r = shift;
    printf STDERR '%s: %s',
        $r->current_callback(), $r->notes('sample_note');
    return OK;
}

1;
__END__

...and here's what I get in my error_log:

PerlHeaderParserHandler: I set this during the PerlHeaderParserHandler phase
PerlFixupHandler: I set this to something else before returning.

If I s/pnotes/notes/ then I get what I expected:

PerlHeaderParserHandler: I set this during the PerlHeaderParserHandler phase
PerlFixupHandler: I set this during the PerlHeaderParserHandler phase

I had gotten into the habit of using pnotes() all the time no matter
what sort of value I was passing around, but it seems that if it's going
to be a regular scalar, notes() is how it must be, or I've got to be careful
not to change that variable after I set the pnotes() field.  The behavior
surprized me because I wasn't passing a reference, yet pnotes() acts like
I did.  In case anyone's wondering: apache 1.3.12, mod_perl 1.24.


Re: Unexpected pnotes() behavior

Posted by Doug MacEachern <do...@covalent.net>.
pnotes() expects a reference, it probably should croak if it's passed
something else.  it just increments the reference count of the sv, it does
not make a copy.  if you don't want to use a reference, you can copy it
yourself:

$r->pnotes(key => "$string")