Skip to content

Instantly share code, notes, and snippets.

@hirose31
Created June 30, 2016 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirose31/84df6775419e7a13019a4d1a2f2f11aa to your computer and use it in GitHub Desktop.
Save hirose31/84df6775419e7a13019a4d1a2f2f11aa to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
# Time-stamp: <2016-06-30 22:05:57 JST, hirose31>
use strict;
use warnings;
use 5.010_000;
use utf8;
use Data::Validator;
sub t {
my $v = shift;
state $rule = Data::Validator->new(
n => { isa => 'Num' },
)->with('NoThrow');
my $args = $rule->validate(n => $v);
print $rule->has_errors ? 'invalid' : 'valid ';
# $rule->clear_errors if $rule->has_errors;
print " - $v\n";
}
t(2);
t('foo');
t(2); # clear_errors しないと invalid になる!!!
__END__
valid - 2
invalid - foo
invalid - 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment