in reply to (jeffa) Re: Trying to re-use code at different levels of an inherited object.
in thread Trying to re-use code at different levels of an inherited object.
If it were that simple, I'd be set :)
I'm sorry that I didn't make sense the first time. The issue is that I want to recursively call SUPER::do_something all the way up to the top most superclass that can do_something. I could do that like this:
package A; sub do_something { print "Foo\n"; } package B; @ISA = ( A ); sub do_something { my $self = shift; $self->SUPER::do_something(); print "Bar\n"; }
But, I'd end up with a whole bunch of stub modules sitting around that were all almost identical, save a literal constant ("Foo\n" vs. "Bar\n") and the fact that A does not call SUPER::do_something(). Shouldn't I be able to abstract this all away so that I only have to implement do_something() once and not worry about making stubs in all my modules? As I said, I'm not very experienced with closures, but I thought this is what they were all about. It would be more maintainable if I could change the requirements of do_something() in the future and NOT have to go change every one of my stubs.
I guess I should just suck it up and write the stubs.
|
|---|