1 package MooseX::Types::Common::Numeric;
2 # ABSTRACT: Commonly used numeric types
7 use MooseX::Types -declare => [
8 qw(PositiveNum PositiveOrZeroNum
9 PositiveInt PositiveOrZeroInt
10 NegativeNum NegativeOrZeroNum
11 NegativeInt NegativeOrZeroInt
15 use MooseX::Types::Moose qw/Num Int/;
20 message { "Must be a positive number" },
21 ( $Moose::VERSION >= 2.0200
23 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
29 subtype PositiveOrZeroNum,
32 message { "Must be a number greater than or equal to zero" },
33 ( $Moose::VERSION >= 2.0200
35 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
44 message { "Must be a positive integer" },
45 ( $Moose::VERSION >= 2.0200
47 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
53 subtype PositiveOrZeroInt,
56 message { "Must be an integer greater than or equal to zero" },
57 ( $Moose::VERSION >= 2.0200
59 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
68 message { "Must be a negative number" },
69 ( $Moose::VERSION >= 2.0200
71 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
77 subtype NegativeOrZeroNum,
80 message { "Must be a number less than or equal to zero" },
81 ( $Moose::VERSION >= 2.0200
83 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
92 message { "Must be a negative integer" },
93 ( $Moose::VERSION >= 2.0200
95 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
101 subtype NegativeOrZeroInt,
104 message { "Must be an integer less than or equal to zero" },
105 ( $Moose::VERSION >= 2.0200
107 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
108 . qq{ ($_[1] <= 0) };
116 message { "Must be a single digit" },
117 ( $Moose::VERSION >= 2.0200
119 $_[0]->parent()->_inline_check( $_[1] ) . ' && '
120 . qq{ ($_[1] <= 9) };
133 use MooseX::Types::Common::Numeric qw/PositiveInt/;
134 has count => (is => 'rw', isa => PositiveInt);
142 A set of commonly-used numeric type constraints that do not ship with Moose by
149 =item * PositiveOrZeroNum
153 =item * PositiveOrZeroInt
157 =item * NegativeOrZeroNum
161 =item * NegativeOrZeroInt
171 =item * L<MooseX::Types::Common::String>