X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FTypes%2FCommon%2FNumeric.pm;h=2b3f08abdef2912685a975f9537801725c0e720e;hb=31633b2663f3f18784c3356360339b919e64846c;hp=af9e01a66ba35dd6b5e5f088648308737cbb5347;hpb=d0b8bc7f34ec718fae7804257ed3db44c126ebd7;p=gitmo%2FMooseX-Types-Common.git diff --git a/lib/MooseX/Types/Common/Numeric.pm b/lib/MooseX/Types/Common/Numeric.pm index af9e01a..2b3f08a 100644 --- a/lib/MooseX/Types/Common/Numeric.pm +++ b/lib/MooseX/Types/Common/Numeric.pm @@ -3,10 +3,14 @@ package MooseX::Types::Common::Numeric; use strict; use warnings; -our $VERSION = '0.001001'; +our $VERSION = '0.001005'; use MooseX::Types -declare => [ - qw(PositiveNum PositiveInt NegativeNum NegativeInt SingleDigit) + qw(PositiveNum PositiveOrZeroNum + PositiveInt PositiveOrZeroInt + NegativeNum NegativeOrZeroNum + NegativeInt NegativeOrZeroInt + SingleDigit) ]; use MooseX::Types::Moose qw/Num Int/; @@ -23,6 +27,18 @@ subtype PositiveNum, : () ); +subtype PositiveOrZeroNum, + as Num, + where { $_ >= 0 }, + message { "Must be a number greater than or equal to zero" }, + ( $Moose::VERSION >= 2.0200 + ? inline_as { + $_[0]->parent()->_inline_check( $_[1] ) . ' && ' + . qq{ ($_[1] >= 0) }; + } + : () + ); + subtype PositiveInt, as Int, where { $_ > 0 }, @@ -35,6 +51,18 @@ subtype PositiveInt, : () ); +subtype PositiveOrZeroInt, + as Int, + where { $_ >= 0 }, + message { "Must be an integer greater than or equal to zero" }, + ( $Moose::VERSION >= 2.0200 + ? inline_as { + $_[0]->parent()->_inline_check( $_[1] ) . ' && ' + . qq{ ($_[1] >= 0) }; + } + : () + ); + subtype NegativeNum, as Num, where { $_ < 0 }, @@ -47,6 +75,18 @@ subtype NegativeNum, : () ); +subtype NegativeOrZeroNum, + as Num, + where { $_ <= 0 }, + message { "Must be a number less than or equal to zero" }, + ( $Moose::VERSION >= 2.0200 + ? inline_as { + $_[0]->parent()->_inline_check( $_[1] ) . ' && ' + . qq{ ($_[1] <= 0) }; + } + : () + ); + subtype NegativeInt, as Int, where { $_ < 0 }, @@ -59,6 +99,18 @@ subtype NegativeInt, : () ); +subtype NegativeOrZeroInt, + as Int, + where { $_ <= 0 }, + message { "Must be an integer less than or equal to zero" }, + ( $Moose::VERSION >= 2.0200 + ? inline_as { + $_[0]->parent()->_inline_check( $_[1] ) . ' && ' + . qq{ ($_[1] <= 0) }; + } + : () + ); + subtype SingleDigit, as PositiveInt, where { $_ <= 9 }, @@ -97,11 +149,19 @@ default. =item * PositiveNum +=item * PositiveOrZeroNum + =item * PositiveInt +=item * PositiveOrZeroInt + =item * NegativeNum -=item * Int +=item * NegativeOrZeroNum + +=item * NegativeInt + +=item * NegativeOrZeroInt =item * SingleDigit