NAME
Poz::Types::number - A module for number type validation and coercion
SYNOPSIS
use Poz qw/z/;
my $number = z->number;
# Validate a number
$number->rule(42); # No error
# Coerce a value to a number
my $coerced_value = $number->coerce("42.5");
# Add validation rules
$number->gt(10)->lt(100);
# Validate with custom rules
$number->rule(50); # No error
DESCRIPTION
Poz::Types::number is a module for validating and coercing number types. It provides various methods to enforce constraints on numbers, such as greater than, less than, integer, positive, negative, and multiples of a given number.
METHODS
rule
$number->rule($value);
Validates the given value against the defined rules. Throws an error if the value is invalid.
coerce
my $coerced_value = $number->coerce($value);
Coerces the given value to a number.
gt
$number->gt($min, \%opts);
Adds a rule to ensure the value is greater than the specified minimum.
gte
$number->gte($min, \%opts);
Adds a rule to ensure the value is greater than or equal to the specified minimum.
lt
$number->lt($max, \%opts);
Adds a rule to ensure the value is less than the specified maximum.
lte
$number->lte($max, \%opts);
Adds a rule to ensure the value is less than or equal to the specified maximum.
int
$number->int(\%opts);
Adds a rule to ensure the value is an integer.
positive
$number->positive(\%opts);
Adds a rule to ensure the value is a positive number.
negative
$number->negative(\%opts);
Adds a rule to ensure the value is a negative number.
nonpositive
$number->nonpositive(\%opts);
Adds a rule to ensure the value is a non-positive number.
nonnegative
$number->nonnegative(\%opts);
Adds a rule to ensure the value is a non-negative number.
multipleOf
$number->multipleOf($divisor, \%opts);
Adds a rule to ensure the value is a multiple of the specified divisor.
step
$number->step($divisor, \%opts);
Synonym for `multipleOf`.
LICENSE
Copyright (C) ytnobody.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
ytnobody <ytnobody@gmail.com>