line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::AttributeHelpers::Number; |
2
|
22
|
|
|
22
|
|
87
|
use Moose; |
|
22
|
|
|
|
|
43
|
|
|
22
|
|
|
|
|
136
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.25'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
extends 'Moose::Meta::Attribute'; |
7
|
|
|
|
|
|
|
with 'MooseX::AttributeHelpers::Trait::Number'; |
8
|
|
|
|
|
|
|
|
9
|
22
|
|
|
22
|
|
97890
|
no Moose; |
|
22
|
|
|
|
|
33
|
|
|
22
|
|
|
|
|
85
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# register the alias ... |
12
|
|
|
|
|
|
|
package # hide me from search.cpan.org |
13
|
|
|
|
|
|
|
Moose::Meta::Attribute::Custom::Number; |
14
|
1
|
|
|
1
|
|
574
|
sub register_implementation { 'MooseX::AttributeHelpers::Number' } |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
1; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
__END__ |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=pod |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=encoding UTF-8 |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
MooseX::AttributeHelpers::Number |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 VERSION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
version 0.25 |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 SYNOPSIS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
package Real; |
35
|
|
|
|
|
|
|
use Moose; |
36
|
|
|
|
|
|
|
use MooseX::AttributeHelpers; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has 'integer' => ( |
39
|
|
|
|
|
|
|
metaclass => 'Number', |
40
|
|
|
|
|
|
|
is => 'ro', |
41
|
|
|
|
|
|
|
isa => 'Int', |
42
|
|
|
|
|
|
|
default => sub { 5 }, |
43
|
|
|
|
|
|
|
provides => { |
44
|
|
|
|
|
|
|
set => 'set', |
45
|
|
|
|
|
|
|
add => 'add', |
46
|
|
|
|
|
|
|
sub => 'sub', |
47
|
|
|
|
|
|
|
mul => 'mul', |
48
|
|
|
|
|
|
|
div => 'div', |
49
|
|
|
|
|
|
|
mod => 'mod', |
50
|
|
|
|
|
|
|
abs => 'abs', |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $real = Real->new(); |
55
|
|
|
|
|
|
|
$real->add(5); # same as $real->integer($real->integer + 5); |
56
|
|
|
|
|
|
|
$real->sub(2); # same as $real->integer($real->integer - 2); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This provides a simple numeric attribute, which supports most of the |
61
|
|
|
|
|
|
|
basic math operations. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 NAME |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
MooseX::AttributeHelpers::Number |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 METHODS |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=over 4 |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item B<meta> |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item B<helper_type> |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item B<method_constructors> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=back |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 PROVIDED METHODS |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
It is important to note that all those methods do in place |
82
|
|
|
|
|
|
|
modification of the value stored in the attribute. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=over 4 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item I<set ($value)> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Alternate way to set the value. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item I<add ($value)> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Adds the current value of the attribute to C<$value>. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item I<sub ($value)> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Subtracts the current value of the attribute to C<$value>. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item I<mul ($value)> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Multiplies the current value of the attribute to C<$value>. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item I<div ($value)> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Divides the current value of the attribute to C<$value>. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item I<mod ($value)> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Modulus the current value of the attribute to C<$value>. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item I<abs> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Sets the current value of the attribute to its absolute value. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=back |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 SUPPORT |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-AttributeHelpers> |
119
|
|
|
|
|
|
|
(or L<bug-MooseX-AttributeHelpers@rt.cpan.org|mailto:bug-MooseX-AttributeHelpers@rt.cpan.org>). |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
122
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
125
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 AUTHOR |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Stevan Little <stevan@iinteractive.com> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Robert Boone |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Stevan Little and Infinity Interactive, Inc. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
138
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |