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