Data-Validate-Struct
view release on metacpan or search on metacpan
my $parse = Parse::RecDescent->new($grammar);
add_validators(calc => sub { defined $parse->line($_[0]) ? 1 : 0; });
my $val = Data::Validate::Struct->new({line => 'calc'});
if ($val->validate({line => "@ARGV"})) {
my $r;
eval "\$r = @ARGV";
print "$r\n";
}
else {
print "syntax error\n";
}
Now you can use it as follows:
./mycalc 54 + 100 - .1
153.9
./mycalc 8^2
syntax error
=head2 NEGATED VALIDATOR
A negative/reverse match is automatically added as well, see
L</NEGATIVE MATCHING>.
=head1 EXAMPLES
Take a look to F<t/run.t> for lots of examples.
=head1 CONFIGURATION AND ENVIRONMENT
No environment variables will be used.
=head1 SEE ALSO
I recommend you to read the following documentations, which are supplied with perl:
L<perlreftut> Perl references short introduction.
L<perlref> Perl references, the rest of the story.
L<perldsc> Perl data structures intro.
L<perllol> Perl data structures: arrays of arrays.
L<Data::Validate> common data validation methods.
L<Data::Validate::IP> common data validation methods for IP-addresses.
=head1 LICENSE AND COPYRIGHT
Copyright (c) 2007-2015 T. v.Dein
This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
=head1 BUGS AND LIMITATIONS
Some implementation details as well as the API may change
in the future. This will no more happen if entering a stable
release (starting with 1.00).
To submit use L<http://rt.cpan.org>.
=head1 INCOMPATIBILITIES
None known.
=head1 DIAGNOSTICS
To debug Data::Validate::Struct use B<debug()> or the perl debugger, see L<perldebug>.
For example to debug the regex matching during processing try this:
perl -Mre=debug yourscript.pl
=head1 DEPENDENCIES
Data::Validate::Struct depends on the module L<Data::Validate>,
L<Data::Validate:IP>, L<Regexp::Common>, L<File::Spec> and L<File::stat>.
=head1 AUTHORS
T. v.Dein <tlinden |AT| cpan.org>
Per Carlson <pelle |AT| cpan.org>
Thanks to David Cantrell for his helpful hints.
=head1 VERSION
0.11
=cut
( run in 0.494 second using v1.01-cache-2.11-cpan-df04353d9ac )