You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by "Philippe M. Chiasson" <go...@cpan.org> on 2001/11/13 10:18:57 UTC
[Patch] $r->pnotes() take 2
Following Stas comments, here is a revised patch.
One question left though, when we have an accessor method like
$r->pnotes('key','value');
Should it return the old or the new values ?
I ask because I think it's inconsistently implemented...
/home/gozer/sources/mod_perl2/deps/perl-12948/bin/perl build/cvsdiff
Index: xs/Apache/RequestUtil/Apache__RequestUtil.h
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/xs/Apache/RequestUtil/Apache__RequestUtil.h,v
retrieving revision 1.10
diff -u -I'$Id' -I'$Revision' -r1.10 Apache__RequestUtil.h
--- xs/Apache/RequestUtil/Apache__RequestUtil.h 7 Nov 2001 03:39:08 -0000 1.10
+++ xs/Apache/RequestUtil/Apache__RequestUtil.h 13 Nov 2001 09:11:16 -0000
@@ -172,6 +172,36 @@
return retval;
}
+static MP_INLINE
+SV *mpxs_Apache__RequestRec_pnotes(pTHX_ request_rec *r, SV *k, SV *val)
+{
+ MP_dRCFG;
+ SV *retval = NULL;
+
+ if (!rcfg)
+ return &PL_sv_undef;
+
+ if (!rcfg->pnotes)
+ rcfg->pnotes = newHV();
+
+ if (k) {
+ STRLEN len;
+ char *key = SvPV(k, len);
+
+ if (val) {
+ retval = *hv_store(rcfg->pnotes, key, len, SvREFCNT_inc(val), FALSE);
+ }
+ else if (hv_exists(rcfg->pnotes, key, len)) {
+ retval = *hv_fetch(rcfg->pnotes, key, len, FALSE);
+ }
+ }
+ else {
+ retval = newRV_inc((SV *)rcfg->pnotes);
+ }
+
+ return (retval) ? SvREFCNT_inc(retval) : &PL_sv_undef;
+}
+
#define mpxs_Apache__RequestRec_dir_config(r, key, sv_val) \
modperl_dir_config(aTHX_ r, r->server, key, sv_val)
Index: t/response/TestAPI/request_rec.pm
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/t/response/TestAPI/request_rec.pm,v
retrieving revision 1.9
diff -u -I'$Id' -I'$Revision' -r1.9 request_rec.pm
--- t/response/TestAPI/request_rec.pm 29 Oct 2001 01:19:16 -0000 1.9
+++ t/response/TestAPI/request_rec.pm 13 Nov 2001 09:11:17 -0000
@@ -11,7 +11,7 @@
sub handler {
my $r = shift;
- plan $r, tests => 49;
+ plan $r, tests => 54;
#Apache->request($r); #PerlOptions +GlobalRequest takes care
my $gr = Apache->request;
@@ -78,6 +78,16 @@
ok $r->subprocess_env;
ok $r->notes;
+
+ ok $r->pnotes;
+
+ ok t_cmp('pnotes_bar', $r->pnotes('pnotes_foo','pnotes_bar'), qq{\$r->pnotes(key,val)});
+
+ ok t_cmp("pnotes_bar", $r->pnotes('pnotes_foo') , qq{\$r->pnotes(key)});
+
+ ok t_cmp('HASH', ref($r->pnotes), qq{ref($r->pnotes)});
+
+ ok t_cmp('pnotes_bar', $r->pnotes()->{'pnotes_foo'}, qq{\$r->pnotes()->{}});
ok $r->content_type;
Index: docs/src/api/mod_perl-2.0/Apache/RequestRec.pod
===================================================================
RCS file: /home/anoncvs/mod_perl-docs-cvs/src/api/mod_perl-2.0/Apache/RequestRec.pod,v
retrieving revision 1.2
diff -u -I'$Id' -I'$Revision' -r1.2 RequestRec.pod
--- docs/src/api/mod_perl-2.0/Apache/RequestRec.pod 10 Oct 2001 05:06:36 -0000 1.2
+++ docs/src/api/mod_perl-2.0/Apache/RequestRec.pod 13 Nov 2001 09:11:17 -0000
@@ -75,6 +75,23 @@
values associated with the key C<$key> (and the key itself) will be
deleted.
+=item * $r->pnotes( [ $key, [$value] ] )
+
+Like $r->notes, but takes any scalar as a value.
+
+ $r->pnotes("MY_HANDLER" => [qw(one two)]);
+ my $val = $r->pnotes("MY_HANDLER");
+ print $val->[0]; # prints "one"
+
+ my $hashref = $r->pnotes();
+ print $hashref->{'MY_HANDLER'}[0]; #also prints one
+
+Called without any arguments, it returns a reference to the pnotes
+hash.
+
+Advantage over just using a Perl variable is that $r->pnotes gets
+cleaned up after every request.
+
=item *
=back
Index: todo/api.txt
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/todo/api.txt,v
retrieving revision 1.15
diff -u -I'$Id' -I'$Revision' -r1.15 api.txt
--- todo/api.txt 8 Nov 2001 03:19:48 -0000 1.15
+++ todo/api.txt 13 Nov 2001 09:11:17 -0000
@@ -10,9 +10,6 @@
need apr_finfo_t <-> struct stat conversion (might already be there,
haven't looked close enough yet)
-$r->pnotes:
-not yet implemented
-
$r->subprocess_env:
in void context should populate %ENV as 1.x does
Index: xs/maps/modperl_functions.map
===================================================================
RCS file: /home/anoncvs/mod_perl-2-cvs/xs/maps/modperl_functions.map,v
retrieving revision 1.27
diff -u -I'$Id' -I'$Revision' -r1.27 modperl_functions.map
--- xs/maps/modperl_functions.map 7 Nov 2001 04:03:07 -0000 1.27
+++ xs/maps/modperl_functions.map 13 Nov 2001 09:11:17 -0000
@@ -13,6 +13,7 @@
mpxs_Apache__RequestRec_set_handlers
mpxs_Apache__RequestRec_get_handlers
mpxs_Apache__RequestRec_location
+ SV *:DEFINE_pnotes | mpxs_Apache__RequestRec_pnotes | request_rec *:r, SV *:key=NULL, SV *:value=NULL
#protocol module helpers
mpxs_Apache__RequestRec_location_merge
--
Philippe M. Chiasson <go...@cpan.org>
Extropia's Resident System Guru
http://www.eXtropia.com/
/* When we have more time, we can teach the penguin to say
* "By your command" or "Activating turbo boost, Michael".
*/
-- Linux 2.2.16
/usr/src/linux/arch/sparc/prom/sun4prom.c
perl -e '$$=\${gozer};{$_=unpack(P26,pack(L,$$));/^Just Another Perl Hacker!\n$/&&print||$$++&&redo}'
Re: [Patch] $r->pnotes() take 2
Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 13 Nov 2001, Philippe M. Chiasson wrote:
> Following Stas comments, here is a revised patch.
thanks, that's in.
> One question left though, when we have an accessor method like
>
> $r->pnotes('key','value');
>
> Should it return the old or the new values ?
it should do whatever 1.x does.
> + if (!rcfg)
> + return &PL_sv_undef;
> +
> + if (!rcfg->pnotes)
> + rcfg->pnotes = newHV();
and just a friendly reminder, needed to add {}'s for style here.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org