Data::Transpose::Validator::Subrefs Validator using custom subroutines
sub custom_sub { my $field = shift; return $field if $field =~ m/\w/; return (undef, "Not a \\w"); } my $vcr = Data::Transpose::Validator::Subrefs->new( \&custom_sub ); ok($vcr->is_valid("H!"), "Hi! is valid"); ok(!$vcr->is_valid("!"), "! is not"); is($vcr->error, "Not a \\w", "error displayed correctly");
The constructor accepts only one argument, a reference to a subroutine. The class will provide the variable to validate as the first and only argument. The subroutine is expected to return a true value on success, or a false value on failure.
To set a custom error, the subroutine in case of error should return 2 elements, where the first should be undefined (see the example above).
Accessor to the subroutine
The call to the validator.
To install Data::Transpose, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Transpose
CPAN shell
perl -MCPAN -e shell install Data::Transpose
For more information on module installation, please visit the detailed CPAN module installation guide.