4 use Test::More tests => 24;
17 sub name { $_[0]->{name} = $_[1] if @_ > 1; $_[0]->{name} }
18 sub age { $_[0]->{age} = $_[1] if @_ > 1; $_[0]->{age} }
26 default => sub { Person->new(age => 37, name => "Chuck") },
27 predicate => 'has_person',
29 person_name => 'name',
36 default => sub { Person->new(age => 21, name => "Shawn") },
38 handles => [qw/name age/],
45 } qr/You must pass a HASH or ARRAY to handles/;
49 handles => \"ref_to_string",
51 } qr/You must pass a HASH or ARRAY to handles/;
57 } qr/You must pass a HASH or ARRAY to handles/;
61 handles => sub { "code" },
63 } qr/You must pass a HASH or ARRAY to handles/;
66 can_ok(Class => qw(person has_person person_name person_age name age quid));
68 my $object = Class->new;
69 ok(!$object->has_person, "don't have a person yet");
70 $object->person_name("Todd");
71 ok($object->has_person, "calling person_name instantiated person");
72 ok($object->person, "we really do have a person");
74 is($object->person_name, "Todd", "handles method");
75 is($object->person->name, "Todd", "traditional lookup");
76 is($object->person_age, 37, "handles method");
77 is($object->person->age, 37, "traditional lookup");
79 my $object2 = Class->new(person => Person->new(name => "Philbert"));
80 ok($object2->has_person, "we have a person from the constructor");
81 is($object2->person_name, "Philbert", "handles method");
82 is($object2->person->name, "Philbert", "traditional lookup");
83 is($object2->person_age, undef, "no age because we didn't use the default");
84 is($object2->person->age, undef, "no age because we didn't use the default");
87 ok($object->quid, "we have a Shawn");
88 is($object->name, "Shawn", "name handle");
89 is($object->age, 21, "age handle");
90 is($object->me->name, "Shawn", "me->name");
91 is($object->me->age, 21, "me->age");
94 $object->meta->get_attribute('me')->handles,
95 { name => 'name', age => 'age' },
96 "correct handles layout for 'me'",
100 $object->meta->get_attribute('person')->handles,
101 { person_name => 'name', person_age => 'age' },
102 "correct handles layout for 'person'",