Data-Validate-Struct
view release on metacpan or search on metacpan
int: /\d+/
float: /\d*\\.\d+/
operator: '+' | '-' | '*' | '/'
};
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
NEGATED VALIDATOR
A negative/reverse match is automatically added as well, see "NEGATIVE
MATCHING".
EXAMPLES
Take a look to t/run.t for lots of examples.
CONFIGURATION AND ENVIRONMENT
No environment variables will be used.
SEE ALSO
I recommend you to read the following documentations, which are supplied
with perl:
perlreftut Perl references short introduction.
perlref Perl references, the rest of the story.
perldsc Perl data structures intro.
perllol Perl data structures: arrays of arrays.
Data::Validate common data validation methods.
Data::Validate::IP common data validation methods for IP-addresses.
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.
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 <http://rt.cpan.org>.
INCOMPATIBILITIES
None known.
DIAGNOSTICS
To debug Data::Validate::Struct use debug() or the perl debugger, see
perldebug.
For example to debug the regex matching during processing try this:
perl -Mre=debug yourscript.pl
DEPENDENCIES
Data::Validate::Struct depends on the module Data::Validate,
Data::Validate:IP, Regexp::Common, File::Spec and File::stat.
AUTHORS
T. v.Dein <tlinden |AT| cpan.org>
Per Carlson <pelle |AT| cpan.org>
Thanks to David Cantrell for his helpful hints.
VERSION
0.10
( run in 1.622 second using v1.01-cache-2.11-cpan-2398b32b56e )