You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Christian Laursen <xi...@borderworlds.dk> on 2003/10/21 14:19:04 UTC
Small problem with mod_perl2 and Apache::compat
I have a small problem with Apache::compat.
I have got some mp1 code running under mp2 using Apache::compat,
but I had to change it a little bit in order to do that.
A few places we have the following:
use Apache::Constants qw(:common :response);
It looks like the response group is missing in Apache::Constants
when running under mp2 with Apache::compat as we get this error:
[Tue Oct 21 13:51:14 2003] [error] [client 127.0.0.1] unknown apache:: group `re
sponse' at /usr/local/lib/perl5/site_perl/5.8.0/mach/Apache2/Apache/compat.pm li
ne 151.
Changing it to "use Apache::Constants qw(:common);" makes it work, but I suspect
that a few constants will then be missing when running it under mp1.
This is with mod_perl/1.99_10. I checked the Changelog via cvsweb, and there
doesn't seem to be any changes regarding this.
As far as I can tell this is a small bug in Apache::compat. If I'm wrong feel
free to enlighten me.
Thanks in advance.
--
Best regards
Christian Laursen
Re: Small problem with mod_perl2 and Apache::compat
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
>>anyway, try this patch (against current CVS - I'm not sure if there
>>have been changes since the last release) which weeds out attempts to
>>import non-existent tags.
>
>
> Thank you, it works. The code now runs unmodified.
cvs has been modified to this end (albeit slightly differently than the
patch I sent you).
thanks for reporting it :)
--Geoff
Re: Small problem with mod_perl2 and Apache::compat
Posted by Christian Laursen <xi...@borderworlds.dk>.
Geoffrey Young <ge...@modperlcookbook.org> writes:
> Christian Laursen wrote:
> > I have a small problem with Apache::compat.
> > I have got some mp1 code running under mp2 using Apache::compat,
> > but I had to change it a little bit in order to do that.
> > A few places we have the following:
> > use Apache::Constants qw(:common :response);
> > It looks like the response group is missing in Apache::Constants
>
> nope, you're right - Apache::compat just passes whatever import tags
> you specify to Apache::Const, and there's no :response tag in mp2.
>
> the only real reason I've ever seen anyone use :response is for
> REDIRECT, which now exists in :common, so I suspect that's why your
> code worked.
Yes, I only skimmed through the code in question, and I think REDIRECT
is the only symbol from :response, that is used.
> anyway, try this patch (against current CVS - I'm not sure if there
> have been changes since the last release) which weeds out attempts to
> import non-existent tags.
Thank you, it works. The code now runs unmodified.
--
Best regards
Christian Laursen
Re: Small problem with mod_perl2 and Apache::compat
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> if :response and :common come in the same import() this will do:
>
> my %seen = ();
> my @args = grep { $seen{$_}++; $seen{$_} < 2 } map { /^:response$/ ?
> ":common" : $_ } @_;
>
> or something like that ;)
too much fwp for you, I think :)
--Geoff
Re: Small problem with mod_perl2 and Apache::compat
Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
>
> ok, I think I've decided that ignoring errors from :server or :args_how
> isn't a good idea - it's better to have that blow up on a user than have
> an unresolved error later on.
+1
> so, if we're not supporting everything right now, this is probably a
> better patch.
>
> --- lib/Apache/compat.pm 30 Aug 2003 02:33:26 -0000 1.88
> +++ lib/Apache/compat.pm 21 Oct 2003 17:57:07 -0000
> @@ -148,7 +148,15 @@
> sub import {
> my $class = shift;
> my $package = scalar caller;
> - Apache::Const->compile($package => @_);
> +
> + my @args = @_;
> +
> + # treat :response as :common - it's not perfect
> + # (and we may import :common twice), but it's
> + # simple and close enough for the majority
> + @args = map { s/:response/:common/; $_ } @args;
if :response and :common come in the same import() this will do:
my %seen = ();
my @args = grep { $seen{$_}++; $seen{$_} < 2 } map { /^:response$/ ? ":common"
: $_ } @_;
or something like that ;)
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Small problem with mod_perl2 and Apache::compat
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
ok, I think I've decided that ignoring errors from :server or :args_how
isn't a good idea - it's better to have that blow up on a user than have an
unresolved error later on.
so, if we're not supporting everything right now, this is probably a better
patch.
--- lib/Apache/compat.pm 30 Aug 2003 02:33:26 -0000 1.88
+++ lib/Apache/compat.pm 21 Oct 2003 17:57:07 -0000
@@ -148,7 +148,15 @@
sub import {
my $class = shift;
my $package = scalar caller;
- Apache::Const->compile($package => @_);
+
+ my @args = @_;
+
+ # treat :response as :common - it's not perfect
+ # (and we may import :common twice), but it's
+ # simple and close enough for the majority
+ @args = map { s/:response/:common/; $_ } @args;
+
+ Apache::Const->compile($package => @args);
}
#no need to support in 2.0
--Geoff
Re: Small problem with mod_perl2 and Apache::compat
Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
>
> > But this patch simply ignores the 3 passed groups. Shouldn't it push
> > :common instead?
> >
> > my @args = grep { !/:response|:server|:args_how/ } @_;
> > push @args, ":common" if @_ != @args;
>
> yeah, I thought about that afterward, since :response does include
> :common. but it wouldn't help on empty args, just on :response -
> :common isn't any use to the other two skipped tags.
>
> so I'll do something with :common on :response and leave the others.
+1, but see below
> >
> > If someone used:
> >
> > use Apache::Constants qw(:response);
> >
> > your patch won't make the code working, besides suppressing the import
> > error.
> >
>
> indeed.
>
> but I already mentioned that there are lots of other cases that would
> also break, such as using MOVED or SERVER_BUILT. and there's no easy
> way around it without simply aliasing _every_ constant in mp1 to its mp2
> equivalent, forgoing entirely a simple pass of @_ to import().
>
> so, I dunno. keeping the code simple and catching the most common
> cases, or doing a complete match and polluting the caller's namespace
> with constants they most likely won't need?
OK, can we easily tell what's supported and what not at run-time? If so, how
about generating a user-friendly error message, explaining how to proceed? Or
may be it won't make much sense, since it'll require the code to be modified.
FWIW, ModPerl::MethodLookup includes a hardcoded map of methods and groups of
methods that were renamed or removed exactly for the porting purpose. How hard
would it be to prepare such a transition map for the odd list of constants
that you mention? Feel free to add a new method to ModPerl::MethodLookup to
lookup constants.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Small problem with mod_perl2 and Apache::compat
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> But this patch simply ignores the 3 passed groups. Shouldn't it push
> :common instead?
>
> my @args = grep { !/:response|:server|:args_how/ } @_;
> push @args, ":common" if @_ != @args;
yeah, I thought about that afterward, since :response does include :common.
but it wouldn't help on empty args, just on :response - :common isn't any
use to the other two skipped tags.
so I'll do something with :common on :response and leave the others.
>
> If someone used:
>
> use Apache::Constants qw(:response);
>
> your patch won't make the code working, besides suppressing the import
> error.
>
indeed.
but I already mentioned that there are lots of other cases that would also
break, such as using MOVED or SERVER_BUILT. and there's no easy way around
it without simply aliasing _every_ constant in mp1 to its mp2 equivalent,
forgoing entirely a simple pass of @_ to import().
so, I dunno. keeping the code simple and catching the most common cases, or
doing a complete match and polluting the caller's namespace with constants
they most likely won't need?
--Geoff
Re: Small problem with mod_perl2 and Apache::compat
Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
>
>
> Christian Laursen wrote:
>
>> I have a small problem with Apache::compat.
>>
>> I have got some mp1 code running under mp2 using Apache::compat,
>> but I had to change it a little bit in order to do that.
>>
>> A few places we have the following:
>>
>> use Apache::Constants qw(:common :response);
>>
>> It looks like the response group is missing in Apache::Constants
>> when running under mp2 with Apache::compat as we get this error:
[...]
> nope, you're right - Apache::compat just passes whatever import tags you
> specify to Apache::Const, and there's no :response tag in mp2.
>
> the only real reason I've ever seen anyone use :response is for
> REDIRECT, which now exists in :common, so I suspect that's why your code
> worked.
>
> anyway, try this patch (against current CVS - I'm not sure if there have
> been changes since the last release) which weeds out attempts to import
> non-existent tags.
[...]
> Index: lib/Apache/compat.pm
> ===================================================================
> RCS file: /home/cvspublic/modperl-2.0/lib/Apache/compat.pm,v
> retrieving revision 1.88
> diff -u -r1.88 compat.pm
> --- lib/Apache/compat.pm 30 Aug 2003 02:33:26 -0000 1.88
> +++ lib/Apache/compat.pm 21 Oct 2003 13:00:07 -0000
> @@ -148,7 +148,11 @@
> sub import {
> my $class = shift;
> my $package = scalar caller;
> - Apache::Const->compile($package => @_);
> +
> + # skip over import tags that don't exist in mp2
> + my @args = grep { !/:response|:server|:args_how/ } @_;
> +
> + Apache::Const->compile($package => @args);
> }
But this patch simply ignores the 3 passed groups. Shouldn't it push :common
instead?
my @args = grep { !/:response|:server|:args_how/ } @_;
push @args, ":common" if @_ != @args;
If someone used:
use Apache::Constants qw(:response);
your patch won't make the code working, besides suppressing the import error.
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Small problem with mod_perl2 and Apache::compat
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Christian Laursen wrote:
> I have a small problem with Apache::compat.
>
> I have got some mp1 code running under mp2 using Apache::compat,
> but I had to change it a little bit in order to do that.
>
> A few places we have the following:
>
> use Apache::Constants qw(:common :response);
>
> It looks like the response group is missing in Apache::Constants
> when running under mp2 with Apache::compat as we get this error:
>
> [Tue Oct 21 13:51:14 2003] [error] [client 127.0.0.1] unknown apache:: group `re
> sponse' at /usr/local/lib/perl5/site_perl/5.8.0/mach/Apache2/Apache/compat.pm li
> ne 151.
>
> Changing it to "use Apache::Constants qw(:common);" makes it work, but I suspect
> that a few constants will then be missing when running it under mp1.
>
> This is with mod_perl/1.99_10. I checked the Changelog via cvsweb, and there
> doesn't seem to be any changes regarding this.
>
> As far as I can tell this is a small bug in Apache::compat. If I'm wrong feel
> free to enlighten me.
nope, you're right - Apache::compat just passes whatever import tags you
specify to Apache::Const, and there's no :response tag in mp2.
the only real reason I've ever seen anyone use :response is for REDIRECT,
which now exists in :common, so I suspect that's why your code worked.
anyway, try this patch (against current CVS - I'm not sure if there have
been changes since the last release) which weeds out attempts to import
non-existent tags.
we still don't handle everything in compat.pm (such as MOVED,
USE_LOCAL_COPY, etc) but I don't really see a reason for supporting these
right now - :response is probably fairly common, as it exists in the eagle
book and lots of examples, but the rest are pretty rare in my experience.
anyway, let me know if it works for you. if not, we'll try something else.
--Geoff