return; from with/etc.
[gitmo/Moo.git] / xt / handle_moose.t
CommitLineData
3362e41c 1use strictures 1;
e7739ca4 2use Test::Exception;
3362e41c 3
4BEGIN { require "t/moo-accessors.t"; }
5
8c46a8f6 6require Moose;
3362e41c 7
8my $meta = Class::MOP::get_metaclass_by_name('Foo');
9
10my $attr;
11
12ok($attr = $meta->get_attribute('one'), 'Meta-attribute exists');
13is($attr->get_read_method, 'one', 'Method name');
14is($attr->get_read_method_ref->body, Foo->can('one'), 'Right method');
15
16is(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
22Moose::Util::apply_all_roles($meta, 'Bar');
23
24my $spoon = Spoon->new(four => 4);
25
26is($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
42lives_ok {
43 Moose::Util::apply_all_roles($meta, 'MooRequiresFour');
44} 'apply role with satisified requirement';
45
46dies_ok {
47 Moose::Util::apply_all_roles($meta, 'MooRequiresGunDog');
48} 'apply role with unsatisified requirement';
49
3362e41c 50done_testing;