You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by Stas Bekman <st...@stason.org> on 2002/01/21 05:45:11 UTC
back compatibility layer for method handlers?
A "method handler" is now specified using the `method' sub attribute, e.g.
sub handler : method {};
instead of 1.xx's
sub handler ($$) {}
How the compat layer is supposed to handle this? I remember that when
I've tried to use method handlers with the new ModPerl::Registry, I was
getting segfaults when using $$ proto.
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: back compatibility layer for method handlers?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Geoffrey Young wrote:
>
> Stas Bekman wrote:
> >
> > A "method handler" is now specified using the `method' sub attribute, e.g.
> >
> > sub handler : method {};
>
> well, I submitted a patch to get this to work in 1.3. last I
> remember, doug was looking it over to make sure it didn't have any
> leaks.
>
> you could always commit it, which would give people a migration path
> :)
BTW, here is the patch against current CVS, along with a test handler
Index: mod_perl.c
===================================================================
RCS file: /home/cvspublic/modperl/src/modules/perl/mod_perl.c,v
retrieving revision 1.141
diff -u -r1.141 mod_perl.c
--- mod_perl.c 10 Jul 2001 03:30:27 -0000 1.141
+++ mod_perl.c 21 Jan 2002 15:19:51 -0000
@@ -1199,20 +1199,33 @@
if (gvp) cv = GvCV(gvp);
}
+ if (cv != NULL) {
+ is_method = perl_cv_ismethod(cv);
+ }
+
+ MP_TRACE_h(fprintf(stderr, "checking if `%s' is a method...%s\n",
+ sub, (is_method ? "yes" : "no")));
+ SvREFCNT_dec(sv);
+ return is_method;
+}
+
+int perl_cv_ismethod(CV *cv)
+{
+ int is_method=0;
+
#ifdef CVf_METHOD
if (cv && (CvFLAGS(cv) & CVf_METHOD)) {
is_method = 1;
}
#endif
+
if (!is_method && (cv && SvPOK(cv))) {
is_method = strnEQ(SvPVX(cv), "$$", 2);
}
- MP_TRACE_h(fprintf(stderr, "checking if `%s' is a method...%s\n",
- sub, (is_method ? "yes" : "no")));
- SvREFCNT_dec(sv);
return is_method;
}
+
#endif
void mod_perl_noop(void *data) {}
@@ -1453,6 +1466,7 @@
HV *stash = Nullhv;
SV *pclass = newSVsv(sv), *dispsv = Nullsv;
CV *cv = Nullcv;
+ GV *gv = Nullgv;
char *method = "handler";
int defined_sub = 0, anon = 0;
char *dispatcher = NULL;
@@ -1587,8 +1601,27 @@
#endif
}
else {
- MP_TRACE_h(fprintf(stderr, "perl_call: handler is a %s\n",
- dispatcher ? "dispatcher" : "cached CV"));
+ if (!dispatcher) {
+ MP_TRACE_h(fprintf(stderr, "perl_call: handler is a cached CV\n"));
+#ifdef PERL_METHOD_HANDLERS
+ cv = sv_2cv(sv, &stash, &gv, FALSE);
+
+ if (cv != NULL) {
+ is_method = perl_cv_ismethod(cv);
+ }
+
+ if (is_method) {
+ sv_setpv(pclass, HvNAME(stash));
+ method = GvNAME(CvGV(cv));
+ }
+
+ MP_TRACE_h(fprintf(stderr, "checking if CV is a method...%s\n",
+ (is_method ? "yes" : "no")));
+#endif
+ }
+ else {
+ MP_TRACE_h(fprintf(stderr, "perl_call: handler is a dispatcher\n"));
+ }
}
callback:
package My::MethodTest;
use Apache::Constants qw(OK);
use strict;
sub handler {
my $r = shift;
$r->push_handlers($r->current_callback => 'My::MethodTest->foo');
$r->push_handlers($r->current_callback => 'My::MethodTest->bar');
return OK;
}
sub foo : method {
my $self = shift;
my $r = shift;
print STDERR "My::Method::foo\n";
print STDERR "self: $self, r: $r\n";
return OK;
}
sub bar ($$) {
my $self = shift;
my $r = shift;
print STDERR "My::Method::bar\n";
print STDERR "self: $self, r: $r\n";
return OK;
}
1;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: back compatibility layer for method handlers?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Doug MacEachern wrote:
>
> On Mon, 21 Jan 2002, Geoffrey Young wrote:
>
> > Stas Bekman wrote:
> > >
> > > A "method handler" is now specified using the `method' sub attribute, e.g.
> > >
> > > sub handler : method {};
> >
> > well, I submitted a patch to get this to work in 1.3.
>
> huh? that isn't what your patch does. in any case, i'll look at it again
> when catching up on 1.x stuffs.
whoops. as usual, I'm not entirely with the program.
after removing the cobwebs from my brain, I remembered that what didn't work was pushing
method handlers as coderefs, even with the : method declaration.
here is an updated test case. sorry for the confusion.
--Geoff
(who tries to break his rut)
package My::MethodTest;
use Apache::Constants qw(OK);
use strict;
sub handler {
my $r = shift;
$r->push_handlers($r->current_callback => \&foo);
$r->push_handlers($r->current_callback => \&bar);
return OK;
}
sub foo : method {
my $self = shift;
my $r = shift;
print STDERR "My::Method::foo\n";
print STDERR "self: $self, r: $r\n";
return OK;
}
sub bar ($$) {
my $self = shift;
my $r = shift;
print STDERR "My::Method::bar\n";
print STDERR "self: $self, r: $r\n";
return OK;
}
1;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: back compatibility layer for method handlers?
Posted by Doug MacEachern <do...@covalent.net>.
On Mon, 21 Jan 2002, Geoffrey Young wrote:
> Stas Bekman wrote:
> >
> > A "method handler" is now specified using the `method' sub attribute, e.g.
> >
> > sub handler : method {};
>
> well, I submitted a patch to get this to work in 1.3.
huh? that isn't what your patch does. in any case, i'll look at it again
when catching up on 1.x stuffs.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: back compatibility layer for method handlers?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Stas Bekman wrote:
>
> A "method handler" is now specified using the `method' sub attribute, e.g.
>
> sub handler : method {};
well, I submitted a patch to get this to work in 1.3. last I
remember, doug was looking it over to make sure it didn't have any
leaks.
you could always commit it, which would give people a migration path
:)
>
> instead of 1.xx's
>
> sub handler ($$) {}
>
> How the compat layer is supposed to handle this? I remember that when
> I've tried to use method handlers with the new ModPerl::Registry, I was
> getting segfaults when using $$ proto.
>
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: back compatibility layer for method handlers?
Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
> here's a (very) brief explanation:
thanks Geoff, committed.
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: back compatibility layer for method handlers?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
here's a (very) brief explanation:
Index: mod_perl_method_handlers.pod
===================================================================
RCS file: /home/cvspublic/modperl/mod_perl_method_handlers.pod,v
retrieving revision 1.9
diff -u -r1.9 mod_perl_method_handlers.pod
--- mod_perl_method_handlers.pod 2 Jan 2002 09:41:23 -0000 1.9
+++ mod_perl_method_handlers.pod 22 Jan 2002 13:38:58 -0000
@@ -53,7 +53,22 @@
In this case, the 'My' class inherits this method from 'BaseClass'.
-To build in this feature, configure with:
+In Perl 5.6.0 or later, you can use subroutine attributes in place
+of subroutine prototypes:
+
+ package My;
+ @ISA = qw(BaseClass);
+
+ sub handler : method {
+ my($class, $r) = @_;
+ ...;
+ }
+
+see the L<attributes> manpage for additional information on
+subroutine attributes.
+
+To build in the ability to specify Perl*Handlers as method handlers,
+configure mod_perl with:
% perl Makefile.PL PERL_METHOD_HANDLERS=1 [PERL_FOO_HOOK=1,etc]
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: back compatibility layer for method handlers?
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Stas Bekman wrote:
> Doug MacEachern wrote:
>
>> On Mon, 21 Jan 2002, Stas Bekman wrote:
>>
>>
>>> A "method handler" is now specified using the `method' sub attribute,
>>> e.g.
>>>
>>> sub handler : method {};
>>>
>>> instead of 1.xx's
>>>
>>> sub handler ($$) {}
>>>
>>
>> there's no need to support that in 2.0, since 1.x has supported the
>> method
>> attribute for nearly 2 years:
>>
>> =item 1.24 - May 16, 2000
>>
>> 'sub handler : method {}' is now treated as a method handler
>>
>> so that code will work with both 1.x and 2.x.
>
>
>
> Cool, but it's not documented anywhere. Not in the pods, nor in the
> eagle book. The book advertises only the $$ proto, as it was published
> before the feature was added. I doubt many people know about this
> feature. e.g. do you cover this in your new book Geoff?
I wasn't aware of it, even though I played with the code for it before I
covered method handlers and should have figured it out. I wish I had.
oh, well *sigh*
>
> Anybody cares to submit a doc patch for this feature in 1.x?
yeah, I'll find a place for it.
--Geoff
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: back compatibility layer for method handlers?
Posted by Stas Bekman <st...@stason.org>.
Doug MacEachern wrote:
> On Mon, 21 Jan 2002, Stas Bekman wrote:
>
>
>>A "method handler" is now specified using the `method' sub attribute, e.g.
>>
>>sub handler : method {};
>>
>>instead of 1.xx's
>>
>>sub handler ($$) {}
>>
>
> there's no need to support that in 2.0, since 1.x has supported the method
> attribute for nearly 2 years:
>
> =item 1.24 - May 16, 2000
>
> 'sub handler : method {}' is now treated as a method handler
>
> so that code will work with both 1.x and 2.x.
Cool, but it's not documented anywhere. Not in the pods, nor in the
eagle book. The book advertises only the $$ proto, as it was published
before the feature was added. I doubt many people know about this
feature. e.g. do you cover this in your new book Geoff?
Anybody cares to submit a doc patch for this feature in 1.x?
> and several callbacks in 2.0 have more arguments than $r, so $$
> doesn't make sense anymore.
ok.
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:stas@stason.org http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
Re: back compatibility layer for method handlers?
Posted by Doug MacEachern <do...@covalent.net>.
On Mon, 21 Jan 2002, Stas Bekman wrote:
> A "method handler" is now specified using the `method' sub attribute, e.g.
>
> sub handler : method {};
>
> instead of 1.xx's
>
> sub handler ($$) {}
there's no need to support that in 2.0, since 1.x has supported the method
attribute for nearly 2 years:
=item 1.24 - May 16, 2000
'sub handler : method {}' is now treated as a method handler
so that code will work with both 1.x and 2.x.
and several callbacks in 2.0 have more arguments than $r, so $$
doesn't make sense anymore.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org