MooseX::Types::Common::Numeric - Commonly used numeric types


MooseX-Types-Common documentation Contained in the MooseX-Types-Common distribution.

Index


Code Index:

NAME

Top

MooseX::Types::Common::Numeric - Commonly used numeric types

SYNOPSIS

Top

    use MooseX::Types::Common::Numeric qw/PositiveInt/;
    has count => (is => 'rw', isa => PositiveInt);

    ...
    #this will fail
    $object->count(-33);

DESCRIPTION

Top

A set of commonly-used numeric type constraints that do not ship with Moose by default.

* PositiveNum
* PositiveInt
* NegativeNum
* Int
* SingleDigit

SEE ALSO

Top

* MooseX::Types::Common::String

AUTHORS

Top

Please see:: MooseX::Types::Common


MooseX-Types-Common documentation Contained in the MooseX-Types-Common distribution.

package MooseX::Types::Common::Numeric;

use strict;
use warnings;

our $VERSION = '0.001001';

use MooseX::Types -declare => [
  qw(PositiveNum PositiveInt NegativeNum NegativeInt SingleDigit)
];

use MooseX::Types::Moose qw/Num Int/;

subtype PositiveNum,
  as Num,
  where { $_ >= 0 },
  message { "Must be a positive number" };

subtype PositiveInt,
  as Int,
  where { $_ >= 0 },
  message { "Must be a positive integer" };

subtype NegativeNum,
  as Num,
  where { $_ <= 0 },
  message { "Must be a negative number" };

subtype NegativeInt,
  as Int,
  where { $_ <= 0 },
  message { "Must be a negative integer" };

subtype SingleDigit,
  as PositiveInt,
  where { $_ <= 9 },
  message { "Must be a single digit" };

1;

__END__;