in reply to calling overloaded comparison operators as method calls?

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; } };

Replies are listed 'Best First'.
Re^2: calling overloaded comparison operators as method calls?
by perl5ever (Pilgrim) on Jul 05, 2009 at 20:47 UTC
    What I want is the overload::Method function. That way I don't have to write separate conditionals for each operation.

    Thanks!

      btw: All of that is covered in the manpage (perldoc overload) - rtfm :-)