NAME
Poz::Types - A module for handling type validation and transformation
SYNOPSIS
use
Poz::Types;
my
$type
= Poz::Types->new({
required_error
=>
'This field is required'
,
invalid_type_error
=>
'Invalid type provided'
,
});
my
$result
=
$type
->parse(
$value
);
DESCRIPTION
Poz::Types is a module designed to handle type validation and transformation. It provides a flexible way to define rules and transformations for different types.
METHODS
new
my
$type
= Poz::Types->new(\
%options
);
Creates a new Poz::Types object. The optional hash reference can contain the following keys: - required_error: Custom error message for required fields. - invalid_type_error: Custom error message for invalid types.
rule
$type
->rule();
This method should be overridden in subclasses to provide specific validation rules. By default, it throws a "Not implemented" error.
parse
my
$result
=
$type
->parse(
$value
);
Parses the given value according to the defined rules and transformations. Returns the transformed value or an error if validation fails.
safe_parse
my
(
$result
,
$error
) =
$type
->safe_parse(
$value
);
Parses the given value and returns the transformed value. If succeeds, returns a tuple of the transformed value and undef. If fails, returns a tuple of undef and an error message.
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>