X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FTypes%2FCommon%2FNumeric.pm;h=9d863b9b4bed8984cccca925f994c42022644b42;hb=c89e026128c964561bd1f4cf823197348044a2b7;hp=7744cfc1aaa814fe14399a823951f5f922566e57;hpb=d2461fdae3ea97b18a2b85487bb46cfc1934aa87;p=gitmo%2FMooseX-Types-Common.git diff --git a/lib/MooseX/Types/Common/Numeric.pm b/lib/MooseX/Types/Common/Numeric.pm index 7744cfc..9d863b9 100644 --- a/lib/MooseX/Types/Common/Numeric.pm +++ b/lib/MooseX/Types/Common/Numeric.pm @@ -3,21 +3,37 @@ package MooseX::Types::Common::Numeric; use strict; use warnings; -our $VERSION = '0.001001'; +our $VERSION = '0.001003'; 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 }, + 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 number greater than or equal to zero" }, + ( $Moose::VERSION >= 2.0200 + ? inline_as { + $_[0]->parent()->_inline_check( $_[1] ) . ' && ' . qq{ ($_[1] >= 0) }; } : () @@ -25,11 +41,23 @@ subtype PositiveNum, subtype PositiveInt, as Int, - where { $_ >= 0 }, + 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 an integer greater than or equal to zero" }, + ( $Moose::VERSION >= 2.0200 + ? inline_as { + $_[0]->parent()->_inline_check( $_[1] ) . ' && ' . qq{ ($_[1] >= 0) }; } : () @@ -37,11 +65,23 @@ subtype PositiveInt, subtype NegativeNum, as Num, - where { $_ <= 0 }, + 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 number less than or equal to zero" }, + ( $Moose::VERSION >= 2.0200 + ? inline_as { + $_[0]->parent()->_inline_check( $_[1] ) . ' && ' . qq{ ($_[1] <= 0) }; } : () @@ -49,11 +89,23 @@ subtype NegativeNum, subtype NegativeInt, as Int, - where { $_ <= 0 }, + 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 an integer less than or equal to zero" }, + ( $Moose::VERSION >= 2.0200 + ? inline_as { + $_[0]->parent()->_inline_check( $_[1] ) . ' && ' . qq{ ($_[1] <= 0) }; } : () @@ -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