implement remove_overloaded_operator
Jesse Luehrs [Sat, 10 Mar 2012 23:37:41 +0000 (17:37 -0600)]
lib/Class/MOP/Mixin/HasMethods.pm
t/metaclasses/overloading.t

index 5f6a4db..c2e870a 100644 (file)
@@ -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) = @_;
index ebc2f12..ba5f1d5 100644 (file)
@@ -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;