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