File: 011_counter_with_defaults.t

package info (click to toggle)
libmoosex-attributehelpers-perl 0.23-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 584 kB
  • ctags: 329
  • sloc: perl: 3,890; makefile: 5
file content (57 lines) | stat: -rw-r--r-- 1,231 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 14;

BEGIN {
    use_ok('MooseX::AttributeHelpers');   
}

{
    package MyHomePage;
    use Moose;

    has 'counter' => (metaclass => 'Counter');
}

my $page = MyHomePage->new();
isa_ok($page, 'MyHomePage');

can_ok($page, $_) for qw[
    dec_counter 
    inc_counter
    reset_counter
];

is($page->counter, 0, '... got the default value');

$page->inc_counter; 
is($page->counter, 1, '... got the incremented value');

$page->inc_counter; 
is($page->counter, 2, '... got the incremented value (again)');

$page->dec_counter; 
is($page->counter, 1, '... got the decremented value');

$page->reset_counter;
is($page->counter, 0, '... got the original value');

# check the meta ..

my $counter = $page->meta->get_attribute('counter');
isa_ok($counter, 'MooseX::AttributeHelpers::Counter');

is($counter->helper_type, 'Num', '... got the expected helper type');

is($counter->type_constraint->name, 'Num', '... got the expected default type constraint');

is_deeply($counter->provides, { 
    inc   => 'inc_counter',
    dec   => 'dec_counter',
    reset => 'reset_counter',        
    set   => 'set_counter',
}, '... got the right default provides methods');