Commit | Line | Data |
565fe238 |
1 | package MooseX::AttributeHelpers::Number; |
2 | use Moose; |
8683383a |
3 | use MooseX::AttributeHelpers::Sugar; |
4 | |
5 | extends 'MooseX::AttributeHelpers::Base'; |
565fe238 |
6 | |
c91a1347 |
7 | our $VERSION = '0.02'; |
565fe238 |
8 | our $AUTHORITY = 'cpan:STEVAN'; |
9 | |
8683383a |
10 | define_attribute_helper ( |
11 | helper_type => 'Num', |
12 | method_provider => 'MooseX::AttributeHelpers::MethodProvider::Number', |
13 | shortcut => 'Number', |
565fe238 |
14 | ); |
565fe238 |
15 | |
8683383a |
16 | no Moose; |
17 | no MooseX::AttributeHelpers::Sugar; |
565fe238 |
18 | |
19 | 1; |
20 | |
8683383a |
21 | __END__ |
22 | |
565fe238 |
23 | =pod |
24 | |
25 | =head1 NAME |
26 | |
27 | MooseX::AttributeHelpers::Number |
28 | |
29 | =head1 SYNOPSIS |
30 | |
31 | package Real; |
5431dff2 |
32 | use Moose; |
33 | use MooseX::AttributeHelpers; |
34 | |
35 | has 'integer' => ( |
36 | metaclass => 'Number', |
37 | is => 'ro', |
38 | isa => 'Int', |
39 | default => sub { 5 }, |
40 | provides => { |
41 | set => 'set', |
42 | add => 'add', |
43 | sub => 'sub', |
44 | mul => 'mul', |
45 | div => 'div', |
46 | mod => 'mod', |
47 | abs => 'abs', |
48 | } |
49 | ); |
565fe238 |
50 | |
51 | my $real = Real->new(); |
52 | $real->add(5); # same as $real->integer($real->integer + 5); |
53 | $real->sub(2); # same as $real->integer($real->integer - 2); |
54 | |
55 | =head1 DESCRIPTION |
56 | |
5431dff2 |
57 | This provides a simple numeric attribute, which supports most of the |
720fa35b |
58 | basic math operations. It is important to note that all operations modify the |
59 | value of the attribute in place. |
5431dff2 |
60 | |
8683383a |
61 | =head1 METHOD PROVIDER |
c91a1347 |
62 | |
8683383a |
63 | The methods for this metaclass are provided by |
720fa35b |
64 | L<MooseX::AttributeHelpers::MethodProvider::Number>. |
c91a1347 |
65 | |
565fe238 |
66 | =head1 BUGS |
67 | |
68 | All complex software has bugs lurking in it, and this module is no |
69 | exception. If you find a bug please either email me, or add the bug |
70 | to cpan-RT. |
71 | |
72 | =head1 AUTHOR |
73 | |
8c651099 |
74 | Robert Boone |
565fe238 |
75 | |
76 | =head1 COPYRIGHT AND LICENSE |
77 | |
99c62fb8 |
78 | Copyright 2007-2008 by Infinity Interactive, Inc. |
565fe238 |
79 | |
80 | L<http://www.iinteractive.com> |
81 | |
82 | This library is free software; you can redistribute it and/or modify |
83 | it under the same terms as Perl itself. |
84 | |
ae2c330e |
85 | =cut |