I am not sure if I understand your problem.

If you make your selector like this:

my $selector = sub { $_[0] eq $whatever };
Then you can call it with any object as $selector->($object) (parentheses - not curly braces to call it!) and it will either use the built-in eq or the overloaded version. As far as I understand you that is what you want which is why I probably don't understand you...

But as an aside you can get a reference to the overloading method with overload::Method, so if you really wanted you could to something like (for the "eq"-case)

my $selector = sub { my($obj)=@_; my $code_ref = overload::Method($obj, "eq"); if($code_ref) { # $obj overloads "eq" # call the overloading-implementation return $code_ref->($obj, $whatever); else { # no overloading -do something else return $obj eq $whatever; } };

In reply to Re: calling overloaded comparison operators as method calls? by morgon
in thread calling overloaded comparison operators as method calls? by perl5ever

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.