Commit | Line | Data |
3362e41c |
1 | use strictures 1; |
e7739ca4 |
2 | use Test::Exception; |
3362e41c |
3 | |
4 | BEGIN { require "t/moo-accessors.t"; } |
5 | |
8c46a8f6 |
6 | require Moose; |
3362e41c |
7 | |
8 | my $meta = Class::MOP::get_metaclass_by_name('Foo'); |
9 | |
10 | my $attr; |
11 | |
12 | ok($attr = $meta->get_attribute('one'), 'Meta-attribute exists'); |
13 | is($attr->get_read_method, 'one', 'Method name'); |
14 | is($attr->get_read_method_ref->body, Foo->can('one'), 'Right method'); |
15 | |
16 | is(Foo->new(one => 1, THREE => 3)->one, 1, 'Accessor still works'); |
17 | |
6e77b8df |
18 | is( |
19 | Foo->meta->get_attribute('one')->get_read_method, 'one', |
20 | 'Method name via ->meta' |
21 | ); |
22 | |
7f9775b1 |
23 | $meta = Moose::Meta::Class->initialize('Spoon'); |
24 | |
25 | $meta->superclasses('Moose::Object'); |
26 | |
27 | Moose::Util::apply_all_roles($meta, 'Bar'); |
28 | |
29 | my $spoon = Spoon->new(four => 4); |
30 | |
31 | is($spoon->four, 4, 'Role application ok'); |
32 | |
e7739ca4 |
33 | { |
34 | package MooRequiresFour; |
35 | |
36 | use Moo::Role; |
37 | |
38 | requires 'four'; |
39 | |
40 | package MooRequiresGunDog; |
41 | |
42 | use Moo::Role; |
43 | |
44 | requires 'gun_dog'; |
45 | } |
46 | |
47 | lives_ok { |
48 | Moose::Util::apply_all_roles($meta, 'MooRequiresFour'); |
49 | } 'apply role with satisified requirement'; |
50 | |
51 | dies_ok { |
52 | Moose::Util::apply_all_roles($meta, 'MooRequiresGunDog'); |
53 | } 'apply role with unsatisified requirement'; |
54 | |
3362e41c |
55 | done_testing; |