NAME

Poz::Types::union - Union type for multiple validators in Poz

SYNOPSIS

use Poz::Builder;
use Poz::Types;

my $builder = Poz::Builder->new;
my $validator = $builder->union(
    $builder->number->multipleOf(3),
    $builder->number->multipleOf(5),
);

my $valid = $validator->parse(6); # 6 is multiple of 3 and 5
my $invalid = $validator->parse(8); # 8 is not multiple of 3 or 5

DESCRIPTION

This module provides a way to validate a value against multiple validators. The value is considered valid if it passes any of the validators.

METHODS

new

my $validator = Poz::Types::union->new(@validators);

Creates a new union validator with the given validators.

parse

my $valid = $validator->parse($value);

Validates the given value against the defined rules. Throws an error if the value is invalid.

safe_parse

my ($valid, $errors) = $validator->safe_parse($value);

Validates the given value against the defined rules. If the value is valid, it returns the parsed value. If the value is invalid, it returns the validation errors.

optional

$validator->optional;

Marks the value as optional.

default

$validator->default($default);

Sets the default value for the validator.

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>