Created
October 20, 2021 13:55
-
-
Save jjn1056/a05d3fefa41d5b339d88d230760b37ca to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package Test::A; | |
use Moo; | |
use Valiant::Validations; | |
use Types::Standard qw(Str); | |
has 'b' => (is=>'ro'); | |
has 'c' => (is=>'ro'); | |
validates 'b', | |
presence => 1, | |
numericality => 'integer'; | |
validates 'c', | |
presence => 1, | |
check => Str; | |
package Test::Container; | |
use Moo; | |
use Valiant::Validations; | |
use Test::A; | |
has '_a' => (is=>'ro', init_arg=>'a'); | |
has 'a' => ( | |
init_arg=>undef, | |
is=>'ro', | |
required=>1, | |
lazy=>1, | |
builder=>'_build_a'); | |
sub _build_a { | |
my @a = map { | |
Test::A->new($_); | |
} @{$_[0]->_a}; | |
return \@a; | |
} | |
validates 'a', | |
presence => 1, | |
array => +{ validations=>[object=>1] }; | |
package Test; | |
use warnings; | |
use strict; | |
use Benchmark qw(cmpthese); | |
use Test::Container; | |
use Data::Dumper; | |
my $data = { | |
a => [{ | |
b => 5, | |
c => 'text', | |
}, { | |
b => -1, | |
c => 'another text', | |
}, ({ | |
b => 1000, | |
c => 'and another', | |
}) x 100] | |
}; | |
cmpthese(-5, { | |
valiant => sub { | |
(my $container = Test::Container->new($data))->validate; | |
die Dumper(+{$container->errors->to_hash(full_messages=>1)}) | |
unless $container->valid; | |
}, | |
}); | |
1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment