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