Data-Validator

 view release on metacpan or  search on metacpan

README.md  view on Meta::CPAN

    Default to true.

- `default=> $value : Any | CodeRef`

    The default value for the argument.
    If it is a CODE reference, it is called in scalar context as
    `$default->($validator, $rule, $args)` and its return value
    is used as a default value.

    Because arguments are validated in the order of definitions, `default`
    callbacks can rely on the previously-filled values:

        my $v = Data::Validator->new(
            foo => { default => 99 },
            bar => { default => sub {
                my($validator, $this_rule, $args) = @_;
                return $args->{foo} + 1;
            } },
        );
        $v->validate();          # bar is 100
        $v->validate(foo => 42); # bar is 43

lib/Data/Validator.pm  view on Meta::CPAN

Default to true.

=item C<< default=> $value : Any | CodeRef >>

The default value for the argument.
If it is a CODE reference, it is called in scalar context as
C<< $default->($validator, $rule, $args) >> and its return value
is used as a default value.

Because arguments are validated in the order of definitions, C<default>
callbacks can rely on the previously-filled values:

    my $v = Data::Validator->new(
        foo => { default => 99 },
        bar => { default => sub {
            my($validator, $this_rule, $args) = @_;
            return $args->{foo} + 1;
        } },
    );
    $v->validate();          # bar is 100
    $v->validate(foo => 42); # bar is 43



( run in 1.459 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )