4 use Test::More tests => 24;
16 sub name { $_[0]->{name} = $_[1] if @_ > 1; $_[0]->{name} }
17 sub age { $_[0]->{age} = $_[1] if @_ > 1; $_[0]->{age} }
25 default => sub { Person->new(age => 37, name => "Chuck") },
26 predicate => 'has_person',
28 person_name => 'name',
35 default => sub { Person->new(age => 21, name => "Shawn") },
37 handles => [qw/name age/],
41 local our $TODO = "Mouse lacks this";
47 ::ok(!$@, "handles => role");
51 local our $TODO = "Mouse lacks this";
54 handles => \"ref_to_string",
57 ::ok(!$@, "handles => \\str");
61 local our $TODO = "Mouse lacks this";
67 ::ok(!$@, "handles => qr/re/");
71 local our $TODO = "Mouse lacks this";
74 handles => sub { "code" },
77 ::ok(!$@, "handles => sub { code }");
81 can_ok(Class => qw(person has_person person_name person_age name age quid));
83 my $object = Class->new;
84 ok(!$object->has_person, "don't have a person yet");
85 $object->person_name("Todd");
86 ok($object->has_person, "calling person_name instantiated person");
87 ok($object->person, "we really do have a person");
89 is($object->person_name, "Todd", "handles method");
90 is($object->person->name, "Todd", "traditional lookup");
91 is($object->person_age, 37, "handles method");
92 is($object->person->age, 37, "traditional lookup");
94 my $object2 = Class->new(person => Person->new(name => "Philbert"));
95 ok($object2->has_person, "we have a person from the constructor");
96 is($object2->person_name, "Philbert", "handles method");
97 is($object2->person->name, "Philbert", "traditional lookup");
98 is($object2->person_age, undef, "no age because we didn't use the default");
99 is($object2->person->age, undef, "no age because we didn't use the default");
102 ok($object->quid, "we have a Shawn");
103 is($object->name, "Shawn", "name handle");
104 is($object->age, 21, "age handle");
105 is($object->me->name, "Shawn", "me->name");
106 is($object->me->age, 21, "me->age");
109 $object->meta->get_attribute('me')->handles,
111 "correct handles layout for 'me'",
115 $object->meta->get_attribute('person')->handles,
116 { person_name => 'name', person_age => 'age' },
117 "correct handles layout for 'person'",