I agree that, if I'm willing to wrap at construction time, then the problem may be solved exactly as you describe. I was just wondering (specifically for the reason that I've described—and because I'm stubborn and want to do something the first way that occurred to me :-)—but more generally because it seems like an interesting, and possibly useful, thing to do) whether it's possible to get at the ‘true’ behaviour of an object which is subject to
overloading.
A use case (which is not my actual situation) might go as follows: Imagine that Perl prototypes don't exist, and we're trying to create them. Then one could imagine wanting to write code like this:
package Prototype;
use overload
'&{}' => sub {
my ( $f ) = @_;
return sub {
check_arguments(@_);
goto &$f;
};
};
sub i_know_what_im_doing {
my $f = shift;
goto &$f;
}
so that executing
$f->(@args)
would check the prototype, but executing
$f->i_know_what_im_doing(@args)
wouldn't.
(It's not a very good use case, because we have to store the prototype somewhere, and, if we are good and store it in the object, then it's easy to find a way around the problem. :-) )
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.