15 is_deeply([sort $meta->overload_operators],
16 [sort map { split /\s+/ } values %overload::ops]);
18 ok(!$meta->has_overloaded_operator('+'));
19 ok(!$meta->has_overloaded_operator('-'));
21 is_deeply([$meta->get_overloaded_operators], []);
23 is_deeply([$meta->get_overload_list], []);
25 is($meta->get_overloaded_operator('+'), undef);
26 is($meta->get_overloaded_operator('-'), undef);
31 BEGIN { $plus_impl = sub { $plus = 1; "plus" } }
33 package Foo::Overloaded;
35 use overload '+' => $plus_impl;
39 my $meta = Foo::Overloaded->meta;
41 ok($meta->has_overloaded_operator('+'));
42 ok(!$meta->has_overloaded_operator('-'));
44 is_deeply([$meta->get_overloaded_operators], ['+']);
46 my @overloads = $meta->get_overload_list;
47 is(scalar(@overloads), 1);
48 my $plus_meth = $overloads[0];
49 isa_ok($plus_meth, 'Class::MOP::Method::Overload');
50 is($plus_meth->operator, '+');
51 is($plus_meth->name, '(+');
52 is($plus_meth->body, $plus_impl);
53 is($plus_meth->package_name, 'Foo::Overloaded');
54 is($plus_meth->associated_metaclass, $meta);
56 my $plus_meth2 = $meta->get_overloaded_operator('+');
57 { local $TODO = "we don't cache these yet";
58 is($plus_meth2, $plus_meth);
60 is($plus_meth2->operator, '+');
61 is($plus_meth2->body, $plus_impl);
62 is($meta->get_overloaded_operator('-'), undef);
65 is(Foo::Overloaded->new + Foo::Overloaded->new, "plus");
69 my $minus_impl = sub { $minus = 1; "minus" };
71 like(exception { Foo::Overloaded->new - Foo::Overloaded->new },
72 qr/Operation "-": no method found/);
74 $meta->add_overloaded_operator('-' => $minus_impl);
76 ok($meta->has_overloaded_operator('-'));
78 is_deeply([sort $meta->get_overloaded_operators], ['+', '-']);
80 is(scalar($meta->get_overload_list), 2);
82 my $minus_meth = $meta->get_overloaded_operator('-');
83 isa_ok($minus_meth, 'Class::MOP::Method::Overload');
84 is($minus_meth->operator, '-');
85 is($minus_meth->name, '(-');
86 is($minus_meth->body, $minus_impl);
87 is($minus_meth->package_name, 'Foo::Overloaded');
88 is($minus_meth->associated_metaclass, $meta);
91 is(Foo::Overloaded->new - Foo::Overloaded->new, "minus");