I am no OO wizard and i really don't fully understand what you are trying to accomplish. I am intriqued by the question however, and i toyed around trying to find a solution. From what i can gather, you are trying to call SUPER after you have already 'backed up' to the SUPER object - not a recommended thing to do.

Instead, how about a more traditional polymorphic approach:

package Foo; use strict; sub new { bless {}, shift(); } sub do_something { my $self = shift; my $name = shift || 'foo'; return make_do_something($name); } sub make_do_something { my $name = shift; return sub { my $self = shift; print "Foo $name!!!\n"; } } 1; ############################################## package Bar; use strict; use base 'Foo'; sub new { bless {}, shift(); } sub do_something { my $self = shift; return $self->SUPER::do_something('bar'); } 1;
I _think_ this will accomodate your needs ...

This is my test script. The big difference is that the do_something() method returns a code ref, so you need to add some syntax:

#!/usr/bin/perl -w use strict; use Foo; use Bar; $_->do_something()->() for (new Foo, new Bar);
The reason why is, well - i don't know exactly what you are trying to accomplish by returning a sub in your make_do_something() method. If the only reason you do that is to create a method, then you can use this code and just drop make_do_something() completely. Everything you need is in Foo::do_something(). Hope this helps.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Trying to re-use code at different levels of an inherited object. by jeffa
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.