Commit | Line | Data |
e3c07b19 |
1 | package Moose::AttributeHelpers::Number; |
2 | use Moose; |
3 | |
dbd46676 |
4 | our $VERSION = '0.83'; |
e3c07b19 |
5 | $VERSION = eval $VERSION; |
6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | |
8 | extends 'Moose::Meta::Attribute'; |
9 | with 'Moose::AttributeHelpers::Trait::Number'; |
10 | |
11 | no Moose; |
12 | |
13 | # register the alias ... |
14 | package # hide me from search.cpan.org |
15 | Moose::Meta::Attribute::Custom::Number; |
16 | sub register_implementation { 'Moose::AttributeHelpers::Number' } |
17 | |
18 | 1; |
19 | |
20 | =pod |
21 | |
22 | =head1 NAME |
23 | |
24 | Moose::AttributeHelpers::Number |
25 | |
26 | =head1 SYNOPSIS |
27 | |
28 | package Real; |
29 | use Moose; |
30 | use Moose::AttributeHelpers; |
31 | |
32 | has 'integer' => ( |
33 | metaclass => 'Number', |
34 | is => 'ro', |
35 | isa => 'Int', |
36 | default => sub { 5 }, |
37 | provides => { |
38 | set => 'set', |
39 | add => 'add', |
40 | sub => 'sub', |
41 | mul => 'mul', |
42 | div => 'div', |
43 | mod => 'mod', |
44 | abs => 'abs', |
45 | } |
46 | ); |
47 | |
48 | my $real = Real->new(); |
49 | $real->add(5); # same as $real->integer($real->integer + 5); |
50 | $real->sub(2); # same as $real->integer($real->integer - 2); |
51 | |
52 | =head1 DESCRIPTION |
53 | |
54 | This provides a simple numeric attribute, which supports most of the |
55 | basic math operations. |
56 | |
57 | =head1 METHODS |
58 | |
59 | =over 4 |
60 | |
61 | =item B<meta> |
62 | |
63 | =item B<helper_type> |
64 | |
65 | =item B<method_constructors> |
66 | |
67 | =back |
68 | |
69 | =head1 PROVIDED METHODS |
70 | |
71 | It is important to note that all those methods do in place |
72 | modification of the value stored in the attribute. |
73 | |
74 | =over 4 |
75 | |
76 | =item I<set ($value)> |
77 | |
78 | Alternate way to set the value. |
79 | |
80 | =item I<add ($value)> |
81 | |
82 | Adds the current value of the attribute to C<$value>. |
83 | |
84 | =item I<sub ($value)> |
85 | |
86 | Subtracts the current value of the attribute to C<$value>. |
87 | |
88 | =item I<mul ($value)> |
89 | |
90 | Multiplies the current value of the attribute to C<$value>. |
91 | |
92 | =item I<div ($value)> |
93 | |
94 | Divides the current value of the attribute to C<$value>. |
95 | |
96 | =item I<mod ($value)> |
97 | |
98 | Modulus the current value of the attribute to C<$value>. |
99 | |
100 | =item I<abs> |
101 | |
102 | Sets the current value of the attribute to its absolute value. |
103 | |
104 | =back |
105 | |
106 | =head1 BUGS |
107 | |
108 | All complex software has bugs lurking in it, and this module is no |
109 | exception. If you find a bug please either email me, or add the bug |
110 | to cpan-RT. |
111 | |
112 | =head1 AUTHOR |
113 | |
114 | Robert Boone |
115 | |
116 | =head1 COPYRIGHT AND LICENSE |
117 | |
118 | Copyright 2007-2009 by Infinity Interactive, Inc. |
119 | |
120 | L<http://www.iinteractive.com> |
121 | |
122 | This library is free software; you can redistribute it and/or modify |
123 | it under the same terms as Perl itself. |
124 | |
125 | =cut |