in reply to Clawing my way out of operator overloading hell

To answer your original question: you can use the Method function in the overload package to get a reference to the subroutine that implements a given operator for an overloaded class; eg:

my $thing = OverloadingClass->new(); my $subref = overload::Method($thing, 'eq');

You could then use something like Devel::Peek to discover the original package that implemented the subroutine reference that was returned. See the CvGV ("Code-Value-to-Glob-Value") method there. Here's a slightly inane example:

package MyOverLoaded; use overload 'eq' => \&my_equal; # just an example overloaded implementation of eq sub my_equal { my $self = shift; my $comparator = shift; return length($$self) == length($comparator); } sub new { my $class = shift; my $thing = shift; bless(\$thing, $class); } package OverLoadedSubClass; use base qw(MyOverLoaded); package main; use Devel::Peek qw(CvGV); my $thing = OverLoadedSubClass->new("It's my birthday!"); my $sub = overload::Method($thing, 'eq'); print CvGV($sub); # prints "*MyOverLoaded::my_equal"

Cheers
ViceRaid

Replies are listed 'Best First'.
Re: Re: Clawing my way out of operator overloading hell
by skyknight (Hermit) on Aug 01, 2003 at 16:22 UTC
    Yee-haw! Most of the other replies I got were interesting and insightful, but weren't quite the answers for which I was looking. Your reply explains exactly the kind of thing that I had hoped existed. Thanks a lot.