6079960f08b133516a7fcdd346d7aaa1f6234f4f
[gitmo/Moose.git] / t / 100_bugs / 024_anon_method_metaclass.t
1 use strict;
2 use warnings;
3 use Test::More tests => 8;
4
5 do {
6     package Ball;
7     use Moose;
8
9     package Arbitrary::Roll;
10     use Moose::Role;
11 };
12
13 my $method_meta = Moose::Meta::Class->create_anon_class(
14     superclasses => ['Moose::Meta::Method'],
15     roles        => ['Arbitrary::Roll'],
16 );
17
18 # For comparing identity without actually keeping $original_meta around
19 my $original_meta = "$method_meta";
20
21 my $method_class  = $method_meta->name;
22
23 my $method_object = $method_class->wrap(
24     sub { 'ok' },
25     associated_metaclass => Ball->meta,
26     package_name         => 'Ball',
27     name                 => 'bounce',
28 );
29
30 Ball->meta->add_method(bounce => $method_object);
31
32 for (1, 2) {
33     is(Ball->bounce, 'ok', "method still exists on Ball");
34     is(Ball->meta->get_method('bounce')->meta->name, $method_class, "method's package still exists");
35
36     local $TODO = "method seems to be reinitialized" if !$method_meta;
37
38     is(Ball->meta->get_method('bounce')->meta . '', $original_meta, "method's metaclass still exists");
39     ok(Ball->meta->get_method('bounce')->meta->does_role('Arbitrary::Roll'), "method still does Arbitrary::Roll");
40
41     undef $method_meta;
42 };
43
44