Tools/JSON/Pointer.pm

filter: Statementstmt 78.3% 29 / 37 Branchbran 37.5% 3 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod 100% 1 / 1 totaltotal 74.5% 41 / 55 CC 3 SCAR 7.4
CC
3
Cov
71%
__ANON__
6.0
json
2.0
BEGIN
1.0
CRAP 2.1
« Compare/JSON/Pointer.pm ↑ Summary
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
BranchTrueFalseTotal
@_ == 1 ? : 5 7 12
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
BranchTrueFalseTotal
if (eval { do { require Test2::Tools::HTTP::Tx } }) 0 4 4
33 {
34 0 ▶ return if $count++;
Branch: 1 branch
BranchTrueFalseTotal
if $count++ 0 0 0
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
BranchTrueFalseTotal
if ($pointer) 0 0 0
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__
« Compare/JSON/Pointer.pm ↑ Summary