Commit | Line | Data |
c3398f5b |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
4 | use Test::More tests => 10; |
8c831d08 |
5 | use Mouse::Util ':test'; |
c3398f5b |
6 | |
7 | do { |
8 | package Class; |
9 | use Mouse; |
10 | |
11 | has 'x'; |
12 | |
13 | has 'y' => ( |
14 | is => 'ro', |
15 | ); |
16 | |
17 | has 'z' => ( |
18 | is => 'rw', |
19 | ); |
20 | }; |
21 | |
22 | ok(!Class->can('x'), "No accessor is injected if 'is' has no value"); |
23 | can_ok('Class', 'y', 'z'); |
24 | |
25 | my $object = Class->new; |
26 | |
27 | ok(!$object->can('x'), "No accessor is injected if 'is' has no value"); |
28 | can_ok($object, 'y', 'z'); |
29 | |
30 | is($object->y, undef); |
636c002e |
31 | |
32 | throws_ok { |
33 | $object->y(10); |
34 | } qr/Cannot assign a value to a read-only accessor/; |
35 | |
c3398f5b |
36 | is($object->y, undef); |
37 | |
38 | is($object->z, undef); |
39 | is($object->z(10), 10); |
40 | is($object->z, 10); |
41 | |