renamed helper_type => _helper_type
[gitmo/Moose.git] / t / 070_attribute_helpers / 201_trait_counter.t
CommitLineData
e3c07b19 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
2e069f5a 6use Test::More tests => 17;
e3c07b19 7use Test::Moose 'does_ok';
8
9BEGIN {
a41de825 10 use_ok('Moose::AttributeHelpers');
e3c07b19 11}
12
13{
14 package MyHomePage;
15 use Moose;
16
17 has 'counter' => (
a41de825 18 traits => [qw/Counter/],
e3c07b19 19 is => 'ro',
20 isa => 'Int',
21 default => sub { 0 },
0d103ac9 22 handles => {
23 inc_counter => 'inc',
24 dec_counter => 'dec',
25 reset_counter => 'reset',
26 set_counter => 'set'
e3c07b19 27 }
28 );
29}
30
31my $page = MyHomePage->new();
32isa_ok($page, 'MyHomePage');
33
34can_ok($page, $_) for qw[
35 dec_counter
36 inc_counter
37 reset_counter
59de9de4 38 set_counter
e3c07b19 39];
40
41is($page->counter, 0, '... got the default value');
42
43$page->inc_counter;
44is($page->counter, 1, '... got the incremented value');
45
46$page->inc_counter;
47is($page->counter, 2, '... got the incremented value (again)');
48
49$page->dec_counter;
50is($page->counter, 1, '... got the decremented value');
51
52$page->reset_counter;
53is($page->counter, 0, '... got the original value');
54
59de9de4 55$page->set_counter(5);
56is($page->counter, 5, '... set the value');
57
58$page->inc_counter(2);
59is($page->counter, 7, '... increment by arg');
60
61$page->dec_counter(5);
62is($page->counter, 2, '... decrement by arg');
63
e3c07b19 64# check the meta ..
65
66my $counter = $page->meta->get_attribute('counter');
a41de825 67does_ok($counter, 'Moose::AttributeHelpers::Trait::Counter');
e3c07b19 68
e3c07b19 69is($counter->type_constraint->name, 'Int', '... got the expected type constraint');
70
0d103ac9 71is_deeply($counter->handles, {
72 inc_counter => 'inc',
73 dec_counter => 'dec',
74 reset_counter => 'reset',
75 set_counter => 'set'
76}, '... got the right handles methods');
e3c07b19 77