Commit | Line | Data |
e3c07b19 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
a5209c26 |
6 | use Test::More tests => 12; |
40ef30a5 |
7 | use Test::Moose; |
e3c07b19 |
8 | |
e3c07b19 |
9 | { |
10 | package MyHomePage; |
11 | use Moose; |
a5209c26 |
12 | use Moose::AttributeHelpers; |
e3c07b19 |
13 | |
d50fc84a |
14 | has 'counter' => ( traits => ['Counter'] ); |
e3c07b19 |
15 | } |
16 | |
17 | my $page = MyHomePage->new(); |
d50fc84a |
18 | isa_ok( $page, 'MyHomePage' ); |
e3c07b19 |
19 | |
d50fc84a |
20 | can_ok( $page, $_ ) for qw[ |
e3c07b19 |
21 | dec_counter |
22 | inc_counter |
23 | reset_counter |
24 | ]; |
25 | |
d50fc84a |
26 | is( $page->counter, 0, '... got the default value' ); |
e3c07b19 |
27 | |
28 | $page->inc_counter; |
d50fc84a |
29 | is( $page->counter, 1, '... got the incremented value' ); |
e3c07b19 |
30 | |
31 | $page->inc_counter; |
d50fc84a |
32 | is( $page->counter, 2, '... got the incremented value (again)' ); |
e3c07b19 |
33 | |
34 | $page->dec_counter; |
d50fc84a |
35 | is( $page->counter, 1, '... got the decremented value' ); |
e3c07b19 |
36 | |
37 | $page->reset_counter; |
d50fc84a |
38 | is( $page->counter, 0, '... got the original value' ); |
e3c07b19 |
39 | |
40 | # check the meta .. |
41 | |
42 | my $counter = $page->meta->get_attribute('counter'); |
a40b446a |
43 | does_ok( $counter, 'Moose::Meta::Attribute::Trait::Native::Counter' ); |
d50fc84a |
44 | |
45 | is( $counter->type_constraint->name, 'Num', |
46 | '... got the expected default type constraint' ); |
47 | |
48 | is_deeply( |
49 | $counter->handles, |
50 | { |
51 | 'inc_counter' => 'inc', |
52 | 'dec_counter' => 'dec', |
53 | 'reset_counter' => 'reset', |
54 | 'set_counter' => 'set', |
55 | }, |
56 | '... got the right default handles methods' |
57 | ); |
e3c07b19 |
58 | |