| 1 | package Test2::Tools::JSON::Pointer; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use 5.008001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use JSON::MaybeXS qw( JSON ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 4 | ▶ | use Test2::Compare::JSON::Pointer; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 4 | ▶ | use parent 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 4 | our @EXPORT = qw( json ); | |||||||||
| 12 | |||||||||||
| 13 | # ABSTRACT: Compare parts of JSON string to data structure using JSON pointers VERSION | ||||||||||
| 14 | 4 | our $VERSION = '0.02'; # VERSION | |||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | sub json ($;$) | ||||||||||
| 18 | 12 | ▶ | { | ||||||||
|
Subroutine
json: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 19 | 12 | ▶ | my($pointer, $json) = @_ == 1 ? ('', $_[0]) : (@_); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 12 | my @caller = caller; | |||||||||
| 21 | 12 | Test2::Compare::JSON::Pointer->new( | |||||||||
| 22 | file => $caller[1], | ||||||||||
| 23 | lines => [$caller[2]], | ||||||||||
| 24 | input => $json, | ||||||||||
| 25 | pointer => $pointer, | ||||||||||
| 26 | json => JSON->new->utf8(1), | ||||||||||
| 27 | ); | ||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 4 | my $count = 0; | |||||||||
| 31 | |||||||||||
| 32 | 4 | ▶ | if(eval { require Test2::Tools::HTTP::Tx }) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | { | ||||||||||
| 34 | 0 | ▶ | return if $count++; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | require JSON::Pointer; | |||||||||
| 36 | Test2::Tools::HTTP::Tx->add_helper( | ||||||||||
| 37 | 0 | ▶ | 'res.json' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 38 | 0 | my($res, $pointer) = @_; | |||||||||
| 39 | 0 | my $json = JSON->new->utf8(1)->decode($res->decoded_content); | |||||||||
| 40 | 0 | ▶ | if($pointer) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | { | ||||||||||
| 42 | 0 | $json = JSON::Pointer->get($json, $pointer); | |||||||||
| 43 | } | ||||||||||
| 44 | 0 | return $json; | |||||||||
| 45 | } | ||||||||||
| 46 | 0 | ); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 4 | 1; | |||||||||
| 50 | |||||||||||
| 51 | __END__ | ||||||||||