Commit | Line | Data |
c3398f5b |
1 | #!/usr/bin/env perl |
2 | use strict; |
3 | use warnings; |
4 | use Test::More tests => 18; |
5 | |
6 | do { |
7 | package Class; |
8 | use Mouse; |
9 | |
10 | has 'x' => ( |
11 | is => 'rw', |
12 | default => 10, |
13 | ); |
14 | |
15 | has 'y' => ( |
16 | is => 'rw', |
17 | default => 20, |
18 | ); |
19 | |
20 | has 'z' => ( |
21 | is => 'rw', |
22 | ); |
23 | }; |
24 | |
25 | my $object = Class->new; |
26 | is($object->x, 10, "attribute has a default of 10"); |
27 | is($object->y, 20, "attribute has a default of 20"); |
28 | is($object->z, undef, "attribute has no default"); |
29 | |
30 | is($object->x(5), 5, "setting a new value"); |
31 | is($object->y(25), 25, "setting a new value"); |
32 | is($object->z(125), 125, "setting a new value"); |
33 | |
34 | is($object->x, 5, "setting a new value does not trigger default"); |
35 | is($object->y, 25, "setting a new value does not trigger default"); |
36 | is($object->z, 125, "setting a new value does not trigger default"); |
37 | |
38 | my $object2 = Class->new(x => 50); |
39 | is($object2->x, 50, "attribute was initialized to 50"); |
40 | is($object2->y, 20, "attribute has a default of 20"); |
41 | is($object2->z, undef, "attribute has no default"); |
42 | |
43 | is($object2->x(5), 5, "setting a new value"); |
44 | is($object2->y(25), 25, "setting a new value"); |
45 | is($object2->z(125), 125, "setting a new value"); |
46 | |
47 | is($object2->x, 5, "setting a new value does not trigger default"); |
48 | is($object2->y, 25, "setting a new value does not trigger default"); |
49 | is($object2->z, 125, "setting a new value does not trigger default"); |
50 | |