in reply to Overloading different instances differently.
Memoizing would solve both of those problems. Matching sub refs isn't that hard. The following code will turn your hash into a string suitable for memoizing.
Another solution is to overload all of the methods you may wish to be able to overload with methods that dynamically figure out the right function to call. If you only have a small number of methods that you'll be overloading this isn't a bad route. But if you could potentially wind up overloading all of the possible things in overload, then doing this basically means re-creating all of the dispatch logic in overload in your code. Which you may not want to do.use Scalar::Util qw(refaddr); sub overload_string_specification { my $overload = shift; join " ", map { ($_=>refaddr($overload->{$_})) } sort keys %$overload; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Overloading different instances differently.
by plobsing (Friar) on Feb 23, 2008 at 01:40 UTC | |
by tilly (Archbishop) on Feb 23, 2008 at 03:48 UTC | |
by lodin (Hermit) on Feb 23, 2008 at 15:51 UTC | |
|
Re^2: Overloading different instances differently.
by kyle (Abbot) on Feb 22, 2008 at 22:23 UTC |