Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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"


In reply to Re: Clawing my way out of operator overloading hell by ViceRaid
in thread Clawing my way out of operator overloading hell by skyknight

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (6)
    As of 2019-10-19 15:10 GMT
    Find Nodes?
      Voting Booth?