in reply to perl inheritance

Is there a way to accomplish this without overriding all the base class methods?
That depends on how the superclass has implemented the methods.

But you may be able to do something like:

foreach my $method (... list of methods to override ...) { eval <<"EOT"; sub $method { my (\$self, \@args) = \@_; my $result = \$self->SUPER::$method(\@args); bless \$result, __PACKAGE__; \$result; } EOT }

Replies are listed 'Best First'.
Re^2: perl inheritance
by Anonymous Monk on Mar 23, 2012 at 18:38 UTC

    This is *very* interesting... Thank you! Would this be invoked in the constructor of the derived class?

    Thanks!
      Would this be invoked in the constructor of the derived class?
      Of course not! This is something you need to be done once, and on class level. So, you'd do it outside of any method. That way, it get executed when you use the module.
        This smells like a good place for an import method.. What do you think? thanks!

        this smells like it should go in an import method? What do you think ?