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 | |
7f9775b1 |
18 | $meta = Moose::Meta::Class->initialize('Spoon'); |
19 | |
20 | $meta->superclasses('Moose::Object'); |
21 | |
22 | Moose::Util::apply_all_roles($meta, 'Bar'); |
23 | |
24 | my $spoon = Spoon->new(four => 4); |
25 | |
26 | is($spoon->four, 4, 'Role application ok'); |
27 | |
e7739ca4 |
28 | { |
29 | package MooRequiresFour; |
30 | |
31 | use Moo::Role; |
32 | |
33 | requires 'four'; |
34 | |
35 | package MooRequiresGunDog; |
36 | |
37 | use Moo::Role; |
38 | |
39 | requires 'gun_dog'; |
40 | } |
41 | |
42 | lives_ok { |
43 | Moose::Util::apply_all_roles($meta, 'MooRequiresFour'); |
44 | } 'apply role with satisified requirement'; |
45 | |
46 | dies_ok { |
47 | Moose::Util::apply_all_roles($meta, 'MooRequiresGunDog'); |
48 | } 'apply role with unsatisified requirement'; |
49 | |
3362e41c |
50 | done_testing; |