Commit | Line | Data |
c0a92932 |
1 | use strict; |
2 | use warnings; |
3 | |
a28e50e4 |
4 | use Test::More; |
95d922a2 |
5 | use Test::Moose; |
c0a92932 |
6 | |
7 | { |
8 | package Foo; |
9 | use Moose; |
10 | has 'type' => ( |
11 | required => 0, |
12 | reader => 'get_type', |
13 | default => 1, |
14 | ); |
15 | |
95d922a2 |
16 | # Assigning types to these non-alpha attrs exposed a bug in Moose. |
c0a92932 |
17 | has '@type' => ( |
95d922a2 |
18 | isa => 'Str', |
c0a92932 |
19 | required => 0, |
20 | reader => 'get_at_type', |
95d922a2 |
21 | writer => 'set_at_type', |
22 | default => 'at type', |
c0a92932 |
23 | ); |
24 | |
25 | has 'has spaces' => ( |
95d922a2 |
26 | isa => 'Int', |
c0a92932 |
27 | required => 0, |
28 | reader => 'get_hs', |
29 | default => 42, |
30 | ); |
31 | |
95d922a2 |
32 | has '!req' => ( |
33 | required => 1, |
34 | reader => 'req' |
35 | ); |
36 | |
c0a92932 |
37 | no Moose; |
38 | } |
39 | |
95d922a2 |
40 | with_immutable { |
c0a92932 |
41 | ok( Foo->meta->has_attribute($_), "Foo has '$_' attribute" ) |
42 | for 'type', '@type', 'has spaces'; |
43 | |
95d922a2 |
44 | my $foo = Foo->new( '!req' => 42 ); |
45 | |
46 | is( $foo->get_type, 1, q{'type' attribute default is 1} ); |
47 | is( $foo->get_at_type, 'at type', q{'@type' attribute default is 1} ); |
48 | is( $foo->get_hs, 42, q{'has spaces' attribute default is 42} ); |
49 | |
50 | $foo = Foo->new( |
51 | type => 'foo', |
52 | '@type' => 'bar', |
53 | 'has spaces' => 200, |
54 | '!req' => 84, |
55 | ); |
56 | |
57 | isa_ok( $foo, 'Foo' ); |
58 | is( $foo->get_at_type, 'bar', q{reader for '@type'} ); |
59 | is( $foo->get_hs, 200, q{reader for 'has spaces'} ); |
c0a92932 |
60 | |
95d922a2 |
61 | $foo->set_at_type(99); |
62 | is( $foo->get_at_type, 99, q{writer for '@type' worked} ); |
c0a92932 |
63 | } |
95d922a2 |
64 | 'Foo'; |
a28e50e4 |
65 | |
66 | done_testing; |