Test2::Compare::JSON::Pointer - Representation of a hash or array reference pointed to by a JSON pointer during deep comparison.
version 0.02
use Test2::Compare::JSON::Pointer; use JSON::PP; sub my_json_test { my($pointer, $json) = @_; my @caller = caller; Test2::Compare::JSON::Pointer->new( file => $caller[1], lines => [$caller[2]], input => $json, pointer => $pointer, json => JSON::PP->new->utf8, ); }
This class lets you specify an expected hash or array reference in deep comparison along with the JSON pointer for where to find that reference.
my $string = $cmp->pointer;
The JSON pointer as a string. Something like /foo/bar
would point to baz
in the json string
{"foo":{"bar":"baz"}}
my $string = $cmp->input;
The JSON to be compared against. This should be a regular Perl scalar in Perl's internal format. It will be encoded into UTF-8 before being decoded.
my $json = $cmp->json;
The JSON object used for decoding JSON. Any one of JSON::PP, JSON::XS, JSON::MaybeXS or compatible ought to work.
This is what you would use in a .t
file, and probably what you are interested in.
Graham Ollis <plicease@cpan.org>
This software is copyright (c) 2018 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.