You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Cédric Bertolini <be...@gmail.com> on 2010/09/27 10:20:51 UTC
Using a handler other than 'handler'
Hello,
I apologize for such a trivial question, but I'd like to use a function
other than "handler" as a perl handler. According to the doc, it was
possible in mod_perl 1, but I can't manage to get it to work under mod_perl
2.
Here is an example of my code:
file Authen.pm
> sub handler {
> // regular handling
> }
>
> sub special {
> // special case
> }
file httpd.conf
> <Location /perl/>
> PerlAuthenHandler /lib/Authen
> </Location>
> <Location /perl/special-case/>
> # I want to override the regular case by using "special" instead of
"handler" in /lib/Authen.pm
> </Location>
Thanks in advance,
Cédric Bertolini
Re: Using a handler other than 'handler'
Posted by Michel Jansen <mj...@cmbi.ru.nl>.
Cédric,
Je schreef:
> Hello,
>
> I apologize for such a trivial question, but I'd like to use a
> function other than "handler" as a perl handler. According to the doc,
> it was possible in mod_perl 1, but I can't manage to get it to work
> under mod_perl 2.
I am using Apache2::RequestRec which fine for me. I am using it as an
AuthenHandler and as the starter for our restfull web application!
Questions?
Grtz,
Michel
Re: Using a handler other than 'handler'
Posted by Michael Peters <mp...@plusthree.com>.
On 09/27/2010 05:17 AM, Cédric Bertolini wrote:
> PerlAuthenHandler Authen::special
>
> doesn't work. It worked in mod_perl 1, but mod_perl 2 complains that it
> can't find Authen/special.pm <http://special.pm> in @INC.
That's not what he suggested. He said:
PerlAuthenHandler Authen->special
Try that and see if it works
--
Michael Peters
Plus Three, LP
Re: Using a handler other than 'handler'
Posted by Cédric Bertolini <be...@gmail.com>.
@John
Thanks for the reply, but
PerlAuthenHandler Authen::special
doesn't work. It worked in mod_perl 1, but mod_perl 2 complains that it
can't find Authen/special.pm in @INC.
@André,
Thanks for the reply. I was reluctant to use this solution because of the
OOC orientation of this syntax, but it isn't actually mandatory to define a
class in order to use this. You just have to be aware that the custom
handler will receive the request object as its second argument instead of
the first.
---
package Authen;
sub handler {
my ($r) = @_;
# regular case with $r as the request object
}
sub special {
my (undef, $r) = @_;
# special case with $r as the request object
}
---
PerlAuthenHandler Authen->special
---
Cheers,
Cédric Bertolini
2010/9/27 André Warnier <aw...@ice-sa.com>
> Hi.
>
> You can use
>
> PerlAuthenhandler Your::Module->special
>
> See http://perl.apache.org/docs/2.0/user/coding/coding.html#Techniques
>
>
>
>
> Cédric Bertolini wrote:
>
>> @Michel,
>>
>> Thanks for the reply. As far as I know, Apache2::RequestRec is a module
>> that
>> provides several functions to manage the $request object provided by
>> mod_perl (http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html).
>> It's
>> not really a handler, though most handlers use this module one way or
>> another. I just want to use a different handler than usual, but from the
>> same file, If that's possible.
>>
>> @Nico
>>
>> Thanks for the reply. Deciding on a behavior based on $r->uri or
>> $r->filename in the handler is what I was doing previously, but I'd love
>> to
>> have a solution based the config file instead of the handler itself, for
>> robustness. I will have to stick to this solution if mod_perl doesn't let
>> me
>> provide the name of the handler, though.
>>
>>
>>
>> 2010/9/27 Nico Coetzee <ni...@gmail.com>
>>
>> I had a similar requirement. My solution: based on the value of $r->uri()
>>> I
>>> would call the different subs from the main handler() sub. All the other
>>> subs take $r as the first argument and then the rest of the parameters
>>> follow.
>>>
>>> Probably not the best solution, but it worked for me.
>>>
>>> Cheers
>>>
>>> Nico
>>>
>>> 2010/9/27 Cédric Bertolini <be...@gmail.com>
>>>
>>> Hello,
>>>
>>>> I apologize for such a trivial question, but I'd like to use a function
>>>> other than "handler" as a perl handler. According to the doc, it was
>>>> possible in mod_perl 1, but I can't manage to get it to work under
>>>> mod_perl
>>>> 2.
>>>>
>>>>
>>>> Here is an example of my code:
>>>>
>>>> file Authen.pm
>>>>
>>>> sub handler {
>>>>> // regular handling
>>>>> }
>>>>>
>>>>> sub special {
>>>>> // special case
>>>>> }
>>>>>
>>>> file httpd.conf
>>>>
>>>> <Location /perl/>
>>>>> PerlAuthenHandler /lib/Authen
>>>>> </Location>
>>>>> <Location /perl/special-case/>
>>>>> # I want to override the regular case by using "special" instead of
>>>>>
>>>> "handler" in /lib/Authen.pm
>>>>
>>>>> </Location>
>>>>>
>>>> Thanks in advance,
>>>> Cédric Bertolini
>>>>
>>>>
>>>>
>>
>
Re: Using a handler other than 'handler'
Posted by André Warnier <aw...@ice-sa.com>.
Hi.
You can use
PerlAuthenhandler Your::Module->special
See http://perl.apache.org/docs/2.0/user/coding/coding.html#Techniques
Cédric Bertolini wrote:
> @Michel,
>
> Thanks for the reply. As far as I know, Apache2::RequestRec is a module that
> provides several functions to manage the $request object provided by
> mod_perl (http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html). It's
> not really a handler, though most handlers use this module one way or
> another. I just want to use a different handler than usual, but from the
> same file, If that's possible.
>
> @Nico
>
> Thanks for the reply. Deciding on a behavior based on $r->uri or
> $r->filename in the handler is what I was doing previously, but I'd love to
> have a solution based the config file instead of the handler itself, for
> robustness. I will have to stick to this solution if mod_perl doesn't let me
> provide the name of the handler, though.
>
>
>
> 2010/9/27 Nico Coetzee <ni...@gmail.com>
>
>> I had a similar requirement. My solution: based on the value of $r->uri() I
>> would call the different subs from the main handler() sub. All the other
>> subs take $r as the first argument and then the rest of the parameters
>> follow.
>>
>> Probably not the best solution, but it worked for me.
>>
>> Cheers
>>
>> Nico
>>
>> 2010/9/27 Cédric Bertolini <be...@gmail.com>
>>
>> Hello,
>>> I apologize for such a trivial question, but I'd like to use a function
>>> other than "handler" as a perl handler. According to the doc, it was
>>> possible in mod_perl 1, but I can't manage to get it to work under mod_perl
>>> 2.
>>>
>>>
>>> Here is an example of my code:
>>>
>>> file Authen.pm
>>>
>>>> sub handler {
>>>> // regular handling
>>>> }
>>>>
>>>> sub special {
>>>> // special case
>>>> }
>>> file httpd.conf
>>>
>>>> <Location /perl/>
>>>> PerlAuthenHandler /lib/Authen
>>>> </Location>
>>>> <Location /perl/special-case/>
>>>> # I want to override the regular case by using "special" instead of
>>> "handler" in /lib/Authen.pm
>>>> </Location>
>>> Thanks in advance,
>>> Cédric Bertolini
>>>
>>>
>
Re: Using a handler other than 'handler'
Posted by Cédric Bertolini <be...@gmail.com>.
@Michel,
Thanks for the reply. As far as I know, Apache2::RequestRec is a module that
provides several functions to manage the $request object provided by
mod_perl (http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html). It's
not really a handler, though most handlers use this module one way or
another. I just want to use a different handler than usual, but from the
same file, If that's possible.
@Nico
Thanks for the reply. Deciding on a behavior based on $r->uri or
$r->filename in the handler is what I was doing previously, but I'd love to
have a solution based the config file instead of the handler itself, for
robustness. I will have to stick to this solution if mod_perl doesn't let me
provide the name of the handler, though.
2010/9/27 Nico Coetzee <ni...@gmail.com>
> I had a similar requirement. My solution: based on the value of $r->uri() I
> would call the different subs from the main handler() sub. All the other
> subs take $r as the first argument and then the rest of the parameters
> follow.
>
> Probably not the best solution, but it worked for me.
>
> Cheers
>
> Nico
>
> 2010/9/27 Cédric Bertolini <be...@gmail.com>
>
> Hello,
>>
>> I apologize for such a trivial question, but I'd like to use a function
>> other than "handler" as a perl handler. According to the doc, it was
>> possible in mod_perl 1, but I can't manage to get it to work under mod_perl
>> 2.
>>
>>
>> Here is an example of my code:
>>
>> file Authen.pm
>>
>> > sub handler {
>> > // regular handling
>> > }
>> >
>> > sub special {
>> > // special case
>> > }
>>
>> file httpd.conf
>>
>> > <Location /perl/>
>> > PerlAuthenHandler /lib/Authen
>> > </Location>
>>
>> > <Location /perl/special-case/>
>> > # I want to override the regular case by using "special" instead of
>> "handler" in /lib/Authen.pm
>> > </Location>
>>
>> Thanks in advance,
>> Cédric Bertolini
>>
>>
>