now uses faster methods for accessors and some other minor cleanup stuff
[gitmo/MooseX-AttributeHelpers.git] / lib / MooseX / AttributeHelpers / Counter.pm
CommitLineData
22d869ff 1
2package MooseX::AttributeHelpers::Counter;
3use Moose;
22d869ff 4
5our $VERSION = '0.01';
6our $AUTHORITY = 'cpan:STEVAN';
7
8e3fab6d 8use MooseX::AttributeHelpers::MethodProvider::Counter;
d26633fc 9
8e3fab6d 10extends 'MooseX::AttributeHelpers::Base';
8ba40fb0 11
8e3fab6d 12has '+method_provider' => (
13 default => 'MooseX::AttributeHelpers::MethodProvider::Counter'
d26633fc 14);
8e3fab6d 15
16sub helper_type { 'Num' }
22d869ff 17
22d869ff 18no Moose;
22d869ff 19
20# register the alias ...
21package Moose::Meta::Attribute::Custom::Counter;
22sub register_implementation { 'MooseX::AttributeHelpers::Counter' }
23
241;
25
26__END__
27
28=pod
29
30=head1 NAME
31
32MooseX::AttributeHelpers::Counter
33
34=head1 SYNOPSIS
35
36 package MyHomePage;
37 use Moose;
5431dff2 38 use MooseX::AttributeHelpers;
22d869ff 39
40 has 'counter' => (
41 metaclass => 'Counter',
42 is => 'rw',
43 isa => 'Int',
44 default => sub { 0 },
45 provides => {
46 inc => 'inc_counter',
21c7045b 47 dec => 'dec_counter',
22d869ff 48 }
49 );
50
51 my $page = MyHomePage->new();
52 $page->inc_counter; # same as $page->counter($page->counter + 1);
21c7045b 53 $page->dec_counter; # same as $page->counter($page->counter - 1);
22d869ff 54
55=head1 DESCRIPTION
56
5431dff2 57This module provides a simple counter attribute, which can be
58incremented and decremeneted.
59
22d869ff 60=head1 METHODS
61
5431dff2 62=over 4
63
64=item B<method_provider>
65
66=item B<has_method_provider>
67
68=item B<helper_type>
69
70=back
71
22d869ff 72=head1 BUGS
73
74All complex software has bugs lurking in it, and this module is no
75exception. If you find a bug please either email me, or add the bug
76to cpan-RT.
77
78=head1 AUTHOR
79
80Stevan Little E<lt>stevan@iinteractive.comE<gt>
81
82=head1 COPYRIGHT AND LICENSE
83
84Copyright 2007 by Infinity Interactive, Inc.
85
86L<http://www.iinteractive.com>
87
88This library is free software; you can redistribute it and/or modify
89it under the same terms as Perl itself.
90
91=cut