6 use Test::More no_plan => 1;
9 use_ok('MooseX::AttributeHelpers');
15 use MooseX::AttributeHelpers;
18 metaclass => 'Collection::Array',
22 default => sub { [] },
23 provides => { 'push' => 'add_observer', count => 'count_observers' }
28 foreach my $observer ( $self->observers() ) {
29 $observer->update($self);
33 ###############################################################################
40 die 'Forgot to implement' . "\n";
43 ###############################################################################
48 use MooseX::AttributeHelpers;
53 metaclass => 'Counter',
63 after 'inc_counter','dec_counter' => sub {
68 ###############################################################################
79 my ( $self, $subject ) = @_;
80 like $subject->count, qr{^-?\d+$}, 'Observed number ' . $subject->count;
83 ###############################################################################
87 my $count = Counter->new();
89 ok($count->can('add_observer'), 'add_observer method added');
91 ok($count->can('count_observers'), 'count_observers method added');
93 ok($count->can('inc_counter'), 'inc_counter method added');
95 ok($count->can('dec_counter'), 'dec_counter method added');
97 $count->add_observer( Display->new() );
99 is($count->count_observers, 1, 'Only one observer');
101 is($count->count, 0, 'Default to zero');
105 is($count->count, 1, 'Increment to one ');
107 $count->inc_counter for (1 .. 6);
109 is($count->count, 7, 'Increment up to seven');
113 is($count->count, 6, 'Decrement to 6');
115 $count->dec_counter for (1 .. 5);
117 is($count->count, 1, 'Decrement to 1');
119 $count->dec_counter for (1 .. 2);
121 is($count->count, -1, 'Negative numbers');
125 is($count->count, 0, 'Back to zero');