X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FTypes%2FCommon%2FNumeric.pm;h=c195a687b662027ae3b515abc1a68d158d25b6d6;hb=bf8650d89cb21d78cc6d3576e315367acd854fb4;hp=c702497941dddea5ed679ef85a5a52608be952a5;hpb=6820e93974f7ea696fb5340f01e6f4e676fdd4b0;p=gitmo%2FMooseX-Types-Common.git diff --git a/lib/MooseX/Types/Common/Numeric.pm b/lib/MooseX/Types/Common/Numeric.pm index c702497..c195a68 100644 --- a/lib/MooseX/Types/Common/Numeric.pm +++ b/lib/MooseX/Types/Common/Numeric.pm @@ -3,38 +3,125 @@ package MooseX::Types::Common::Numeric; use strict; use warnings; -our $VERSION = '0.001001'; +our $VERSION = '0.001008'; 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/; subtype PositiveNum, as Num, + where { $_ > 0 }, + message { "Must be a positive number" }, + ( $Moose::VERSION >= 2.0200 + ? inline_as { + $_[0]->parent()->_inline_check( $_[1] ) . ' && ' + . qq{ ($_[1] > 0) }; + } + : () + ); + +subtype PositiveOrZeroNum, + as Num, where { $_ >= 0 }, - message { "Must be a positive number" }; + 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 }, + message { "Must be a positive integer" }, + ( $Moose::VERSION >= 2.0200 + ? inline_as { + $_[0]->parent()->_inline_check( $_[1] ) . ' && ' + . qq{ ($_[1] > 0) }; + } + : () + ); + +subtype PositiveOrZeroInt, + as Int, where { $_ >= 0 }, - message { "Must be a positive integer" }; + 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 }, + message { "Must be a negative number" }, + ( $Moose::VERSION >= 2.0200 + ? inline_as { + $_[0]->parent()->_inline_check( $_[1] ) . ' && ' + . qq{ ($_[1] < 0) }; + } + : () + ); + +subtype NegativeOrZeroNum, + as Num, where { $_ <= 0 }, - message { "Must be a negative number" }; + 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 }, + message { "Must be a negative integer" }, + ( $Moose::VERSION >= 2.0200 + ? inline_as { + $_[0]->parent()->_inline_check( $_[1] ) . ' && ' + . qq{ ($_[1] < 0) }; + } + : () + ); + +subtype NegativeOrZeroInt, + as Int, where { $_ <= 0 }, - message { "Must be a negative integer" }; + 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 }, - message { "Must be a single digit" }; + message { "Must be a single digit" }, + ( $Moose::VERSION >= 2.0200 + ? inline_as { + $_[0]->parent()->_inline_check( $_[1] ) . ' && ' + . qq{ ($_[1] <= 9) }; + } + : () + ); 1; @@ -62,11 +149,19 @@ default. =item * PositiveNum +=item * PositiveOrZeroNum + =item * PositiveInt +=item * PositiveOrZeroInt + =item * NegativeNum -=item * Int +=item * NegativeOrZeroNum + +=item * NegativeInt + +=item * NegativeOrZeroInt =item * SingleDigit