Params-Validate-Strict
view release on metacpan or search on metacpan
t/function.t view on Meta::CPAN
# The early-deref mutates $value to a plain string before optional => CODE is
# evaluated. The fix captures the original ref so the coderef sees what the
# caller actually passed, not the module's internal representation.
subtest 'validate_strict: type stringref à optional CODE receives original SCALAR ref' => sub {
my $received;
my $s = 'world';
_vs({
schema => { x => {
type => 'stringref',
optional => sub { $received = $_[0]; 0 }, # 0 = required; just capture
} },
input => { x => \$s },
});
ok(ref($received) eq 'SCALAR', 'optional coderef receives the original SCALAR ref');
is(${$received}, 'world', 'the ref still points to the correct string value');
};
subtest 'validate_strict: type stringref à optional CODE returning true â param treated as optional' => sub {
# Confirm the coderef return value is honoured even though the value is a ref.
my $s = 'ignored';
( run in 0.599 second using v1.01-cache-2.11-cpan-6aa56a78535 )