Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: perl inheritance

by JavaFan (Canon)
on Mar 23, 2012 at 18:26 UTC ( #961278=note: print w/ replies, xml ) Need Help??


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 }


Comment on Re: perl inheritance
Download Code
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 ?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://961278]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2014-08-31 02:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls