File Coverage

blib/lib/App/yajg/Output/Json.pm
Criterion Covered Total %
statement 27 30 90.0
branch 1 2 50.0
condition 1 2 50.0
subroutine 9 10 90.0
pod 0 3 0.0
total 38 47 80.8


line stmt bran cond sub pod time code
1             package App::yajg::Output::Json;
2              
3 1     1   904 use 5.014000;
  1         4  
4 1     1   3 use strict;
  1         1  
  1         15  
5 1     1   3 use warnings;
  1         0  
  1         18  
6 1     1   3 use utf8;
  1         0  
  1         5  
7              
8 1     1   390 use parent qw(App::yajg::Output);
  1         231  
  1         3  
9              
10 1     1   68 use App::yajg;
  1         1  
  1         20  
11 1     1   3 use JSON qw();
  1         1  
  1         137  
12              
13 0     0 0 0 sub lang {'js'} # lang for highlight
14 5     5 0 15 sub need_change_depth {1} # need to change max depth via Data::Dumper
15              
16             sub as_string {
17 7     7 0 6 my $self = shift;
18 7         24 local $SIG{__WARN__} = \&App::yajg::warn_without_line;
19 7         8 my $json = eval {
20 7   50     40 JSON
21             ->new
22             ->pretty(not $self->minimal)
23             ->canonical($self->sort_keys // 0)
24             ->allow_nonref
25             ->encode($self->data)
26             };
27 7 50       28 if ($@) {
28 0         0 warn $@;
29 0         0 return '';
30             }
31 7         18 return $json;
32             }
33              
34             1;