2 package MooseX::AttributeHelpers::Counter;
4 use Moose::Util::TypeConstraints;
7 our $AUTHORITY = 'cpan:STEVAN';
9 extends 'MooseX::AttributeHelpers::Base';
11 has '+method_constructors' => (
16 return sub { $attr->set_value($_[0], $attr->get_value($_[0]) + 1) };
20 return sub { $attr->set_value($_[0], $attr->get_value($_[0]) - 1) };
26 sub _process_options_for_provides {
27 my ($self, $options) = @_;
28 (exists $options->{isa})
29 || confess "You must define a type with the Counter metaclass";
31 (find_type_constraint($options->{isa})->is_a_type_of('Num'))
32 || confess "The type constraint for a Counter ($options->{isa}) must be a subtype of Num";
36 no Moose::Util::TypeConstraints;
38 # register the alias ...
39 package Moose::Meta::Attribute::Custom::Counter;
40 sub register_implementation { 'MooseX::AttributeHelpers::Counter' }
50 MooseX::AttributeHelpers::Counter
58 metaclass => 'Counter',
67 my $page = MyHomePage->new();
68 $page->inc_counter; # same as $page->counter($page->counter + 1);
76 All complex software has bugs lurking in it, and this module is no
77 exception. If you find a bug please either email me, or add the bug
82 Stevan Little E<lt>stevan@iinteractive.comE<gt>
84 =head1 COPYRIGHT AND LICENSE
86 Copyright 2007 by Infinity Interactive, Inc.
88 L<http://www.iinteractive.com>
90 This library is free software; you can redistribute it and/or modify
91 it under the same terms as Perl itself.