Pad/Config/Format/Json.pm

filter: Statementstmt 100% 42 / 42 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 66.6% 2 / 3 totaltotal 98.4% 64 / 65 CC 7 SCAR 11.9
CC
7
Cov
100%
plainScalars
6.0
parse
2.0
BEGIN
1.0
CRAP 3.3
« Pad/Parser.pm ↑ Summary Pad/Spec/Option.pm »
1 5 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 5 ▶use Getopt::Pad::Config::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 class Getopt::Pad::Config::Format::Json :isa(Getopt::Pad::Config::Format) :strict(params) {
7 5 ▶ use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 our $VERSION = '0.06';
10  
11 5 ▶ use constant NAMES => ['json'];
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # An empty file sets nothing. Values arrive as plain scalars, as YAML
14 # gives them: booleans as 1 and 0, so a string option set to true reads
15 # 1, not an object; numbers as written, so a large integer is not
16 # rounded to a float before a bigint option sees it.
17 10 ▶ method parse($text) {
Subroutine parse: called CC=2 SCAR=6.9
Pod documented
18 10 ▶ return {} if $text !~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $text =~ /\S/u 2 8 10
19 8 return $self->plainScalars(JSON::PP->new->allow_bignum->decode($text));
20 5 }
21  
22 26 ▶ method plainScalars($data) {
Subroutine plainScalars: called CC=6 SCAR=17.9
Pod undocumented
23 26 ▶ return [map { $self->plainScalars($_) } $data->@*] if ref $data eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data eq "ARRAY" 1 25 26
24 25 ▶ return { map { $_ => $self->plainScalars($data->{$_}) } keys $data->%* } if ref $data eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $data eq "HASH" 14 11 25
25 11 ▶ return $data ? 1 : 0 if JSON::PP::is_bool($data);
Branch: 2 branches
BranchTrueFalseTotal
if JSON::PP::is_bool($data) 3 8 11
$data ? : 2 1 3
26 8 ▶ return "$data" if ref $data;
Branch: 1 branch
BranchTrueFalseTotal
if ref $data 4 4 8
27 4 return $data;
28 5 }
29  
30 2 ▶ method dump($data) {
Subroutine dump: called CC=1 SCAR=0.0
Pod documented
31 2 return JSON::PP->new->pretty->canonical->encode($data);
32 5 }
33 }
34  
35 5 1;
36  
37 __END__
« Pad/Parser.pm ↑ Summary Pad/Spec/Option.pm »