File Coverage

lib/Sisimai/Data/JSON.pm
Criterion Covered Total %
statement 20 20 100.0
branch 3 4 75.0
condition 1 2 50.0
subroutine 5 5 100.0
pod 0 1 0.0
total 29 32 90.6


line stmt bran cond sub pod time code
1             package Sisimai::Data::JSON;
2 4     4   1510 use feature ':5.10';
  4         5  
  4         294  
3 4     4   19 use strict;
  4         4  
  4         75  
4 4     4   15 use warnings;
  4         7  
  4         94  
5 4     4   1052 use JSON;
  4         13313  
  4         20  
6              
7             sub dump {
8             # Data dumper(JSON)
9             # @param [Sisimai::Data] argvs Object
10             # @return [String, Undef] Dumped data or Undef if the argument is
11             # missing
12 640     640 0 2174 my $class = shift;
13 640   50     1596 my $argvs = shift // return undef;
14 640 100       1693 return undef unless ref $argvs eq 'Sisimai::Data';
15              
16 639         934 my $jsonstring = '';
17 639         967 eval { $jsonstring = JSON->new->space_after(1)->encode($argvs->damn) };
  639         8883  
18 639 50       21577 warn sprintf(" ***warning: Something is wrong in JSON encoding: %s", $@) if $@;
19 639         2661 return $jsonstring;
20             }
21              
22             1;
23             __END__