2 package MooseX::AttributeHelpers::Counter;
6 our $AUTHORITY = 'cpan:STEVAN';
8 extends 'MooseX::AttributeHelpers::Base';
10 has '+method_constructors' => (
15 return sub { $attr->set_value($_[0], $attr->get_value($_[0]) + 1) };
19 return sub { $attr->set_value($_[0], $attr->get_value($_[0]) - 1) };
25 sub _process_options_for_provides {
26 my ($self, $options) = @_;
27 (exists $options->{isa})
28 || confess "You must define a type with the Counter metaclass";
30 (find_type_constraint($options->{isa})->is_subtype_of('Num'))
31 || confess "The type constraint for a Counter must be a subtype of Num";
36 # register the alias ...
37 package Moose::Meta::Attribute::Custom::Counter;
38 sub register_implementation { 'MooseX::AttributeHelpers::Counter' }
48 MooseX::AttributeHelpers::Counter
56 metaclass => 'Counter',
65 my $page = MyHomePage->new();
66 $page->inc_counter; # same as $page->counter($page->counter + 1);
74 All complex software has bugs lurking in it, and this module is no
75 exception. If you find a bug please either email me, or add the bug
80 Stevan Little E<lt>stevan@iinteractive.comE<gt>
82 =head1 COPYRIGHT AND LICENSE
84 Copyright 2007 by Infinity Interactive, Inc.
86 L<http://www.iinteractive.com>
88 This library is free software; you can redistribute it and/or modify
89 it under the same terms as Perl itself.