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.


In reply to Re: (jeffa) Re: Trying to re-use code at different levels of an inherited object. by ehdonhon
in thread Trying to re-use code at different levels of an inherited object. by ehdonhon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.