6 use Test::More no_plan => 1;
9 use_ok('MooseX::AttributeHelpers');
12 ## convert this to a test ...
13 ## code by Robert Boone
18 use MooseX::AttributeHelpers;
21 metaclass => 'Collection::Array',
25 default => sub { [] },
26 provides => { 'push' => 'add_observer', count => 'count_observers' }
31 foreach my $observer ( $self->observers() ) {
32 $observer->update($self);
36 ###############################################################################
43 die 'Forgot to implement' . "\n";
46 ###############################################################################
51 use MooseX::AttributeHelpers;
56 metaclass => 'Counter',
66 after 'inc_counter','dec_counter' => sub {
71 ###############################################################################
82 my ( $self, $subject ) = @_;
83 like $subject->count, qr{^-?\d+$}, 'Observed number ' . $subject->count;
86 ###############################################################################
90 my $count = Counter->new();
92 ok($count->can('add_observer'), 'add_observer method added');
94 ok($count->can('count_observers'), 'count_observers method added');
96 ok($count->can('inc_counter'), 'inc_counter method added');
98 ok($count->can('dec_counter'), 'dec_counter method added');
100 $count->add_observer( Display->new() );
102 is($count->count_observers, 1, 'Only one observer');
104 is($count->count, 0, 'Default to zero');
108 is($count->count, 1, 'Increment to one ');
110 $count->inc_counter for (1 .. 6);
112 is($count->count, 7, 'Increment up to seven');
116 is($count->count, 6, 'Decrement to 6');
118 $count->dec_counter for (1 .. 5);
120 is($count->count, 1, 'Decrement to 1');
122 $count->dec_counter for (1 .. 2);
124 is($count->count, -1, 'Negative numbers');
128 is($count->count, 0, 'Back to zero');