| 1 | package JSON::Conditional; | ||||||||||||||||||||||||||||
| 2 | 14 | ▶ | use 5.006; use strict; use warnings; our $VERSION = '1.03'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 14 | ▶ | use JSON; use base 'Struct::Conditional'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 14 | our $JSON; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 14 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 14 | $JSON = JSON->new->pretty(1)->allow_blessed->convert_blessed; | |||||||||||||||||||||||||||
| 9 | } | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | sub encode { | ||||||||||||||||||||||||||
|
Subroutine
encode: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | if ($_[2]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 13 | 0 | $_[0]->encode_file($_[1], $_[2]); | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | 1 | $JSON->encode($_[1]); | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub encode_file { | ||||||||||||||||||||||||||
|
Subroutine
encode_file: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | open my $file, '>', $_[2] or die "cannot open file $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 0 | print $file $_[0]->encode($_[1]); | |||||||||||||||||||||||||||
| 21 | 0 | close $file; | |||||||||||||||||||||||||||
| 22 | 0 | return $file; | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 15 | ▶ | sub decode { | ||||||||||||||||||||||||||
|
Subroutine
decode: called CC=3 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 15 | ▶ | if ( $_[1] !~ m/\n/ && -f $_[1]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $_[1] =~ /\n/ and -f $_[1]
MC/DC0%0/2
not $_[1] =~ /\n/ and -f $_[1]
not $_[1] =~ /\n/
-f $_[1]
Truth table33%1/3
not(A) and B
A= not $_[1] =~ /\n/B= -f $_[1]
| |||||||||||||||||||||||||||||
| 27 | 0 | return $_[0]->decode_file($_[1]); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | 15 | $JSON->decode($_[1]); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub decode_file { | ||||||||||||||||||||||||||
|
Subroutine
decode_file: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | open my $file, '<', $_[1] or die "cannot open file $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | my $content = do { local $/; <$file> }; | |||||||||||||||||||||||||||
| 35 | 0 | close $file; | |||||||||||||||||||||||||||
| 36 | 0 | return $_[0]->decode($content); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 15 | ▶ | sub compile { | ||||||||||||||||||||||||||
|
Subroutine
compile: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 15 | my ($self, $json, $params, $return_struct, $out_file) = @_; | |||||||||||||||||||||||||||
| 41 | 15 | ▶ | $json = $self->decode($json) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | unless ref $json; | ||||||||||||||||||||||||||||
| 43 | 15 | ▶ | $params = $self->decode($params) unless ref $params; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 15 | $json = $self->SUPER::compile($json, $params); | |||||||||||||||||||||||||||
| 45 | 15 | ▶ | return $return_struct | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | ? $json | ||||||||||||||||||||||||||||
| 47 | : $self->encode($json, $out_file); | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 14 | 1; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||||||||||