line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moose::Meta::Attribute::Native::Trait::Counter; |
2
|
|
|
|
|
|
|
our $VERSION = '2.2206'; |
3
|
|
|
|
|
|
|
|
4
|
4
|
|
|
4
|
|
2862
|
use Moose::Role; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
34
|
|
5
|
|
|
|
|
|
|
with 'Moose::Meta::Attribute::Native::Trait'; |
6
|
|
|
|
|
|
|
|
7
|
11
|
|
|
11
|
|
32
|
sub _helper_type { 'Num' } |
8
|
56
|
|
|
56
|
|
352
|
sub _root_types { 'Num', 'Int' } |
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
32
|
no Moose::Role; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
18
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
1; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# ABSTRACT: Helper trait for Int attributes which represent counters |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
__END__ |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=pod |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=encoding UTF-8 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for Int attributes which represent counters |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 VERSION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
version 2.2206 |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SYNOPSIS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
package MyHomePage; |
33
|
|
|
|
|
|
|
use Moose; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has 'counter' => ( |
36
|
|
|
|
|
|
|
traits => ['Counter'], |
37
|
|
|
|
|
|
|
is => 'ro', |
38
|
|
|
|
|
|
|
isa => 'Num', |
39
|
|
|
|
|
|
|
default => 0, |
40
|
|
|
|
|
|
|
handles => { |
41
|
|
|
|
|
|
|
inc_counter => 'inc', |
42
|
|
|
|
|
|
|
dec_counter => 'dec', |
43
|
|
|
|
|
|
|
reset_counter => 'reset', |
44
|
|
|
|
|
|
|
}, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $page = MyHomePage->new(); |
48
|
|
|
|
|
|
|
$page->inc_counter; # same as $page->counter( $page->counter + 1 ); |
49
|
|
|
|
|
|
|
$page->dec_counter; # same as $page->counter( $page->counter - 1 ); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $count_by_twos = 2; |
52
|
|
|
|
|
|
|
$page->inc_counter($count_by_twos); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
This trait provides native delegation methods for counters. A counter can be |
57
|
|
|
|
|
|
|
any sort of number (integer or not). The delegation methods allow you to |
58
|
|
|
|
|
|
|
increment, decrement, or reset the value. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 DEFAULT TYPE |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
If you don't provide an C<isa> value for your attribute, it will default to |
63
|
|
|
|
|
|
|
C<Num>. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 PROVIDED METHODS |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=over 4 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item * B<set($value)> |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Sets the counter to the specified value and returns the new value. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This method requires a single argument. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item * B<inc> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item * B<inc($arg)> |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Increases the attribute value by the amount of the argument, or by 1 if no |
80
|
|
|
|
|
|
|
argument is given. This method returns the new value. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This method accepts a single argument. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item * B<dec> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item * B<dec($arg)> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Decreases the attribute value by the amount of the argument, or by 1 if no |
89
|
|
|
|
|
|
|
argument is given. This method returns the new value. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This method accepts a single argument. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item * B<reset> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Resets the value stored in this slot to its default value, and returns the new |
96
|
|
|
|
|
|
|
value. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=back |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 BUGS |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
See L<Moose/BUGS> for details on reporting bugs. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 AUTHORS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=over 4 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Stevan Little <stevan@cpan.org> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Jesse Luehrs <doy@cpan.org> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Shawn M Moore <sartak@cpan.org> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Florian Ragwitz <rafl@debian.org> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Hans Dieter Pearcey <hdp@cpan.org> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Chris Prather <chris@prather.org> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Matt S Trout <mstrout@cpan.org> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=back |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This software is copyright (c) 2006 by Infinity Interactive, Inc. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
155
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=cut |