2 package MooseX::AttributeHelpers::Counter;
4 use Moose::Util::TypeConstraints;
7 our $AUTHORITY = 'cpan:STEVAN';
9 extends 'MooseX::AttributeHelpers::Base';
11 sub helper_type { 'Num' }
13 has '+method_constructors' => (
18 return sub { $attr->set_value($_[0], $attr->get_value($_[0]) + 1) };
22 return sub { $attr->set_value($_[0], $attr->get_value($_[0]) - 1) };
29 no Moose::Util::TypeConstraints;
31 # register the alias ...
32 package Moose::Meta::Attribute::Custom::Counter;
33 sub register_implementation { 'MooseX::AttributeHelpers::Counter' }
43 MooseX::AttributeHelpers::Counter
51 metaclass => 'Counter',
61 my $page = MyHomePage->new();
62 $page->inc_counter; # same as $page->counter($page->counter + 1);
63 $page->dec_counter; # same as $page->counter($page->counter - 1);
71 All complex software has bugs lurking in it, and this module is no
72 exception. If you find a bug please either email me, or add the bug
77 Stevan Little E<lt>stevan@iinteractive.comE<gt>
79 =head1 COPYRIGHT AND LICENSE
81 Copyright 2007 by Infinity Interactive, Inc.
83 L<http://www.iinteractive.com>
85 This library is free software; you can redistribute it and/or modify
86 it under the same terms as Perl itself.