File Coverage

blib/lib/App/yajg/Output/Perl.pm
Criterion Covered Total %
statement 30 39 76.9
branch 4 8 50.0
condition 2 4 50.0
subroutine 9 12 75.0
pod 0 3 0.0
total 45 66 68.1


line stmt bran cond sub pod time code
1             package App::yajg::Output::Perl;
2              
3 1     1   2049 use 5.014000;
  1         2  
4 1     1   3 use strict;
  1         1  
  1         19  
5 1     1   3 use warnings;
  1         1  
  1         26  
6 1     1   3 use utf8;
  1         0  
  1         5  
7              
8 1     1   23 use parent qw(App::yajg::Output);
  1         1  
  1         4  
9              
10 1     1   44 use App::yajg;
  1         1  
  1         18  
11 1     1   2 use Data::Dumper qw();
  1         1  
  1         60  
12              
13 0     0 0 0 sub lang {'perl'} # lang for highlight
14 0     0 0 0 sub need_change_depth {0} # need to change max depth via Data::Dumper
15              
16             sub as_string {
17 2     2 0 3 my $self = shift;
18 2         7 local $SIG{__WARN__} = \&App::yajg::warn_without_line;
19 1     1   3 no warnings 'redefine';
  1         1  
  1         315  
20             local *Data::Dumper::qquote = $self->escapes
21             ? \&Data::Dumper::qquote
22             : sub {
23 0     0   0 local $_ = shift;
24 0         0 s/\\/\\\\/g;
25 0         0 s/'/\\'/g;
26 0 0       0 utf8::encode($_) if utf8::is_utf8($_);
27 0         0 return "'$_'";
28 2 50       5 };
29 2         3 my $perl = eval {
30 2 100 50     4 Data::Dumper->new([$self->data])
      50        
31             ->Indent(int not $self->minimal)
32             ->Pair($self->minimal ? '=>' : ' => ')
33             ->Terse(1)
34             ->Sortkeys($self->sort_keys // 0)
35             ->Useperl(int not $self->escapes)
36             ->Useqq(1)
37             ->Deepcopy(1)
38             ->Maxdepth($self->max_depth // 0)
39             ->Dump()
40             };
41 2 50       99 if ($@) {
42 0         0 warn $@;
43 0         0 return '';
44             }
45 2         9 return $perl;
46             }
47              
48             1;