28 accessor => 'rw_attr',
29 reader => 'read_attr',
30 writer => 'write_attr',
34 accessor => 'rw_attr2',
38 ok(!Class->can('x'), "No accessor is injected if 'is' has no value");
39 can_ok('Class', 'y', 'z');
41 has_attribute_ok 'Class', 'x';
42 has_attribute_ok 'Class', 'y';
43 has_attribute_ok 'Class', 'z';
45 my $object = Class->new;
47 ok(!$object->can('x'), "No accessor is injected if 'is' has no value");
48 can_ok($object, 'y', 'z');
50 is($object->y, undef);
54 } qr/Cannot assign a value to a read-only accessor/;
56 is($object->y, undef);
58 is($object->z, undef);
59 is($object->z(10), 10);
62 can_ok($object, qw(rw_attr read_attr write_attr));
63 $object->write_attr(42);
64 is $object->rw_attr, 42;
65 is $object->read_attr, 42;
66 $object->rw_attr(100);
67 is $object->rw_attr, 100;
68 is $object->read_attr, 100;
70 is $object->write_attr("piyo"), "piyo";
71 is $object->rw_attr("yopi"), "yopi";
73 can_ok $object, qw(rw_attr2);
74 ok !$object->can('attr2'), "doesn't have attr2";
83 Class->write_attr(42);
86 my @attrs = map { $_->name }
87 sort { $a->insertion_order <=> $b->insertion_order } $object->meta->get_all_attributes;
88 is join(' ', @attrs), 'x y z attr attr2', 'insertion_order';