|
NAMETest2::Compare::Custom - Custom field check for comparisons. DESCRIPTIONSometimes you want to do something complicated or unusual when validating a field nested inside a deep data structure. You could pull it out of the structure and test it separately, or you can use this to embed the check. This provides a way for you to write custom checks for fields in deep comparisons. SYNOPSIS my $cus = Test2::Compare::Custom->new(
name => 'IsRef',
operator => 'ref(...)',
stringify_got => 1,
code => sub {
my %args = @_;
return $args{got} ? 1 : 0;
},
);
# Pass
is(
{ a => 1, ref => {}, b => 2 },
{ a => 1, ref => $cus, b => 2 },
"This will pass"
);
# Fail
is(
{a => 1, ref => 'notref', b => 2},
{a => 1, ref => $cus, b => 2},
"This will fail"
);
ARGUMENTSYour custom sub will be passed 4 arguments in a hash: code => sub {
my %args = @_;
# provides got, exists, operator, name
return ref($args{got}) ? 1 : 0;
},
$_ is also localized to "got" to make it easier for those who need to use regexes.
METHODS
SOURCEThe source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. MAINTAINERSAUTHORSCOPYRIGHTCopyright Chad Granum <exodist@cpan.org>. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://dev.perl.org/licenses/
|