Commit | Line | Data |
ac73ab52 |
1 | package MooseX::Types::Common::Numeric; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | our $VERSION = '0.001000'; |
7 | |
8 | use MooseX::Types -declare => [ |
9 | qw(PositiveNum PositiveInt NegativeNum NegativeInt SingleDigit) |
10 | ]; |
11 | |
12 | use MooseX::Types::Moose qw/Num Int/; |
13 | |
14 | subtype PositiveNum, |
15 | as Num, |
16 | where { $_ >= 0 }, |
17 | message { "Must be a positive number" }; |
18 | |
19 | subtype PositiveInt, |
20 | as Int, |
21 | where { $_ >= 0 }, |
22 | message { "Must be a positive integer" }; |
23 | |
24 | subtype NegativeNum, |
25 | as Num, |
26 | where { $_ <= 0 }, |
27 | message { "Must be a negative number" }; |
28 | |
29 | subtype NegativeInt, |
30 | as Int, |
31 | where { $_ <= 0 }, |
32 | message { "Must be a negative integer" }; |
33 | |
34 | subtype SingleDigit, |
35 | as PositiveInt, |
36 | where { $_ <= 9 }, |
37 | message { "Must be a single digit" }; |
38 | |
39 | |
40 | 1; |
41 | |
42 | __END__; |
43 | |
44 | |
45 | =head1 NAME |
46 | |
47 | MooseX::Types::Common::Numeric |
48 | |
49 | =head1 SYNOPSIS |
50 | |
51 | use MooseX::Types::Common::Numeric qw/PositiveInt/; |
52 | has count => (is => 'rw', isa => PositiveInt); |
53 | |
54 | ... |
55 | #this will fail |
56 | $object->count(-33); |
57 | |
58 | =head1 DESCRIPTION |
59 | |
60 | A set of commonly-used numeric type constraints that do not ship with Moose by |
61 | default. |
62 | |
63 | =over |
64 | |
65 | =item * PositiveNum |
66 | |
67 | =item * PositiveInt |
68 | |
69 | =item * NegativeNum |
70 | |
71 | =item * Int |
72 | |
73 | =item * SingleDigit |
74 | |
75 | =back |
76 | |
77 | =head1 SEE ALSO |
78 | |
79 | =over |
80 | |
81 | =item * L<MooseX::Types::Common::String> |
82 | |
83 | =back |
84 | |
85 | =head1 AUTHORS |
86 | |
87 | Please see:: L<MooseX::Types::Common> |
88 | |
89 | =cut |