in reply to calling overloaded comparison operators as method calls?
If you make your selector like this:
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...my $selector = sub { $_[0] eq $whatever };
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 | |
by morgon (Priest) on Jul 06, 2009 at 09:56 UTC |