Why not adopt me?
NAME
Test::Deep::Filter - Perform a filter on a matched element before doing sub-matching
VERSION
version 0.001001
DESCRIPTION
This module exists so that one can apply some kind of transform of the content of some node, before applying a deep testing structure against it.
This is especially the kind of domain Test::Deep::YAML and Test::Deep::JSON are targeted at, but implemented in a more generic way.
cmp_deeply( $got, { payload => filter(\&decode_json, { x => 1 }) } )
This would perform matching against a Perl
data structure called $got
, and find its key called payload
, and, if existing, filter the key via &decode_json
, and then compare the resulting structure with { x => 1 }
.
This would in theory be equivalent to:
cmp_deeply( $got, { payload => json({ x => 1 }) } )
Except may be tailored for what ever local decoding scheme you may require, e.g.:
cmp_deeply( $got, {
payload => filter(sub {
my ( $got ) = @_;
return parse_ini( $got );
}, { x => 1 })
});
FUNCTIONS
filter
my $object = filter( \&filter_function, $expected );
cmp_deeply( $got, filter( \&filter_function, $expected ));
A filter
can take any value into &filter_function
, and return any value and the Test::Deep
infrastructure will handle the rest.
If the value cannot be parsed, or is of a type you cannot handle, or the internal logic returns an invalid value ( including any failures in internal logic that fail to parse, etc) then you must cause the function to throw an exception with "die", and the nested $expected
will be assumed to be false.
The "die" message will be used as a diagnostic for why the match failed.
AUTHOR
Kent Fredric <kentnl@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.