From: Jesse Luehrs Date: Thu, 8 Mar 2012 07:09:57 +0000 (-0600) Subject: provide an is_overloaded method X-Git-Tag: 2.0500~22 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c18e272e9602650d75112d2921d67abe167b7b6d;p=gitmo%2FMoose.git provide an is_overloaded method --- diff --git a/lib/Class/MOP/Mixin/HasMethods.pm b/lib/Class/MOP/Mixin/HasMethods.pm index 9ecfd69..f714cd5 100644 --- a/lib/Class/MOP/Mixin/HasMethods.pm +++ b/lib/Class/MOP/Mixin/HasMethods.pm @@ -211,12 +211,17 @@ sub overload_operators { return @$overload_operators; } +sub is_overloaded { + my $self = shift; + return overload::Overloaded($self->name); +} + # XXX this could probably stand to be cached, but i figure it should be # uncommon enough to not particularly matter sub _overload_map { my $self = shift; - return {} unless overload::Overloaded($self->name); + return {} unless $self->is_overloaded; my %map; for my $op ($self->overload_operators) { diff --git a/t/metaclasses/overloading.t b/t/metaclasses/overloading.t index 3621dd9..f2227c8 100644 --- a/t/metaclasses/overloading.t +++ b/t/metaclasses/overloading.t @@ -12,6 +12,8 @@ use Test::Fatal; { my $meta = Foo->meta; + ok(!$meta->is_overloaded); + is_deeply([sort $meta->overload_operators], [sort map { split /\s+/ } values %overload::ops]); @@ -38,6 +40,8 @@ BEGIN { $plus_impl = sub { $plus = 1; "plus" } } { my $meta = Foo::Overloaded->meta; + ok($meta->is_overloaded); + ok($meta->has_overloaded_operator('+')); ok(!$meta->has_overloaded_operator('-'));