🌻 📖 Test2::Compare::JSON::Pointer

NAME

Test2::Compare::JSON::Pointer - Representation of a hash or array reference pointed to by a JSON pointer during deep comparison.

VERSION

version 0.02

SYNOPSIS

 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,
  );
 }

DESCRIPTION

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.

BASE CLASS

Test2::Compare::Base

ATTRIBUTES

pointer
 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"}}
input
 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.

json
 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.

SEE ALSO

Test2::Tools::JSON::Pointer

This is what you would use in a .t file, and probably what you are interested in.

AUTHOR

Graham Ollis <plicease@cpan.org>

COPYRIGHT AND LICENSE

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.