in reply to Class Inheritance without an instance / $AUTOLOAD equ

It's not clear to me what problem you are trying to describe. Perhaps it would help if you showed a concrete example? For example, what is different about what you're trying to do, from that in the code below which correctly prints the name of the subclass?
package A; sub foo { print "$_[0]\n" } package B; @ISA = qw(A); package main; B->foo(); __END__ $ perl /tmp/p B

Dave.

Replies are listed 'Best First'.
Re^2: Class Inheritance without an instance
by dynamo (Chaplain) on Oct 13, 2005 at 11:43 UTC
    Here is the difference from your code:

    I am stuck with this kind of call:

    package main; B::foo();
    rather than this kind:
    package main; B->foo();
    which would be the same in practice (I believe) as:
    package main; B::foo(B);
    My problem is that neither the class name nor an instance are being passed. But it's still originally called as B::foo, so when I get to A::foo, it seems like it should be _somewhere_ that it was B::foo at first.

      B::foo(B) does not invoke inheritance. If A::foo ends up being executed, then it's not as a direct result of calling B::foo(B).

      (The slight exception to the the above is that AUTOLOAD is still inherited for non-method calls, although it's deprecated:

      package A; sub foo { print "A::foo called\n" } sub AUTOLOAD { print "A::AUTOLOAD called, \$AUTOLOAD=$AUTOLOAD\n" } package B; @ISA = qw(A); package main; B::foo('B'); __END__ $ perl /tmp/p Use of inherited AUTOLOAD for non-method B::foo() is deprecated at /tm +p/p line 11. A::AUTOLOAD called, $AUTOLOAD=B::foo $

      Dave.

        I think using an AUTOLOAD method to catch the apache handler call is the way to go here. Thank you for writing this out, it made it clear to me how easy that would be.
      If B inherits A, and B::foo isn't defined, but A::foo is, calling B::foo will fail. There's no such sub.

      If you want Perl to act in an OO way, you should make a method call, not a sub call. Use B->foo, and A::foo will be called.

      If you can't or won't, you're out of luck.

      use strict; use warnings; $| = 1; sub A::foo {print "This is A::foo\n"} @B::ISA = qw /A/; print "Calling B->foo(): "; B->foo(); print "Calling B::foo(): "; B::foo(); __END__ Calling B->foo(): This is A::foo Calling B::foo(): Undefined subroutine &B::foo called at ...
      Perl --((8:>*
      That was my best idea, given my understanding of mod_perl, but now i'm not as sure. I just tested what I did above and got an error that wasn't present in the apache logs. The interface is the same as any other mod_perl handler:

      sub handler { my $r = shift; my $err = ErrorTracker->new; # ... setup stuff my $args = validate_args($r, wrapped_handler_args()); $r->content_type('text/plain'); wrapped_handler($r,$args,$err); # shutdown / error handling stuff return $err->apacheStatus(); } sub wrapped_handler { print "inheritance is broken"; } sub wrapped_handler_args { return {}; }