Created
June 30, 2016 13:06
-
-
Save hirose31/84df6775419e7a13019a4d1a2f2f11aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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