| 1 | package JSON::JSONFold ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use 5.014 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use JSON::PP qw(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | our $VERSION = '0.2.2'; ## VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | our @EXPORT = qw(format_json write_json fold_text write_folded) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | our $BACKEND ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=8 SCAR=24.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | return if defined($BACKEND) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | my $backend = $ENV{JSONFOLD_BACKEND} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | if ( defined($backend)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | $backend = "JSON::$backend" if $backend =~ /^\w+/ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | ▶ | $backend = JSON::MaybeXS::JSON() if eval { require JSON::MaybeXS } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | if ( $backend ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | ▶ | eval "require $backend" or die "cannot load '$backend'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 5 | ▶ | $BACKEND = $backend || 'JSON::PP' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$backend || 'JSON::PP'
MC/DC0%0/1
$backend || 'JSON::PP'
$backend
Truth table50%1/2
A
A= $backend
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 5 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | jsonfold_config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | create_writer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | encode_json | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | to_json | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # Object Orient Interface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 19 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 19 | my ($class, %overrides) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # Required parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 19 | my $width = delete $overrides{width} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 19 | my $config = delete $overrides{config} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 19 | ▶ | my $gold = delete $overrides{gold} // 1 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $overrides{"gold"} // 1
MC/DC100%1/1
delete $overrides{"gold"} // 1
delete $overrides{"gold"}
Truth table100%2/2
A
A= delete $overrides{"gold"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 19 | my $indent = delete $overrides{indent} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 19 | ▶ | my $json = delete $overrides{json} // _json_coder($gold, $indent, %overrides) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
delete $overrides{"json"} // _json_coder($gold, $indent, %overrides)
MC/DC0%0/2
delete $overrides{"json"} // _json_coder($gold, $indent, %overrides)
delete $overrides{"json"}
_json_coder($gold, $indent, %overrides)
Truth table33%1/3
A // B
A= delete $overrides{"json"}B= _json_coder($gold, $indent, %overrides)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 19 | my $do_close = delete $overrides{do_close} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 19 | ▶ | return bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
ref $class || $class || __PACKAGE__
ref $class or $class
MC/DC0%0/2
ref $class || $class || __PACKAGE__
ref $class
$class
Truth table33%1/3
A or B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | json => $json, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | width => $width, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | config => _config($config, $width), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | do_close => $do_close, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | }, ref($class) || $class || __PACKAGE__ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 18 | ▶ | sub format { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 18 | my($self, $data) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 18 | my $config = $self->{config} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 18 | my $output = '' ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 18 | ▶ | open my $out, '>:utf8', \$output or die "open output: $!" ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 18 | my $stream = _stream($out, $config, 0) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 18 | my $json = $self->{json} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 18 | my $text = $json->encode($data) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 18 | $stream->write($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 18 | ▶ | close $out or die "close output: $!" ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 18 | ▶ | $output .= "\n" unless $output =~ /\n\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 18 | return Encode::decode('UTF-8', $output) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub fold { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fold: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my ($self, $text) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $config = $self->{config} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $output = '' ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | open my $out, '>', \$output or die "open output: $!" ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $stream = _stream($out, $config, 0) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $stream->write($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | close $out or die "close output: $!" ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $output .= "\n" unless $output =~ /\n\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | return $output ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub fold_to { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fold_to: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my ($self, $text, $fh) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $stream = _stream($fh, $self->{config}, $self->{do_close}) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $stream->write($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $stream->finish ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $stream->flush ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $stream->close or die "close output: $!" ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $info = $stream->stats ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | return $info ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | sub format_to { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_to: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | my($self, $data, $fh) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | my $stream = _stream($fh, $self->{config}, $self->{do_close}) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | my $text = $self->{json}->encode($data) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | $stream->write($text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | $stream->finish; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1 | $stream->flush; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | my $info = $stream->stats ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | $stream->close or die "close output: $!" ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | return $info ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # Functional Interface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # Not exportable. Allow using DEV::JSONFold::config(...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub config { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my($base_config, $width, %overrides) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | $width //= $overrides{width} ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$width //= $overrides{"width"}
MC/DC0%0/2
$width //= $overrides{"width"}
$width
$overrides{"width"}
Truth table0%0/3
A //= B
A= $widthB= $overrides{"width"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | return _config($base_config, $width, %overrides) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | sub jsonfold_config { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
jsonfold_config: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | my($base_config, $width, %overrides) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | ▶ | $width //= $overrides{width} ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$width //= $overrides{"width"}
MC/DC0%0/2
$width //= $overrides{"width"}
$width
$overrides{"width"}
Truth table33%1/3
A //= B
A= $widthB= $overrides{"width"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | return _config($base_config, $width, %overrides) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub format_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_json: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my($data, $width, $config, %overrides) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $fmt = __PACKAGE__->new(width => $width, config => $config, %overrides) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $output = $fmt->format($data) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | return $output ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | ▶ | sub write_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_json: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | my($data, $fh, $width, $config, %overrides) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | my $fmt = __PACKAGE__->new(width => $width, config => $config, %overrides) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | my $info = $fmt->format_to($data, $fh) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | return $info ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | sub fold_text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fold_text: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | my($text, $width, $config) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $fmt = __PACKAGE__->new(width => $width, config => $config) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | return $fmt->fold($text) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub write_folded { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_folded: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my($text, $fh, $width, $config) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $fmt = __PACKAGE__->new(width => $width, config => $config) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | return $fmt->fold_to($text, $fh) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub create_writer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_writer: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my($fh, $width, $config, %overrides) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $do_close = delete $overrides{close_fp} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | return _stream($fh, _config($config, $width, %overrides), $do_close) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # Helper for Function/OO interface methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 20 | ▶ | sub _config { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_config: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 20 | my ($preset, $width, %overrides) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 20 | ▶ | $overrides{width} = $width if defined $width ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 20 | return JSON::JSONFold::Config::config($preset, %overrides) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 19 | ▶ | sub _stream { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stream: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 19 | my ($fp, $config, $close_fp) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 19 | return JSON::JSONFold::Writer->new($fp, $config, $close_fp) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 19 | ▶ | sub _json_coder { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_json_coder: called CC=7 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 19 | my ($gold, $indent, %opt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | # Must have valid indent, otherwise cannot parse the data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 19 | ▶ | my $json = ($BACKEND || 'JSON::PP')->new->pretty ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$JSON::JSONFold::BACKEND || 'JSON::PP'
MC/DC0%0/1
$JSON::JSONFold::BACKEND || 'JSON::PP'
$JSON::JSONFold::BACKEND
Truth table50%1/2
A
A= $JSON::JSONFold::BACKEND
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 19 | ▶ | if ( $gold ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 19 | ▶ | my $sort_keys = $opt{sort_keys} // 1 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt{"sort_keys"} // 1
MC/DC100%1/1
$opt{"sort_keys"} // 1
$opt{"sort_keys"}
Truth table100%2/2
A
A= $opt{"sort_keys"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # JSON has a bug with XS implementatio, may want to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # $indent ||= 2 if ! ($json->is('JSON') && $json->is_XS()) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 19 | ▶ | $indent //=2 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$indent //= 2
MC/DC0%0/1
$indent //= 2
$indent
Truth table50%1/2
A
A= $indent
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 19 | $json->allow_nonref->canonical($sort_keys); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 19 | $json->space_before(0)->space_after(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # Some JSON coder can not set indent_length (JSON::XS), which is silently ignored | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Defaulting to indent of 3. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 19 | ▶ | $json->indent_length($indent) if $indent && $json->can('indent_length') ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$indent and $json->can("indent_length")
MC/DC0%0/2
$indent and $json->can("indent_length")
$indent
$json->can("indent_length")
Truth table33%1/3
A and B
A= $indentB= $json->can("indent_length")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 19 | return $json; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # JSON compatible API - OO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | sub encode { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my ($self, $data) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return $self->format($data) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # JSON compatiable API - Functional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 18 | ▶ | sub encode_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode_json: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 18 | my ($data, $opts) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 18 | ▶ | my %overrides = %$opts if $opts ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 18 | my $width = delete $overrides{width} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 18 | my $compact = delete $overrides{compact} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 18 | my $fmt = __PACKAGE__->new(width => $width, config => $compact, %overrides) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 18 | my $output = $fmt->format($data) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 18 | return $output ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # Same as encode_json - for users of legacy "JSON" wrapper. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | sub to_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_json: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my ($data, $opts) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | my %overrides = %$opts if $opts ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my $width = delete $overrides{width} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my $compact = delete $overrides{compact} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $fmt = __PACKAGE__->new(width => $width, config => $compact, %overrides) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | my $output = $fmt->format($data) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | return $output ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | JSON::JSONFold::CLI::run() ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | package JSON::JSONFold::Kind; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 5 | ▶ | use strict ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 5 | ▶ | use warnings ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 5 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 5 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | KIND_NONE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | KIND_DICT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | KIND_LIST | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | %OPENING_KIND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | %CLOSING_KIND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 5 | ▶ | use constant KIND_NONE => 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 5 | ▶ | use constant KIND_DICT => 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 5 | ▶ | use constant KIND_LIST => 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 5 | our %OPENING_KIND = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | '{' => KIND_DICT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | '[' => KIND_LIST, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 5 | our %CLOSING_KIND = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | '}' => KIND_DICT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | '},' => KIND_DICT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | ']' => KIND_LIST, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | '],' => KIND_LIST, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # Internal package: immutable-ish configuration record | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | package JSON::JSONFold::Config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 5 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 5 | ▶ | use constant DEFAULT_WIDTH => 100 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 5 | ▶ | use constant MAX_ARRAY_ITEMS => 1000 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 5 | ▶ | use constant MAX_OBJ_ITEMS => 1000 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 5 | ▶ | use constant MAX_NESTING => 10 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 5 | ▶ | use constant MAX_GRID_LINES => 1000 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 5 | ▶ | use constant MAX_WIDTH => 255 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 5 | our $SEQ = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 5 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 5 | C_OFF => $SEQ++, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | C_WIDTH => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | C_PACK_ARRAY_ITEMS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | C_PACK_OBJ_ITEMS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | C_PACK_NESTING => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | C_FOLD_ARRAY_ITEMS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | C_FOLD_OBJ_ITEMS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | C_FOLD_NESTING => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | C_GRID_ARRAY_ITEMS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | C_GRID_OBJ_ITEMS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | C_GRID_MIN_LINES => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | C_GRID_MAX_LINES => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | C_GRID_ARRAY_MIN => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | C_GRID_OBJ_MIN => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | C_JOIN_ARRAY_ITEMS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | C_JOIN_OBJ_ITEMS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | C_JOIN_NESTING => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | C_UNUSED_LAST => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 5 | } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 5 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | C_OFF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | C_WIDTH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | C_PACK_ARRAY_ITEMS C_PACK_OBJ_ITEMS C_PACK_NESTING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | C_FOLD_ARRAY_ITEMS C_FOLD_OBJ_ITEMS C_FOLD_NESTING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | C_GRID_ARRAY_ITEMS C_GRID_OBJ_ITEMS C_GRID_MIN_LINES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | C_GRID_MAX_LINES C_GRID_ARRAY_MIN C_GRID_OBJ_MIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | C_JOIN_ARRAY_ITEMS C_JOIN_OBJ_ITEMS C_JOIN_NESTING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 5 | our @FIELDS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | [ 'off', C_OFF ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | [ 'width', C_WIDTH ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | [ 'pack_array_items', C_PACK_ARRAY_ITEMS ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | [ 'pack_obj_items', C_PACK_OBJ_ITEMS ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | [ 'pack_nesting', C_PACK_NESTING ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | [ 'fold_array_items', C_FOLD_ARRAY_ITEMS ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | [ 'fold_obj_items', C_FOLD_OBJ_ITEMS ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | [ 'fold_nesting', C_FOLD_NESTING ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | [ grid_array_items => C_GRID_ARRAY_ITEMS ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | [ grid_obj_items => C_GRID_OBJ_ITEMS ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | [ grid_min_lines => C_GRID_MIN_LINES ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | [ grid_max_lines => C_GRID_MAX_LINES ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | [ grid_array_min => C_GRID_ARRAY_MIN ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | [ grid_obj_min => C_GRID_OBJ_MIN ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | [ 'join_array_items', C_JOIN_ARRAY_ITEMS ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | [ 'join_obj_items', C_JOIN_OBJ_ITEMS ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | [ 'join_nesting', C_JOIN_NESTING ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 5 | our %NAME_TO_INDEX = map { @$_ } @FIELDS ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 5 | our %PRESETS ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 5 | our ($NONE, $DEFAULT) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | sub as_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_hash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | my ($self) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | map { my ($name, $idx) = @$_ ; ($name => $self->[$idx]) ; } @FIELDS ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 15 | ▶ | sub _make { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_make: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 15 | my ($class, %arg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 15 | my @d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 15 | $#d = $SEQ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 15 | $d[C_OFF] = $arg{off} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 15 | $d[C_WIDTH] = $arg{width}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 15 | $d[C_PACK_ARRAY_ITEMS] = $arg{pack_array_items}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 15 | $d[C_PACK_OBJ_ITEMS] = $arg{pack_obj_items}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 15 | $d[C_PACK_NESTING] = $arg{pack_nesting}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 15 | $d[C_FOLD_ARRAY_ITEMS] = $arg{fold_array_items}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 15 | $d[C_FOLD_OBJ_ITEMS] = $arg{fold_obj_items}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 15 | $d[C_FOLD_NESTING] = $arg{fold_nesting}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 15 | $d[C_GRID_ARRAY_ITEMS] = $arg{grid_array_items} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 15 | $d[C_GRID_OBJ_ITEMS] = $arg{grid_obj_items} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 15 | $d[C_GRID_MIN_LINES] = $arg{grid_min_lines} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 15 | $d[C_GRID_MAX_LINES] = $arg{grid_max_lines} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 15 | $d[C_GRID_ARRAY_MIN] = $arg{grid_array_min} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 15 | $d[C_GRID_OBJ_MIN] = $arg{grid_obj_min} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 15 | $d[C_JOIN_ARRAY_ITEMS] = $arg{join_array_items}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 15 | $d[C_JOIN_OBJ_ITEMS] = $arg{join_obj_items}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 15 | $d[C_JOIN_NESTING] = $arg{join_nesting}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 15 | return bless \@d, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 84 | ▶ | sub _replace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_replace: called CC=9 SCAR=22.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 84 | my ($base, $validate) = (shift, shift) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 84 | ▶ | return $base unless @_ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 84 | ▶ | my $overrides = @_ == 1 && ref($_[0]) ? $_[0] : { @_ } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@_ == 1 and ref $_[0]
MC/DC50%1/2
@_ == 1 and ref $_[0]
@_ == 1
ref $_[0]
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 84 | ▶ | return $base unless %$overrides ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 46 | my @d = @$base ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 46 | for my $key (keys %$overrides) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 276 | ▶ | unless (exists $NAME_TO_INDEX{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 1 | ▶ | die "unknown JSON::JSONFold config key: $key\n" if $validate ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 1 | next ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 275 | $d[$NAME_TO_INDEX{$key}] = $overrides->{$key} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 46 | ▶ | return bless \@d, ref($base) || __PACKAGE__ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
ref $base || __PACKAGE__
MC/DC0%0/1
ref $base || __PACKAGE__
ref $base
Truth table50%1/2
A
A= ref $base
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 39 | ▶ | sub _resolve_config { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_config: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 39 | my ($config) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 39 | ▶ | return $config if ref($config) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 19 | ▶ | my $name = $config // '' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$config // ""
MC/DC100%1/1
$config // ""
$config
Truth table100%2/2
A
A= $config
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | die "unknown JSON::JSONFold preset: $name\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 19 | ▶ | unless exists $PRESETS{$name} ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 19 | return $PRESETS{$name} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 39 | ▶ | sub config { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 39 | my ($preset, %overrides) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 39 | return _replace(_resolve_config($preset), 0, \%overrides) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | my ($class, $config, @args) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | return config($config, @args) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 45 | ▶ | sub _new_preset { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_preset: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 45 | my $base = shift ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 45 | return _replace($base, 1, @_) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 5 | ▶ | sub _class_init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_class_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 5 | my $class = shift ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 5 | $DEFAULT = $class->_make( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | width => DEFAULT_WIDTH, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | pack_array_items => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | pack_obj_items => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | pack_nesting => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | fold_array_items => 10, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | fold_obj_items => 5, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | fold_nesting => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | grid_array_items => MAX_ARRAY_ITEMS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | grid_obj_items => MAX_OBJ_ITEMS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | grid_min_lines => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | grid_max_lines => 100, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | grid_array_min => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | grid_obj_min => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | join_array_items => 8, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | join_obj_items => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | join_nesting => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 5 | $NONE = $class->_make( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | width => DEFAULT_WIDTH, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | pack_array_items => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | pack_obj_items => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | pack_nesting => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | fold_array_items => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | fold_obj_items => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | fold_nesting => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | grid_array_items => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | grid_obj_items => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | grid_min_lines => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | grid_max_lines => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | grid_array_min => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | grid_obj_min => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | join_array_items => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | join_obj_items => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | join_nesting => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 5 | my %pack_max = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | pack_array_items => MAX_ARRAY_ITEMS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | pack_obj_items => MAX_OBJ_ITEMS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | pack_nesting => MAX_NESTING, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 5 | my %fold_max = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | fold_array_items => MAX_ARRAY_ITEMS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | fold_obj_items => MAX_OBJ_ITEMS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | fold_nesting => MAX_NESTING, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 5 | my %join_max = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | join_array_items => MAX_ARRAY_ITEMS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | join_obj_items => MAX_OBJ_ITEMS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | join_nesting => MAX_NESTING, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 5 | my %grid_max = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | grid_array_items => MAX_ARRAY_ITEMS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | grid_obj_items => MAX_OBJ_ITEMS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | grid_min_lines => 3, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | grid_max_lines => MAX_GRID_LINES, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 5 | %PRESETS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | off => $class->_make(off => 1), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | '' => $DEFAULT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | default => $DEFAULT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | none => $NONE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | low => _new_preset($DEFAULT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | fold_nesting => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | join_nesting => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | grid_max_lines => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | med => _new_preset($DEFAULT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | join_nesting => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | grid_max_lines => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | classic => _new_preset($DEFAULT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | grid_max_lines => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | high => _new_preset($DEFAULT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | pack_array_items => 20, pack_obj_items => 10, pack_nesting => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | fold_array_items => 20, fold_obj_items => 10, fold_nesting => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | grid_array_min => 4, grid_obj_min => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | join_array_items => 16, join_obj_items => 8, join_nesting => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | max => _new_preset($DEFAULT, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | width => MAX_WIDTH, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | %pack_max, %fold_max, %join_max, %grid_max, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | grid_array_min => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | grid_obj_min => 4, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | pack => _new_preset($NONE, %pack_max), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | fold => _new_preset($NONE, %fold_max), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | grid => _new_preset($NONE, %pack_max, %fold_max, %grid_max), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | join => _new_preset($NONE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | %fold_max, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | join_array_items => MAX_ARRAY_ITEMS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | join_obj_items => MAX_OBJ_ITEMS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | join_nesting => MAX_NESTING, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 5 | __PACKAGE__->_class_init ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | # Internal package: one physical pretty-printed line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | package JSON::JSONFold::Line ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 5 | ▶ | use strict ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 5 | ▶ | use warnings ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 5 | ▶ | use Exporter 'import' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 5 | ▶ | use constant KIND_NONE => $JSON::JSONFold::Kind::KIND_NONE ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 5 | ▶ | use constant KIND_DICT => $JSON::JSONFold::Kind::KIND_DICT ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 5 | ▶ | use constant KIND_LIST => $JSON::JSONFold::Kind::KIND_LIST ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 5 | our $SEQ = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 5 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 5 | L_INDENT => $SEQ++, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | L_PARTS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | L_PARTS_LENGTH => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | L_KIND => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | L_ITEMS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | L_LEAFS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | L_CHILD_NESTING => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | L_OPENER => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | L_CLOSER => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | L_CAN_JOIN => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | L_CAN_PACK => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | L_CAN_GRID => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 5 | } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 5 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | L_INDENT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | L_PARTS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | L_PARTS_LENGTH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | L_KIND | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | L_ITEMS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | L_LEAFS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | L_CHILD_NESTING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | L_OPENER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | L_CLOSER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | L_CAN_JOIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | L_CAN_PACK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | L_CAN_GRID | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 5 | my $KEY_RE = qr/^\s*(?:(?:"[^"\\]*")|(?:'[^'\\]*')|(?:[A-Za-z_\$][A-Za-z0-9_\$]*)|)\s*:/ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | ▶ | sub _calc_parts_length { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_calc_parts_length: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | my ($parts) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | ▶ | return 0 unless @$parts ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | my $n = -1 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | $n += 1 + length($_) for @$parts ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | return $n ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 169 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 169 | my ($class, $s) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 169 | my ($spaces) = $s =~ /^(\s*)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 169 | my $body = substr($s, length($spaces)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 169 | $body =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 169 | ▶ | my $last = length($body) ? substr($body, -1, 1) : '' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 169 | ▶ | my $opener = $JSON::JSONFold::Kind::OPENING_KIND{$last} // KIND_NONE ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$JSON::JSONFold::Kind::OPENING_KIND{$last} // undef
MC/DC100%1/1
$JSON::JSONFold::Kind::OPENING_KIND{$last} // undef
$JSON::JSONFold::Kind::OPENING_KIND{$last}
Truth table100%2/2
A
A= $JSON::JSONFold::Kind::OPENING_KIND{$last}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 169 | ▶ | my $closer = $JSON::JSONFold::Kind::CLOSING_KIND{$body} // KIND_NONE ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$JSON::JSONFold::Kind::CLOSING_KIND{$body} // undef
MC/DC100%1/1
$JSON::JSONFold::Kind::CLOSING_KIND{$body} // undef
$JSON::JSONFold::Kind::CLOSING_KIND{$body}
Truth table100%2/2
A
A= $JSON::JSONFold::Kind::CLOSING_KIND{$body}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 169 | ▶ | my $is_body = !$opener && !$closer ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opener || $closer
MC/DC100%2/2
$opener || $closer
$opener
$closer
Truth table100%3/3
A || B
A= $openerB= $closer
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 169 | my @d ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 169 | $#d = $SEQ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 169 | $d[L_INDENT] = length($spaces); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 169 | $d[L_PARTS] = [ $body ] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 169 | $d[L_PARTS_LENGTH] = length($body) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 169 | $d[L_KIND] = KIND_NONE ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 169 | ▶ | $d[L_ITEMS] = $is_body ? 1 : 0 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 169 | ▶ | $d[L_LEAFS] = $is_body ? 1 : 0 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 169 | $d[L_CHILD_NESTING] = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 169 | $d[L_OPENER] = $opener; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 169 | $d[L_CLOSER] = $closer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 169 | $d[L_CAN_JOIN] = $is_body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 169 | $d[L_CAN_PACK] = $is_body; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 169 | $d[L_CAN_GRID] = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 169 | return bless \@d, $class ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 60 | ▶ | sub raw { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
raw: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 60 | return (' ' x $_[0][L_INDENT]) . join(' ', @{ $_[0][L_PARTS] }) . "\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 106 | ▶ | sub width { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
width: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 106 | return $_[0][L_INDENT] + $_[0][L_PARTS_LENGTH] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 45 | ▶ | sub can_merge { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_merge: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 45 | my ($self, $other, $item_limit, $width_limit) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 45 | ▶ | return $self->[L_INDENT] == $other->[L_INDENT] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$self->[0] == $other->[0] && $self->[4] + $other->[4] <= $item_limit && $self->[0] + $self->[2] + 1 + $other->[2] <= $width_limit
$self->[0] == $other->[0] and $self->[4] + $other->[4] <= $item_limit
MC/DC0%0/3
$self->[0] == $other->[0] && $self->[4] + $other->[4] <= $item_limit && $self->[0] + $self->[2] + 1 + $other->[2] <= $width_limit
$self->[0] == $other->[0]
$self->[4] + $other->[4] <= $item_limit
$self->[0] + $self->[2] + 1 + $other->[2] <= $width_limit
Truth table25%1/4
A and B && C
A= $self->[0] == $other->[0]B= $self->[4] + $other->[4] <= $item_limitC= $self->[0] + $self->[2] + 1 + $other->[2] <= $width_limit
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | && $self->[L_ITEMS] + $other->[L_ITEMS] <= $item_limit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | && $self->[L_INDENT] + $self->[L_PARTS_LENGTH] + 1 + $other->[L_PARTS_LENGTH] <= $width_limit ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 45 | ▶ | sub merge_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge_line: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 45 | my ($self, $other) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 45 | push @{ $self->[L_PARTS] }, @{ $other->[L_PARTS] } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 45 | ▶ | $self->[L_PARTS_LENGTH] += 1 + $other->[L_PARTS_LENGTH] if @{ $other->[L_PARTS] } ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 45 | $self->[L_ITEMS] += $other->[L_ITEMS]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 45 | $self->[L_LEAFS] += $other->[L_LEAFS]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 45 | ▶ | if ($other->[L_CHILD_NESTING] > $self->[L_CHILD_NESTING]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | $self->[L_CHILD_NESTING] = $other->[L_CHILD_NESTING]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 0 | $self->[L_CAN_PACK] = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 45 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | ▶ | sub set_parts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_parts: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | my ($self, $parts) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | $self->[L_PARTS] = $parts ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | $self->[L_PARTS_LENGTH] = _calc_parts_length($parts) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | return $self ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | sub dict_signature { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dict_signature: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | my ($self) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | my @parts = @{ $self->[L_PARTS] } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | ▶ | return undef if @parts < 3 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 0 | my @signature ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | for my $part (@parts[1 .. $#parts - 1]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | ▶ | return undef unless $part =~ /($KEY_RE)/ ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 0 | push @signature, $1 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | return join("\x1e", @signature) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | sub _format_parts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_parts: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 0 | my ($parts, $widths) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 0 | my $last = $#$widths ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | my @out ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | for my $i (0 .. $#$parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | my $part = $parts->[$i] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | my $w = $widths->[$i] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | ▶ | if ($part =~ /^[\-0-9]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | push @out, sprintf("%*s", $w, $part) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | elsif ($i < $last) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | push @out, sprintf("%-*s", $w, $part) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | push @out, $part ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | return \@out ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | ▶ | sub apply_grid { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_grid: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 0 | my ($self, $widths) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 0 | return $self->set_parts(_format_parts($self->[L_PARTS], $widths)) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | # Internal package: stack frame for a currently open JSON container | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | package JSON::JSONFold::Frame; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 5 | ▶ | use Exporter 'import' ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 5 | JSON::JSONFold::Line->import() ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 5 | our $SEQ = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 5 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 5 | F_KIND => $SEQ++, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | F_INDENT => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | F_DEPTH => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | F_LINES => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | F_PARTS_LENGTH => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | F_PACK_LIMIT => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | F_FOLD_LIMIT => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | F_JOIN_LIMIT => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | F_GRID_LIMIT => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | F_GRID_MIN_ITEMS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | F_CONTENT_LINES => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | F_ITEMS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | F_LEAFS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | F_FOLD_OK => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | F_GRID_OK => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | F_CHILD_NESTING => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 5 | } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 5 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | F_KIND F_INDENT F_DEPTH F_LINES F_PARTS_LENGTH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | F_PACK_LIMIT F_FOLD_LIMIT F_JOIN_LIMIT F_GRID_LIMIT F_GRID_MIN_ITEMS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | F_CONTENT_LINES F_ITEMS F_LEAFS F_FOLD_OK F_GRID_OK F_CHILD_NESTING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 47 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=24.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 47 | my ($class, %arg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 47 | my @d ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 47 | $#d = $SEQ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 47 | ▶ | $d[F_KIND] = $arg{kind} // 0 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"kind"} // 0
MC/DC0%0/1
$arg{"kind"} // 0
$arg{"kind"}
Truth table50%1/2
A
A= $arg{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 47 | ▶ | $d[F_INDENT] = $arg{indent} // 0 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"indent"} // 0
MC/DC0%0/1
$arg{"indent"} // 0
$arg{"indent"}
Truth table50%1/2
A
A= $arg{"indent"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 47 | ▶ | $d[F_DEPTH] = $arg{depth} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"depth"} // 0
MC/DC0%0/1
$arg{"depth"} // 0
$arg{"depth"}
Truth table50%1/2
A
A= $arg{"depth"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 47 | ▶ | $d[F_LINES] = $arg{lines} // []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"lines"} // []
MC/DC0%0/1
$arg{"lines"} // []
$arg{"lines"}
Truth table50%1/2
A
A= $arg{"lines"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 47 | $d[F_PARTS_LENGTH] = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 47 | ▶ | $d[F_PACK_LIMIT] = $arg{pack_limit} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"pack_limit"} // 0
MC/DC0%0/1
$arg{"pack_limit"} // 0
$arg{"pack_limit"}
Truth table50%1/2
A
A= $arg{"pack_limit"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 47 | ▶ | $d[F_FOLD_LIMIT] = $arg{fold_limit} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"fold_limit"} // 0
MC/DC0%0/1
$arg{"fold_limit"} // 0
$arg{"fold_limit"}
Truth table50%1/2
A
A= $arg{"fold_limit"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 47 | ▶ | $d[F_JOIN_LIMIT] = $arg{join_limit} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"join_limit"} // 0
MC/DC0%0/1
$arg{"join_limit"} // 0
$arg{"join_limit"}
Truth table50%1/2
A
A= $arg{"join_limit"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 47 | ▶ | $d[F_GRID_LIMIT] = $arg{grid_limit} // 0 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"grid_limit"} // 0
MC/DC0%0/1
$arg{"grid_limit"} // 0
$arg{"grid_limit"}
Truth table50%1/2
A
A= $arg{"grid_limit"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 47 | ▶ | $d[F_GRID_MIN_ITEMS] = $arg{grid_min_items} // 0 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$arg{"grid_min_items"} // 0
MC/DC0%0/1
$arg{"grid_min_items"} // 0
$arg{"grid_min_items"}
Truth table50%1/2
A
A= $arg{"grid_min_items"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 47 | $d[F_CONTENT_LINES] = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 47 | $d[F_ITEMS] = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 47 | $d[F_LEAFS] = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 47 | $d[F_FOLD_OK] = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 47 | $d[F_GRID_OK] = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 47 | $d[F_CHILD_NESTING] = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 47 | return bless \@d, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 124 | ▶ | sub is_empty { return @{ $_[0][F_LINES] } == 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_empty: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 90 | ▶ | sub last_line { return $_[0][F_LINES][-1] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_line: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 205 | ▶ | sub update_stats { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_stats: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 205 | my ($self, $line) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 205 | $self->[F_ITEMS] += $line->[L_ITEMS]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 205 | $self->[F_LEAFS] += $line->[L_LEAFS]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 205 | ▶ | $self->[F_PARTS_LENGTH] += $line->[L_PARTS_LENGTH] + ($self->[F_PARTS_LENGTH] ? 1 : 0) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 205 | ▶ | if ($line->[L_CHILD_NESTING] >= $self->[F_CHILD_NESTING]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 61 | $self->[F_CHILD_NESTING] = $line->[L_CHILD_NESTING] + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 205 | return ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 166 | ▶ | sub add_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_line: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 166 | my ($self, $line) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 166 | push @{ $self->[F_LINES] }, $line ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | 166 | ▶ | if (!$line->[L_OPENER] && !$line->[L_CLOSER]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$line->[7] or $line->[8]
MC/DC100%2/2
$line->[7] or $line->[8]
$line->[7]
$line->[8]
Truth table100%3/3
A or B
A= $line->[7]B= $line->[8]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 62 | $self->[F_CONTENT_LINES]++ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 166 | $self->update_stats($line) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 166 | return ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 101 | ▶ | sub check_fold_limits { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_fold_limits: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 101 | my ($self, $cfg) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 101 | ▶ | return 0 if $self->[F_PARTS_LENGTH] > $cfg->[JSON::JSONFold::Config::C_WIDTH] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 101 | ▶ | return 0 if $self->[F_ITEMS] > $self->[F_FOLD_LIMIT] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 97 | ▶ | return 0 if $self->[F_CHILD_NESTING] >= $cfg->[JSON::JSONFold::Config::C_FOLD_NESTING] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 92 | return 1 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 32 | ▶ | sub fold_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fold_lines: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 32 | my ($self, $cfg) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 32 | my @parts = map { @{ $_->[L_PARTS] } } @{ $self->[F_LINES] } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | 32 | my @d ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 32 | $#d = $JSON::JSONFold::Line::SEQ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | 32 | $d[L_INDENT] = $self->[F_INDENT] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 32 | $d[L_PARTS] = \@parts ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 32 | $d[L_PARTS_LENGTH] = $self->[F_PARTS_LENGTH] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 32 | $d[L_KIND] = $self->[F_KIND] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 32 | $d[L_ITEMS] = 1 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 32 | $d[L_LEAFS] = $self->[F_LEAFS] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | 32 | $d[L_CHILD_NESTING] = $self->[F_CHILD_NESTING] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 32 | $d[L_OPENER] = JSON::JSONFold::Kind::KIND_NONE ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 32 | $d[L_CLOSER] = JSON::JSONFold::Kind::KIND_NONE ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 32 | $d[L_CAN_PACK] = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 32 | ▶ | $d[L_CAN_JOIN] = $self->[F_CHILD_NESTING] < $cfg->[JSON::JSONFold::Config::C_JOIN_NESTING] ? 1 : 0 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 32 | ▶ | $d[L_CAN_GRID] = ($cfg->[JSON::JSONFold::Config::C_GRID_MAX_LINES] > 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cfg->[11] > 0 and $self->[11] <= $self->[8]
MC/DC50%1/2
$cfg->[11] > 0 and $self->[11] <= $self->[8]
$cfg->[11] > 0
$self->[11] <= $self->[8]
Truth table66%2/3
A and B
A= $cfg->[11] > 0B= $self->[11] <= $self->[8]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | && $self->[F_ITEMS] <= $self->[F_GRID_LIMIT]) ? 1 : 0 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 32 | @{ $self->[F_LINES] } = (bless \@d, 'JSON::JSONFold::Line') ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 32 | return ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 10 | ▶ | sub join_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
join_lines: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 10 | my ($self, $cfg) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 10 | my $lines = $self->[F_LINES] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 10 | my $n = @$lines ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 10 | ▶ | return if $n < 2 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 10 | my $prev = $lines->[0] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 10 | my $write_pos = 1 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 10 | ▶ | for (my $read_pos = 1; $read_pos < $n; $read_pos++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | 26 | my $line = $lines->[$read_pos] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | 26 | ▶ | if ($prev->[L_CAN_JOIN] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$prev->[9] and $line->[9] and $prev->can_merge($line, $self->[7], $cfg->[1])
$prev->[9] and $line->[9]
MC/DC66%2/3
$prev->[9] and $line->[9] and $prev->can_merge($line, $self->[7], $cfg->[1])
$prev->[9]
$line->[9]
$prev->can_merge($line, $self->[7], $cfg->[1])
Truth table75%3/4
A and B and C
A= $prev->[9]B= $line->[9]C= $prev->can_merge($line, $self->[7], $cfg->[1])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | && $line->[L_CAN_JOIN] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | && $prev->can_merge($line, $self->[F_JOIN_LIMIT], $cfg->[JSON::JSONFold::Config::C_WIDTH])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 6 | $prev->merge_line($line) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 6 | $prev->[L_CAN_PACK] = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | 20 | ▶ | $lines->[$write_pos] = $line if $read_pos != $write_pos ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 20 | $prev = $line ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 20 | $write_pos++ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 10 | ▶ | splice(@$lines, $write_pos) if $write_pos < @$lines ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 10 | $self->[F_CONTENT_LINES] -= ($n - $write_pos) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 10 | return ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | # Internal package: counters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | package JSON::JSONFold::Stats; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 19 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 19 | my ($class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 19 | return bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | bytes_in => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | bytes_out => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | lines_in => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | lines_out => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 0 | ▶ | sub bytes_in { $_[0]{bytes_in} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bytes_in: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 0 | ▶ | sub bytes_out { $_[0]{bytes_out} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bytes_out: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 0 | ▶ | sub lines_in { $_[0]{lines_in} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lines_in: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 0 | ▶ | sub lines_out { $_[0]{lines_out} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lines_out: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 0 | ▶ | sub as_hash { return %{ $_[0] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_hash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | # Internal package: streaming folding filter/writer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | package JSON::JSONFold::Writer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 5 | ▶ | use Encode ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 5 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 5 | JSON::JSONFold::Line->import() ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 5 | JSON::JSONFold::Frame->import() ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 5 | JSON::JSONFold::Config->import() ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | 5 | our $SEQ = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 5 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 5 | W_UNUSED_FIRST => $SEQ++, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | W_FH => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | W_CFG => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | W_PENDING => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | W_STACK => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | W_STATS => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | W_DO_CLOSE => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | W_UNUSED_LAST => $SEQ++, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | 5 | } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 19 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 19 | my ($class, $fh, $config, $do_close) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 19 | my $cfg = JSON::JSONFold::Config::config($config) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 19 | my @d ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | 19 | $#d = $SEQ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 19 | $d[W_FH] = $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | 19 | ▶ | $d[W_CFG] = $cfg unless $cfg->[C_OFF] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 19 | $d[W_PENDING] = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 19 | $d[W_STACK] = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | 19 | $d[W_STATS] = JSON::JSONFold::Stats->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | 19 | $d[W_DO_CLOSE] = $do_close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 19 | return bless \@d, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 1 | ▶ | sub stats { return $_[0][W_STATS] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stats: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | 19 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 19 | my ($self, $s) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 19 | ▶ | $s = '' unless defined $s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 19 | my $len = length($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 19 | $self->[W_STATS]{bytes_in} += $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 19 | ▶ | unless ($self->[W_CFG]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | 1 | $self->[W_STATS]{lines_in} += _count_newlines($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 1 | return $self->_write_str($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 18 | my $nl = index($s, "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 18 | ▶ | if ($nl < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 0 | $self->[W_PENDING] .= $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | 0 | return $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 18 | my $nl2 = index($s, "\n", $nl + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 18 | ▶ | if ($nl2 < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 2 | $self->[W_STATS]{lines_in}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 2 | my $line_text = $self->[W_PENDING] . substr($s, 0, $nl); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | 2 | $self->[W_PENDING] = substr($s, $nl + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 2 | $self->_feed(JSON::JSONFold::Line->parse($line_text)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 2 | return $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | # We have multiple lines - at least 2 new lines in the new buffer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 16 | my @lines = split("\n", $s, -1) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | 16 | $lines[0] = $self->[W_PENDING] . $lines[0] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 16 | $self->[W_PENDING] = pop @lines ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | 16 | for my $part ( @lines ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | 167 | $self->_feed(JSON::JSONFold::Line->parse($part)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | 16 | $self->[W_STATS]{lines_in} += @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | 16 | return $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 0 | ▶ | sub write_bytes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_bytes: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 0 | my ($self, $s) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 0 | ▶ | $s = '' unless defined $s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | 0 | my $len = length($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | 0 | $self->[W_STATS]{bytes_in} += $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | 0 | ▶ | unless ($self->[W_CFG]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | 0 | $self->[W_STATS]{lines_in} += _count_newlines($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | 0 | return $self->_write_str($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | 0 | my $nl = index($s, "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | 0 | ▶ | if ($nl < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 0 | $self->[W_PENDING] .= $s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | 0 | return $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | 0 | my $nl2 = index($s, "\n", $nl + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | 0 | ▶ | if ($nl2 < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | 0 | $self->[W_STATS]{lines_in}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | 0 | my $line_data = $self->[W_PENDING] . substr($s, 0, $nl); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | 0 | my $line_text = Encode::decode('UTF-8', $line_data) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | 0 | $self->[W_PENDING] = substr($s, $nl + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | 0 | $self->_feed(JSON::JSONFold::Line->parse($line_text)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | 0 | return $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | # We have multiple lines - at least 2 new lines in the new buffer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | 0 | $s = $self->[W_PENDING] . $s ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 0 | my $last_nl = rindex($s, "\n") ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | # Move last partial lines to pending, remove from $s | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 0 | $self->[W_PENDING] = substr(substr($s, $last_nl, length($s)-$last_nl, ""), 1) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 0 | my @lines = split("\n", Encode::decode('UTF-8', $s), -1) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 0 | for my $part ( @lines ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | 0 | $self->_feed(JSON::JSONFold::Line->parse($part)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | 0 | $self->[W_STATS]{lines_in} += @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 0 | return $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | 2 | ▶ | sub finish { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finish: called CC=4 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | 2 | ▶ | if (length $self->[W_PENDING]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 0 | $self->_feed(JSON::JSONFold::Line->parse($self->[W_PENDING], $self->_parent_kind)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 0 | $self->[W_PENDING] = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | 2 | for my $frame (@{ $self->[W_STACK] }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 0 | $self->_write_line($_) for @{ $frame->[F_LINES] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | 2 | @{ $self->[W_STACK] } = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 2 | ▶ | sub flush { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | 2 | my $fh = $self->[W_FH]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 2 | ▶ | $fh->flush if $fh && $fh->can('flush'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$fh and $fh->can("flush")
MC/DC0%0/2
$fh and $fh->can("flush")
$fh
$fh->can("flush")
Truth table33%1/3
A and B
A= $fhB= $fh->can("flush")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | 1 | ▶ | sub close { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | 1 | $self->finish; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | 1 | $self->flush; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | 1 | ▶ | $self->[W_FH]->close if $self->[W_DO_CLOSE] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | 169 | ▶ | sub _feed { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_feed: called CC=8 SCAR=20.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | 169 | my ($self, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | # Opener | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | 169 | ▶ | if ($line->[L_OPENER]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | my $frame = JSON::JSONFold::Frame->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | kind => $line->[L_OPENER], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | indent => $line->[L_INDENT], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | 47 | depth => scalar(@{ $self->[W_STACK] }), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | pack_limit => $self->_pack_limit($line->[L_OPENER]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | fold_limit => $self->_fold_limit($line->[L_OPENER]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | join_limit => $self->_join_limit($line->[L_OPENER]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | grid_limit => $self->_grid_limit($line->[L_OPENER]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | grid_min_items => $self->_grid_min_items($line->[L_OPENER]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 47 | $frame->add_line($line) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 47 | push @{ $self->[W_STACK] }, $frame ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 47 | ▶ | $self->_mark_no_fold if $line->width > $self->[W_CFG][C_WIDTH] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 47 | return ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 122 | ▶ | unless (@{ $self->[W_STACK] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 2 | $self->_write_line($line) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | 2 | return ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 120 | my $frame = $self->[W_STACK][-1] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 120 | ▶ | if ($line->[L_CLOSER]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 47 | ▶ | if ($frame->[F_KIND] != $line->[L_CLOSER]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 0 | $frame->[F_FOLD_OK] = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 0 | $frame->[F_GRID_OK] = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 47 | $frame->add_line($line) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 47 | $self->_close_frame ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | 47 | return ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | 73 | ▶ | $line->[L_CAN_PACK] = 0 if $line->[L_ITEMS] >= $frame->[F_PACK_LIMIT] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 73 | ▶ | $line->[L_CAN_JOIN] = 0 if $line->[L_ITEMS] >= $frame->[F_JOIN_LIMIT] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 73 | $self->_add_to_frame($frame, $line) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | 73 | return ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | 62 | ▶ | sub _emit_lines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_emit_lines: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 62 | my ($self, $lines, $depth) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | 62 | ▶ | return unless @$lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | 62 | ▶ | $depth = @{ $self->[W_STACK] } - 1 unless defined $depth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | 62 | ▶ | if ($depth < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | 24 | $self->_write_line($_) for @$lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | 24 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | 38 | my $frame = $self->[W_STACK][$depth]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | 38 | $self->_add_to_frame($frame, $_) for @$lines; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | 38 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | 124 | ▶ | sub _add_to_frame { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_to_frame: called CC=21 SCAR=31.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | 124 | my ($self, $frame, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | 124 | ▶ | if (!$frame->is_empty) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | 107 | ▶ | unless ($frame->[F_GRID_OK]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | 90 | my $prev = $frame->last_line ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | 90 | ▶ | return if $line->[L_CAN_PACK] && $prev->[L_CAN_PACK] && $self->_try_pack($frame, $prev, $line) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$line->[10] and $prev->[10] and $self->_try_pack($frame, $prev, $line)
$line->[10] and $prev->[10]
MC/DC66%2/3
$line->[10] and $prev->[10] and $self->_try_pack($frame, $prev, $line)
$line->[10]
$prev->[10]
$self->_try_pack($frame, $prev, $line)
Truth table75%3/4
A and B and C
A= $line->[10]B= $prev->[10]C= $self->_try_pack($frame, $prev, $line)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | 55 | ▶ | return if $line->[L_CAN_JOIN] && $prev->[L_CAN_JOIN] && $self->_try_join($frame, $prev, $line) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$line->[9] and $prev->[9] and $self->_try_join($frame, $prev, $line)
$line->[9] and $prev->[9]
MC/DC66%2/3
$line->[9] and $prev->[9] and $self->_try_join($frame, $prev, $line)
$line->[9]
$prev->[9]
$self->_try_join($frame, $prev, $line)
Truth table75%3/4
A and B and C
A= $line->[9]B= $prev->[9]C= $self->_try_join($frame, $prev, $line)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | # If frame is empty, may be it's in "streaming" mode, which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | # mean that lines that can not be packed/joined can be sent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | # directly to the output: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | ▶ | } elsif ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$frame->[13] || $line->[10] || $line->[9]
$frame->[13] or $line->[10]
MC/DC33%1/3
$frame->[13] || $line->[10] || $line->[9]
$frame->[13]
$line->[10]
$line->[9]
Truth table50%2/4
A or B || C
A= $frame->[13]B= $line->[10]C= $line->[9]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | !$frame->[F_FOLD_OK] && !$line->[L_CAN_PACK] && !$line->[L_CAN_JOIN] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 13 | $self->_write_line($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 13 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 72 | $frame->add_line($line) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | 72 | ▶ | if ( $frame->[F_FOLD_OK] && $line->width > $self->[W_CFG][C_WIDTH] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$frame->[13] and $line->width > $self->[2][1]
MC/DC0%0/2
$frame->[13] and $line->width > $self->[2][1]
$frame->[13]
$line->width > $self->[2][1]
Truth table66%2/3
A and B
A= $frame->[13]B= $line->width > $self->[2][1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 0 | $self->_mark_no_fold ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | 72 | ▶ | unless ($line->[L_CLOSER]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | 67 | ▶ | if ($frame->[F_FOLD_OK] && !$frame->check_fold_limits($self->[W_CFG])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$frame->[13] and not $frame->check_fold_limits($self->[2])
MC/DC100%2/2
$frame->[13] and not $frame->check_fold_limits($self->[2])
$frame->[13]
not $frame->check_fold_limits($self->[2])
Truth table100%3/3
A and not(B)
A= $frame->[13]B= not $frame->check_fold_limits($self->[2])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 8 | $self->_mark_no_fold ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | 67 | ▶ | if ($frame->[F_GRID_OK] && !$line->[L_CAN_GRID]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$frame->[14] and not $line->[11]
MC/DC0%0/2
$frame->[14] and not $line->[11]
$frame->[14]
not $line->[11]
Truth table66%2/3
A and not(B)
A= $frame->[14]B= not $line->[11]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | 0 | $self->_mark_no_grid ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | 0 | $frame->join_lines($self->[W_CFG]) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 72 | ▶ | $self->_stream_frame($frame) unless $frame->[F_FOLD_OK] || $frame->[F_GRID_OK] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$frame->[13] or $frame->[14]
MC/DC100%2/2
$frame->[13] or $frame->[14]
$frame->[13]
$frame->[14]
Truth table100%3/3
A or B
A= $frame->[13]B= $frame->[14]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | 72 | return ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | 39 | ▶ | sub _merge_into_frame { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_into_frame: called CC=7 SCAR=20.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | 39 | my ($self, $frame, $prev, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | 39 | $prev->merge_line($line) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | 39 | ▶ | $prev->[L_CAN_PACK] = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$prev->[4] >= $frame->[5] or $prev->[6] >= $self->[2][4]
MC/DC50%1/2
$prev->[4] >= $frame->[5] or $prev->[6] >= $self->[2][4]
$prev->[4] >= $frame->[5]
$prev->[6] >= $self->[2][4]
Truth table66%2/3
A or B
A= $prev->[4] >= $frame->[5]B= $prev->[6] >= $self->[2][4]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | if $prev->[L_ITEMS] >= $frame->[F_PACK_LIMIT] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | || $prev->[L_CHILD_NESTING] >= $self->[W_CFG][C_PACK_NESTING] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | 39 | ▶ | $prev->[L_CAN_JOIN] = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$prev->[4] >= $frame->[7] or $prev->[6] >= $self->[2][16]
MC/DC50%1/2
$prev->[4] >= $frame->[7] or $prev->[6] >= $self->[2][16]
$prev->[4] >= $frame->[7]
$prev->[6] >= $self->[2][16]
Truth table66%2/3
A or B
A= $prev->[4] >= $frame->[7]B= $prev->[6] >= $self->[2][16]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | if $prev->[L_ITEMS] >= $frame->[F_JOIN_LIMIT] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | || $prev->[L_CHILD_NESTING] >= $self->[W_CFG][C_JOIN_NESTING] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 39 | $frame->update_stats($line) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | 39 | ▶ | if ($frame->[F_FOLD_OK] && !$frame->check_fold_limits($self->[W_CFG])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$frame->[13] and not $frame->check_fold_limits($self->[2])
MC/DC0%0/2
$frame->[13] and not $frame->check_fold_limits($self->[2])
$frame->[13]
not $frame->check_fold_limits($self->[2])
Truth table66%2/3
A and not(B)
A= $frame->[13]B= not $frame->check_fold_limits($self->[2])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 0 | $self->_mark_no_fold ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | 0 | $self->_stream_frame($frame) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 35 | ▶ | sub _try_pack { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_try_pack: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | 35 | my ($self, $frame, $prev, $line) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | 35 | ▶ | return 0 if $frame->[F_PACK_LIMIT] <= 1 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 35 | ▶ | return 0 unless $prev->can_merge($line, $frame->[F_PACK_LIMIT], $self->[W_CFG][C_WIDTH]) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | 35 | $self->_merge_into_frame($frame, $prev, $line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 35 | ▶ | $prev->[L_CAN_JOIN] = 0 unless $prev->[L_CAN_PACK] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | 35 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | 10 | ▶ | sub _try_grid { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_try_grid: called CC=21 SCAR=57.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | 10 | my ($self, $frame) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | 10 | ▶ | return 0 if $frame->[F_KIND] != JSON::JSONFold::Kind::KIND_LIST ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | 1 | my $line_count = @{ $frame->[F_LINES] } - 2 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | 1 | ▶ | return 0 if $line_count < 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$line_count < 2 or $line_count < $self->[2][10] or $line_count > $self->[2][11]
$line_count < 2 or $line_count < $self->[2][10]
MC/DC0%0/3
$line_count < 2 or $line_count < $self->[2][10] or $line_count > $self->[2][11]
$line_count < 2
$line_count < $self->[2][10]
$line_count > $self->[2][11]
Truth table25%1/4
A or B or C
A= $line_count < 2B= $line_count < $self->[2][10]C= $line_count > $self->[2][11]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | || $line_count < $self->[W_CFG][C_GRID_MIN_LINES] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | || $line_count > $self->[W_CFG][C_GRID_MAX_LINES] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | 0 | my @lines = @{ $frame->[F_LINES] }[1 .. @{ $frame->[F_LINES] } - 2] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | 0 | ▶ | return 0 unless @lines ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 0 | my $first = $lines[0] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | 0 | my $part_count = @{ $first->[L_PARTS] } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | 0 | ▶ | return 0 if $part_count < 4 || ($part_count - 2) < $frame->[F_GRID_MIN_ITEMS] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$part_count < 4 or $part_count - 2 < $frame->[9]
MC/DC0%0/2
$part_count < 4 or $part_count - 2 < $frame->[9]
$part_count < 4
$part_count - 2 < $frame->[9]
Truth table0%0/3
A or B
A= $part_count < 4B= $part_count - 2 < $frame->[9]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 0 | for my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 0 | ▶ | return 0 if @{ $line->[L_PARTS] } != $part_count ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 0 | ▶ | if ($first->[L_KIND] == JSON::JSONFold::Kind::KIND_DICT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 0 | my $sig = $first->dict_signature ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 0 | ▶ | return 0 unless defined $sig ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 0 | for my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | 0 | my $line_sig = $line->dict_signature ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | 0 | ▶ | return 0 unless defined $line_sig && $line_sig eq $sig ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $line_sig and $line_sig eq $sig
MC/DC0%0/2
defined $line_sig and $line_sig eq $sig
defined $line_sig
$line_sig eq $sig
Truth table0%0/3
A and B
A= defined $line_sigB= $line_sig eq $sig
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 0 | my @widths ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 0 | for my $i (0 .. $part_count - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | 0 | my $max = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | 0 | for my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | 0 | my $len = length($line->[L_PARTS][$i]) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | 0 | ▶ | $max = $len if $len > $max ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | 0 | push @widths, $max ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | 0 | my $grided_length = -1 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | 0 | $grided_length += 1 + $_ for @widths ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | 0 | ▶ | return 0 if $frame->[F_LINES][0][L_INDENT] + $grided_length > $self->[W_CFG][C_WIDTH] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | 0 | for my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 0 | $line->apply_grid(\@widths) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | 0 | $line->[L_CAN_PACK] = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | 0 | $line->[L_CAN_JOIN] = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 0 | $line->[L_CAN_GRID] = 0 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 0 | return 1 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | 4 | ▶ | sub _try_join { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_try_join: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | 4 | my ($self, $frame, $prev, $line) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | 4 | ▶ | return 0 if $frame->[F_JOIN_LIMIT] <= 1 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | 4 | ▶ | return 0 unless $prev->can_merge($line, $frame->[F_JOIN_LIMIT], $self->[W_CFG][C_WIDTH]) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | 4 | $self->_merge_into_frame($frame, $prev, $line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | 47 | ▶ | sub _close_frame { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_close_frame: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | 47 | my ($self) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | 47 | my $frame = pop @{ $self->[W_STACK] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 47 | ▶ | if ($frame->[F_GRID_OK]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | 10 | ▶ | if ($self->_try_grid($frame)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | 0 | $self->_mark_no_grid ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | 10 | $self->_mark_no_grid ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | 10 | $frame->join_lines($self->[W_CFG]) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | 10 | $frame->[F_FOLD_OK] = $frame->check_fold_limits($self->[W_CFG]) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | 47 | ▶ | if ($frame->[F_FOLD_OK]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | 35 | ▶ | if ($self->_try_fold($frame)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 32 | ▶ | if (@{ $self->[W_STACK] } && $frame->[F_LINES][0][L_CAN_GRID]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$self->[4];} and $frame->[3][0][11]
MC/DC100%2/2
@{$self->[4];} and $frame->[3][0][11]
@{$self->[4];}
$frame->[3][0][11]
Truth table100%3/3
A and B
A= @{$self->[4];}B= $frame->[3][0][11]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | 18 | my $parent = $self->[W_STACK][-1] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | 18 | ▶ | $parent->[F_GRID_OK] = 1 if $parent->[F_CONTENT_LINES] == 0 ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | 47 | $self->_emit_lines($frame->[F_LINES]) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | 47 | return ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | 35 | ▶ | sub _try_fold { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_try_fold: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | 35 | my ($self, $frame) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | return 0 if !$frame->[F_FOLD_OK] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | || $frame->[F_CONTENT_LINES] != 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | 35 | ▶ | || @{ $frame->[F_LINES] } != 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
not $frame->[13] or $frame->[10] != 1 or @{$frame->[3];} != 3 or $frame->[1] + $frame->[4] > $self->[2][1]
not $frame->[13] or $frame->[10] != 1 or @{$frame->[3];} != 3
not $frame->[13] or $frame->[10] != 1
MC/DC25%1/4
not $frame->[13] or $frame->[10] != 1 or @{$frame->[3];} != 3 or $frame->[1] + $frame->[4] > $self->[2][1]
not $frame->[13]
$frame->[10] != 1
@{$frame->[3];} != 3
$frame->[1] + $frame->[4] > $self->[2][1]
Truth table40%2/5
not(A) or B or C or D
A= not $frame->[13]B= $frame->[10] != 1C= @{$frame->[3];} != 3D= $frame->[1] + $frame->[4] > $self->[2][1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | || $frame->[F_INDENT] + $frame->[F_PARTS_LENGTH] > $self->[W_CFG][C_WIDTH] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | 32 | $frame->fold_lines($self->[W_CFG]) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 32 | return 1 ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | 19 | ▶ | sub _stream_frame { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stream_frame: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | 19 | my ($self, $frame) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | 19 | my $lines = $frame->[F_LINES]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | 19 | ▶ | return unless @$lines ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | 19 | my $last = $lines->[-1] ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1271 | 19 | ▶ | my $keep_last = $last->[L_CAN_PACK] || $last->[L_CAN_JOIN] ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$last->[10] || $last->[9]
MC/DC50%1/2
$last->[10] || $last->[9]
$last->[10]
$last->[9]
Truth table66%2/3
A || B
A= $last->[10]B= $last->[9]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1272 | 19 | ▶ | pop @$lines if $keep_last ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1273 | 19 | ▶ | if ( @$lines ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1274 | 15 | $self->_emit_lines($lines, $frame->[F_DEPTH] - 1) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1275 | 15 | @$lines = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1277 | 19 | ▶ | push @$lines, $last if $keep_last ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1278 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1279 | 19 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1281 | 8 | ▶ | sub _mark_no_fold { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mark_no_fold: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1282 | 8 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1283 | 8 | $_->[F_FOLD_OK] = 0 for @{ $self->[W_STACK] }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1286 | 10 | ▶ | sub _mark_no_grid { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_mark_no_grid: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1287 | 10 | my ($self) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1288 | 10 | $_->[F_GRID_OK] = 0 for @{ $self->[W_STACK] } ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1289 | 10 | return ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1292 | 60 | ▶ | sub _write_line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_line: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1293 | 60 | my ($self, $line) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1294 | 60 | $self->[W_STATS]{lines_out} ++ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1295 | 60 | return $self->_write_str($line->raw) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1298 | 61 | ▶ | sub _write_str { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_str: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1299 | 61 | my ($self, $s) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1301 | 61 | $self->[W_FH]->print($s) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1302 | 61 | $self->[W_STATS]{bytes_out} += length($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1303 | 61 | return length($s); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1306 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1307 | 235 | ▶ | sub _choose_limit { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_choose_limit: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1308 | 235 | my ($kind, $list, $dict) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1309 | 235 | ▶ | return $kind == JSON::JSONFold::Kind::KIND_LIST() ? $list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1310 | : $kind == JSON::JSONFold::Kind::KIND_DICT() ? $dict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1311 | : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1314 | 47 | ▶ | sub _pack_limit { _choose_limit($_[1], $_[0][W_CFG][C_PACK_ARRAY_ITEMS], $_[0][W_CFG][C_PACK_OBJ_ITEMS]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_pack_limit: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1315 | 47 | ▶ | sub _fold_limit { _choose_limit($_[1], $_[0][W_CFG][C_FOLD_ARRAY_ITEMS], $_[0][W_CFG][C_FOLD_OBJ_ITEMS]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fold_limit: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1316 | 47 | ▶ | sub _join_limit { _choose_limit($_[1], $_[0][W_CFG][C_JOIN_ARRAY_ITEMS], $_[0][W_CFG][C_JOIN_OBJ_ITEMS]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_join_limit: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1317 | 47 | ▶ | sub _grid_limit { _choose_limit($_[1], $_[0][W_CFG][C_GRID_ARRAY_ITEMS], $_[0][W_CFG][C_GRID_OBJ_ITEMS]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_grid_limit: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1318 | 47 | ▶ | sub _grid_min_items { _choose_limit($_[1], $_[0][W_CFG][C_GRID_ARRAY_MIN], $_[0][W_CFG][C_GRID_OBJ_MIN]) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_grid_min_items: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1319 | 1 | ▶ | sub _count_newlines { return ($_[0] =~ tr/\n//) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_count_newlines: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1321 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1322 | # CLI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1323 | # ------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1325 | package JSON::JSONFold::CLI ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1327 | 5 | ▶ | use strict ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1328 | 5 | ▶ | use warnings ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1329 | 5 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1331 | 5 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1332 | demo_data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1333 | run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1334 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1336 | 0 | ▶ | sub setup { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1337 | 0 | require Carp ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1339 | 0 | ▶ | $SIG{__DIE__} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1340 | 0 | ▶ | return if $^S; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1341 | 0 | local $SIG{__DIE__}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1342 | 0 | Carp::confess(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1343 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1345 | 0 | ▶ | $SIG{__WARN__} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1346 | 0 | local $SIG{__WARN__}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1347 | 0 | Carp::cluck(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1348 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1350 | 0 | require Getopt::Long ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1351 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1354 | 0 | ▶ | sub demo_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
demo_data: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1355 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1356 | meta => { version => 1, ok => JSON::PP::true, name => "jsonfold demo" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1357 | ids => [ 1, 2, 3, 4, 5, 6 ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1358 | items => [ { id => 1, name => "alpha" }, { id => 2, name => "beta" }, ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1359 | matrix => [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1360 | long => [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1361 | "this is a long message that may force the block to stay expanded", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1362 | "second", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1363 | "third", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1364 | "fourth", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1365 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1366 | "single-array" => [1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1367 | "single-obj" => { x => 2 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1368 | 0 | long_array => [ map { "a$_" } 1..50 ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1369 | 0 | wide_array => [ map { "abcdefghijklmnopqrstuvwxyz$_" } 1 .. 9 ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1370 | 0 | wide_object => { map { ; "abcdefghijk$_" => "lmnopqrstuvwxyz$_" } 1 .. 9 }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1372 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1375 | 0 | ▶ | sub parse_options { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_options: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1376 | 0 | my %opt = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1377 | compact => 'default', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1378 | indent => 2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1379 | sort_keys => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1380 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1381 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1382 | Getopt::Long::GetOptions( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1383 | 'demo' => \$opt{demo}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1384 | 'verbose|v' => \$opt{verbose}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1385 | 'help|h' => \$opt{help}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1386 | 'input|i=s' => \$opt{input}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1387 | 'compact=s' => \$opt{compact}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1388 | 'indent=i' => \$opt{indent}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1389 | 'sort-keys!' => \$opt{sort_keys}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1390 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1391 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1392 | 0 | return \%opt ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1395 | 0 | ▶ | sub usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1396 | 0 | my $out = shift ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1397 | 0 | $out->print(<<___ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1398 | Usage: json-jsonfold [options] < input.json | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1399 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1400 | --demo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1401 | --compact=default|classic|none|low|med|high|max|grid|pack|fold|join|off | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1402 | --width=N | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1403 | --indent=N | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1404 | --sort-keys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1405 | --input=FILE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1406 | ___ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1407 | ) ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1409 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1410 | 0 | ▶ | sub read_input { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_input: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1411 | 0 | my ($input) = @_ ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1413 | 0 | my $json_text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1414 | 0 | ▶ | if (defined $input) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1415 | 0 | ▶ | open my $fh, '<', $input or die "$input: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1416 | 0 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1417 | 0 | $json_text = <$fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1418 | 0 | ▶ | close $fh or die "$input: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1419 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1420 | 0 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1421 | 0 | $json_text = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1424 | 0 | return JSON::PP->new->allow_nonref->decode($json_text); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1427 | 0 | ▶ | sub show_verbose { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_verbose: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1428 | 0 | require Data::Dumper ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1430 | 0 | my ($label) = shift ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1431 | 0 | my $dumper = new Data::Dumper([])->Terse(1)->Indent(1)->Sortkeys(1)->Pair('=')->Quotekeys(0) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1433 | 0 | my $s = $dumper->Values( \@_)->Dump ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1434 | 0 | $s =~ s/\s+/ /gsm ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1436 | 0 | print STDERR "$label: $s\n" ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1440 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1441 | 0 | setup() ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1442 | 0 | my $opt = parse_options(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1444 | 0 | ▶ | if ($opt->{help}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1445 | 0 | usage(\*STDOUT); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1446 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1449 | 0 | binmode STDOUT, ':encoding(UTF-8)' ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1450 | 0 | ▶ | my $data = $opt->{demo} ? demo_data() : read_input($opt->{input}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1451 | 0 | my %cfg ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1452 | 0 | my $config = JSON::JSONFold::config($opt->{compact}, $opt->{width}, %cfg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1453 | 0 | my $verbose = $opt->{verbose} ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1455 | 0 | ▶ | print STDERR "Backend: ", $JSON::JSONFold::BACKEND || "-", "\n" if $verbose ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$JSON::JSONFold::BACKEND || '-'
MC/DC0%0/1
$JSON::JSONFold::BACKEND || '-'
$JSON::JSONFold::BACKEND
Truth table0%0/2
A
A= $JSON::JSONFold::BACKEND
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1456 | 0 | ▶ | show_verbose("config", { $config->as_hash } ) if $verbose ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1458 | 0 | my $info = JSON::JSONFold::write_json($data, \*STDOUT, $opt->{width}, $config, sort_keys => $opt->{sort_keys}, indent => $opt->{indent} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1460 | 0 | ▶ | show_verbose("stats", { % $info }) if $verbose ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1461 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1463 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1464 | 5 | ▶ | run() unless caller() ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1466 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1468 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||