You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Martijn <sw...@googlemail.com> on 2007/03/01 11:11:02 UTC

PerlAuthenHandler

Hello.

I've been building a perl script that automatically logs a visitor  in
upon visiting the website (given that they're not logged in already
and they have chosen to be remembered by the server etc.).
I've written a handler that does this and I call it using

	PerlAuthenHandler MyRoot::Testing

which executes the handler subroutine in the MyRoot/Testing.pm module.
This works well, though I'm not sure if there aren't nicer solutions
to this; after all there is no authentication taking place here, the
script returns OK both if the visitor is actually logged in and if,
for some reason, they aren't.

But my main concern is that I'd like to rename the subroutine to
something more appropriate, especially since I might want to use more
than one 'handler' and wouldn't want to create modules for each of
then. However, when I try to change it to MyRoot::Testing->autologin I
get an error that it can't find the MyRoot/Testing/autologin.pm
module. This surprises me in particular because the line above the
PerlAuthenHandler one is

	PerlAuthenHandler MyRoot::AxKit::Plugin::Authenticate->authenticate

which, indeed, calls the authenticate subroutine from said module. But
even placing my handler subroutine there doesn't work... Could it
perhaps be that PerlAuthenHandler shouldn't be called twice?
It's not a very big problem, as it works fine now, and I could always
make different modules, but it just isn't very tidy. And I just like
to understand things.

Thanks.

Martijn

Re: PerlAuthenHandler

Posted by Martijn <sw...@googlemail.com>.
This, of course, is the solution. Thanks, both!

In case you wonder why I hadn't just copied a working handler and
started by changing that, I wonder too. Stubborn is my middle name, I
am afraid.

Martijn

On 3/1/07, Martin Moss <ma...@btopenworld.com> wrote:
> As I understand it...
>
> if you use this ->autologin   the first argument to
> your autologin subroutine will be a string
> 'MyRoot::Testing'
>
> if you use ::autologin  It won't be...
>
> Perhaps this might have something to do with it...
>
>
>
> I setup my subroutines like this:-
>
> ====http.conf
>
> PerlModule MyRoot::Testing
> PerlAuthenHandler MyRoot::Testing->autologin
>
> ===Testing.pm
>
> sub autologin : method
> {
>     my $class =shift;
>     my $r = shift;
>
> }

Re: PerlAuthenHandler

Posted by Perrin Harkins <ph...@gmail.com>.
On 3/1/07, Martijn <sw...@googlemail.com> wrote:
> But then it still didn't work, until for some reason I changed
>   PerlAuthenHandler MyRoot::Testing->autologin
> to
>   PerlAuthenHandler MyRoot::Testing::autologin

Don't forget to mark autologin as a method.  In mod_perl 2, that means
adding a sub attribute of "method" to it.

- Perrin

Re: PerlAuthenHandler

Posted by Martin Moss <ma...@btopenworld.com>.
As I understand it...

if you use this ->autologin   the first argument to
your autologin subroutine will be a string
'MyRoot::Testing'

if you use ::autologin  It won't be...

Perhaps this might have something to do with it...



I setup my subroutines like this:-

====http.conf

PerlModule MyRoot::Testing
PerlAuthenHandler MyRoot::Testing->autologin

===Testing.pm

sub autologin : method
{
    my $class =shift;
    my $r = shift;

}


--- Martijn <sw...@googlemail.com> wrote:

> As someone here pointed out in an off-list email
> (thanks!), I had
> forgotten to load the perl module, by writing
>   PerlModule MyRoot::Testing
> in httpd.conf. That wasn't very clever...
> 
> But then it still didn't work, until for some reason
> I changed
>   PerlAuthenHandler MyRoot::Testing->autologin
> to
>   PerlAuthenHandler MyRoot::Testing::autologin
> 
> It's doing my head in, as in the line above this
> one, a -> is used
> without any problems. It's all not very important,
> but I'd like to
> write code of which I understand why it works,
> rather than code that
> just happens to work.
> 
> Martijn.
> 



		
___________________________________________________________ 
Copy addresses and emails from any email account to Yahoo! Mail - quick, easy and free. http://uk.docs.yahoo.com/trueswitch2.html

Re: PerlAuthenHandler

Posted by Martijn <sw...@googlemail.com>.
As someone here pointed out in an off-list email (thanks!), I had
forgotten to load the perl module, by writing
  PerlModule MyRoot::Testing
in httpd.conf. That wasn't very clever...

But then it still didn't work, until for some reason I changed
  PerlAuthenHandler MyRoot::Testing->autologin
to
  PerlAuthenHandler MyRoot::Testing::autologin

It's doing my head in, as in the line above this one, a -> is used
without any problems. It's all not very important, but I'd like to
write code of which I understand why it works, rather than code that
just happens to work.

Martijn.