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