Subject: | few bugs |
Date: | Tue, 5 May 2015 11:32:41 -0400 |
To: | bug-Validate-Tiny [...] rt.cpan.org |
From: | val <valkoles [...] gmail.com> |
Provided checks aren't exactly correct.
For example if I want to check that { var => '' } was passed for
validation is_required will return error message though variable and
its value were provided (empty string is a valid value. As undef
value). IMHO is_required check should look something like:
sub is_required {
my $err_msg = shift || 'Required';
return sub { exists $_[ 1 ] -> { $_[ 2 ] } ? undef : $err_msg }
}
and current check might be renamed to something like is_defined_and_non_empty.
Though just introducing is_defined instead sounds as a good idea to me.
Standard check is_a has line:
return undef if !defined($_[0]) || $_[0] eq '';
which is incorrect in case $_[ 0 ] is an object of a class that
overrides string comparison operators (cmp/eq/..). In such case
validation dies in the middle of process.
I'd recommend at least replacing it with:
return undef
unless defined $_[ 0 ]
&& length $_[ 0 ]; # or even ref $_[ 0 ] instead this line.
Thanks for fixing filters for undefined value.