Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Overloading functions

by BigJoe (Curate)
on Jun 18, 2002 at 18:19 UTC ( #175445=perlquestion: print w/ replies, xml ) Need Help??
BigJoe has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to overload a function in a module. I was reading the documentation about Apache::AuthenNTLM to tweak it to what I need and I want to overload the handler function like he describes but it doesn't work. The line This override rules never gets written. Does any one know where I can find information on debugging method overiding?
package MyOverride; use strict; use Apache::AuthenNTLM; use Apache::Constants qw(OK FORBIDDEN REDIRECT); @MyOverride::ISA = qw(Apache::AuthenNTLM) sub handler ($$) { my ($self, $r) = @_; print STDERR "\n\n\n\n\n\n\nThis override Rules\n\n\n\n\n\n\n\n"; return Apache::AuthenNTLM::handler ($self, $r) if(0); return OK; } 1;


--BigJoe

Learn patience, you must.
Young PerlMonk, craves Not these things.
Use the source Luke.

Comment on Overloading functions
Download Code
Re: Overloading functions
by samtregar (Abbot) on Jun 18, 2002 at 18:36 UTC
    How are you using Apache::AuthenNTLM? For this change to work you'll need to change any references to Apache::AuthenNTLM to use your new sub-class MyOverride. For example, if this was used as an Authen handler (just a guess) you would use:

    PerlAuthenHandler MyOverride

    Does that help?

    BTW: the correct term for what you're doing above is overriding. Overloading refers to something totally different - see overload for details.

    -sam

Re: Overloading functions
by BigJoe (Curate) on Jun 18, 2002 at 18:47 UTC
    I forgot to add my httpd.conf stuff.
    <Location /> PerlAuthenHandler MyOverride AuthName "Warning you are entering a development server!! (an +d being logged)" AuthType ntlm,Basic PerlAddVar ntdomain "DOM MyPDC " PerlSetVar defaultdomain DOM PerlSetVar ntlmdebug 1 require valid-user </Location>


    --BigJoe

    Learn patience, you must.
    Young PerlMonk, craves Not these things.
    Use the source Luke.
Re: Overloading functions
by domm (Chaplain) on Jun 18, 2002 at 19:52 UTC
    I know nothing about Apache::AuthenNTLM, but I assume you did the obvious things, like restarting Apache etc?

    One reason might be that you have written your handler as a method handler (sub handler ($$)), but are calling it like a normal handler.

    Try this in your httpd.conf

    PerlAuthenHandler MyOverride->handler

    Or change your handler to a "normal" handler, like so:

    sub handler { my $r = shift; ...

    What about not printing to STDERR, but to use $r->log->error('bla')

    You could post you message to the mod_perl mailing list, but please read this before you do. There are a lot of very clever minds there...

    -- #!/usr/bin/perl for(ref bless[],just'another'perl'hacker){s-:+-$"-g&&print$_.$/}
      I gave your two suggestions a try. The first one gives me an error that possibly MyOverride has not been loaded. The second runs but nothing is populated in the error log. I will change my print STDERR to $r->log->error but I don't think that will fix it because when I wrote some mod_perl that wasn't doing this but still generating errors I used STDERR.

      Thanks for your suggestions. I will send out an email to the mod_perl mailing list too.

      --BigJoe

      Learn patience, you must.
      Young PerlMonk, craves Not these things.
      Use the source Luke.
Re: Overloading functions Works
by BigJoe (Curate) on Jun 19, 2002 at 15:51 UTC
    This version works for me. Thanks for all the suggestions.
    package MyOverride; use strict; use Apache::AuthenNTLM; use Apache::Constants qw(OK FORBIDDEN REDIRECT); @MyOverride::ISA = qw(Apache::AuthenNTLM); sub handler ($$) { my ($self, $r) = @_; warn ("\n\n\n\n\n\n\nThis override Rules\n\n\n\n\n\n\n\n"); return $self->Apache::AuthenNTLM::handler ($r) if(1); return OK; } 1;


    --BigJoe

    Learn patience, you must.
    Young PerlMonk, craves Not these things.
    Use the source Luke.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://175445]
Approved by samtregar
Front-paged by samtregar
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2014-09-01 14:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (13 votes), past polls