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