Apache2::SafePnotes - a safer replacement for Apache2::RequestUtil::pnotes
use Apache2::SafePnotes; use Apache2::SafePnotes qw/pnotes/; use Apache2::SafePnotes qw/whatever/;
This module cures a problem with Apache2::RequestRec::pnotes and Apache2::Connection::pnotes (available since mod_perl 2.0.3). These functions store perl variables making them accessible from various phases of the Apache request cycle.
Apache2::RequestRec::pnotes
Apache2::Connection::pnotes
According to the docs there are 2 ways to store data as a pnote:
$r->pnotes( key=>"value" );
and
$r->pnotes->{key}="value";
Unfortunately, these 2 versions work slightly different. Assuming the following code
my $v=1; $r->pnotes( 'v'=>$v ); $v++; my $x=$r->pnotes('v');
I'd expect $x to be 1 but it turns out to be 2. Further on, also this code snippet leads to unexpected results:
$x
1
2
my $v=1; $r->pnotes( 'v'=>$v ); $r->pnotes->{v}++; my $x=$v;
Surprise, $x is 2 as well.
The problem lies in $r->pnotes( 'v'=>$v ). With $r->pnotes->{v}=$v all works as expected ($x==1).
$r->pnotes( 'v'=>$v )
$r->pnotes->{v}=$v
$x==1
With Apache2::SafePnotes the problem goes away and $x will be 1 in both cases.
Apache2::SafePnotes
This module must be use'd not require'd. It does it's work in an import function.
use
require
import
creates the function Apache::RequestRec::safe_pnotes as a replacement for pnotes. The old pnotes function is preserved just in case some code relies on the odd behavior.
Apache::RequestRec::safe_pnotes
pnotes
creates the function Apache::RequestRec::NAME as a replacement for pnotes. If pnotes is passed as NAME the original pnotes function is replaced by the safer one.
Apache::RequestRec::NAME
modperl2, Apache2::RequestUtil, Apache2::Connection
Torsten Foertsch, <torsten.foertsch@gmx.net>
Copyright (C) 2006 by Torsten Foertsch
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Apache2::SafePnotes, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Apache2::SafePnotes
CPAN shell
perl -MCPAN -e shell install Apache2::SafePnotes
For more information on module installation, please visit the detailed CPAN module installation guide.