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