File Coverage

blib/lib/App/yajg/Output/Perl.pm
Criterion Covered Total %
statement 36 40 90.0
branch 4 6 66.6
condition 1 2 50.0
subroutine 10 12 83.3
pod 0 3 0.0
total 51 63 80.9


line stmt bran cond sub pod time code
1             package App::yajg::Output::Perl;
2              
3 1     1   2135 use 5.014000;
  1         2  
4 1     1   3 use strict;
  1         1  
  1         30  
5 1     1   3 use warnings;
  1         1  
  1         32  
6 1     1   2 use utf8;
  1         1  
  1         6  
7              
8 1     1   18 use parent qw(App::yajg::Output);
  1         1  
  1         5  
9              
10 1     1   46 use App::yajg;
  1         1  
  1         15  
11 1     1   3 use Data::Dumper qw();
  1         0  
  1         76  
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         6 local $SIG{__WARN__} = \&App::yajg::warn_without_line;
19 2         3 local $Data::Dumper::Useperl = 1;
20 1     1   3 no warnings 'redefine';
  1         1  
  1         202  
21             local *Data::Dumper::qquote = sub {
22 16     16   1051 my $d = shift;
23 16         20 $d =~ s/\\/\\\\/g;
24 16         11 $d =~ s/'/\\'/g;
25 16 50       32 utf8::encode($d) if utf8::is_utf8($d);
26 16         34 return "'$d'";
27 2         8 };
28 2         2 my $perl = eval {
29 2 100 50     5 Data::Dumper->new([$self->data])
30             ->Indent(int not $self->minimal)
31             ->Pair($self->minimal ? '=>' : ' => ')
32             ->Terse(1)
33             ->Sortkeys(int not $self->minimal)
34             ->Useqq(1)
35             ->Maxdepth($self->max_depth // 0)
36             ->Dump()
37             };
38 2 50       68 if ($@) {
39 0         0 warn $@;
40 0         0 return '';
41             }
42 2         12 return $perl;
43             }
44              
45             1;