test the pre-5.8.3 weak_ref setter code on newer perls too
[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
6e77b8df 18is(
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
27Moose::Util::apply_all_roles($meta, 'Bar');
28
29my $spoon = Spoon->new(four => 4);
30
31is($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
47lives_ok {
48 Moose::Util::apply_all_roles($meta, 'MooRequiresFour');
49} 'apply role with satisified requirement';
50
51dies_ok {
52 Moose::Util::apply_all_roles($meta, 'MooRequiresGunDog');
53} 'apply role with unsatisified requirement';
54
3362e41c 55done_testing;