From: Jesse Luehrs Date: Sat, 10 Mar 2012 23:37:41 +0000 (-0600) Subject: implement remove_overloaded_operator X-Git-Tag: 2.0500~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=702be3d89ea803c8ece85c0bfaccfdff72f6cd0b;p=gitmo%2FMoose.git implement remove_overloaded_operator --- diff --git a/lib/Class/MOP/Mixin/HasMethods.pm b/lib/Class/MOP/Mixin/HasMethods.pm index 5f6a4db..c2e870a 100644 --- a/lib/Class/MOP/Mixin/HasMethods.pm +++ b/lib/Class/MOP/Mixin/HasMethods.pm @@ -264,6 +264,14 @@ sub add_overloaded_operator { $self->name->overload::OVERLOAD($op => $body); } +sub remove_overloaded_operator { + my $self = shift; + my ($op) = @_; + # ugh, overload.pm provides no api for this + $self->get_or_add_package_symbol('%OVERLOAD')->{dummy}++; + $self->remove_package_symbol('&(' . $op); +} + sub _get_overloaded_operator_body { my $self = shift; my ($op) = @_; diff --git a/t/metaclasses/overloading.t b/t/metaclasses/overloading.t index ebc2f12..ba5f1d5 100644 --- a/t/metaclasses/overloading.t +++ b/t/metaclasses/overloading.t @@ -94,6 +94,11 @@ BEGIN { $plus_impl = sub { $plus = 1; "plus" } } is($minus, 0); is(Foo::Overloaded->new - Foo::Overloaded->new, "minus"); is($minus, 1); + + $meta->remove_overloaded_operator('-'); + + like(exception { Foo::Overloaded->new - Foo::Overloaded->new }, + qr/Operation "-": no method found/); } done_testing;