Your question stands on its own merits, of course, but I'm still puzzled as to why one would want to do it. The syntax you describe above could be accomplished without overloading simply by using the wrapped functions reference address as a key into a hash that stores the original code reference. This would also give you the advantage of making the definition of i_know_what_im_doing class specific. Perhaps you could suggest another use case where overloading really is essential? The modified routine for those interested (I expect the OP could easily write it on his/her own).

use Scalar::Util; { package Before; my %hUnwrapped; sub new { my ($sClass,$f) = @_; my $fBefore= sub { print "Special stuff for class $sClass\n"; goto &$f }; $hUnwrapped{Scalar::Util::refaddr($fBefore)}=$f; return bless($fBefore,$sClass); } sub i_know_what_im_doing { my $k = Scalar::Util::refaddr(shift); goto $hUnwrapped{$k}; } } my $f1=Before->new(sub {print "Hello @_!\n";}); print "Wrapped sub\n-------------\n"; $f1->('tweedledum','tweedledee'); print "\nUnwrapped sub\n-------------\n"; $f1->i_know_what_im_doing('walrus','carpenter');

which prints

Wrapped sub ------------- Special stuff for class Before Hello tweedledum tweedledee! Unwrapped sub ------------- Hello walrus carpenter!

Best, beth

Update: distinguished my question from OP's and clarified my own question which is still about why


In reply to Re^3: Overloading without infinite descent by ELISHEVA
in thread Overloading without infinite descent (fixed by time: see Perl 5.10.1) by JadeNB

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.