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