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