| 1 | # ABSTRACT: YAML 1.2 Processor | ||||||||||||||||||||||||||||||||
| 2 | 48 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 48 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | package YAML::PP; | ||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 48 | our $VERSION = 'v0.43.0'; # VERSION | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 48 | ▶ | use YAML::PP::Schema; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 48 | ▶ | use YAML::PP::Schema::JSON; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 48 | ▶ | use YAML::PP::Loader; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 48 | ▶ | use YAML::PP::Dumper; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 48 | ▶ | use Scalar::Util qw/ blessed /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 48 | ▶ | use Carp qw/ croak /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 48 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 48 | our @EXPORT_OK = qw/ Load LoadFile Dump DumpFile /; | |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 48 | my %YAML_VERSIONS = ('1.1' => 1, '1.2' => 1); | |||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 767 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 22 | 767 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 767 | my $bool = delete $args{boolean}; | |||||||||||||||||||||||||||||||
| 25 | 767 | ▶ | $bool = 'perl' unless defined $bool; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 26 | 767 | ▶ | my $schemas = delete $args{schema} || ['+']; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{'schema'} || ['+']
MC/DC100%1/1
delete $args{'schema'} || ['+']
delete $args{'schema'}
Truth table100%2/2
A
A= delete $args{'schema'}
| |||||||||||||||||||||||||||||||||
| 27 | 767 | ▶ | my $cyclic_refs = delete $args{cyclic_refs} || 'fatal'; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $args{'cyclic_refs'} || 'fatal'
MC/DC100%1/1
delete $args{'cyclic_refs'} || 'fatal'
delete $args{'cyclic_refs'}
Truth table100%2/2
A
A= delete $args{'cyclic_refs'}
| |||||||||||||||||||||||||||||||||
| 28 | 767 | my $indent = delete $args{indent}; | |||||||||||||||||||||||||||||||
| 29 | 767 | my $width = delete $args{width}; | |||||||||||||||||||||||||||||||
| 30 | 767 | my $writer = delete $args{writer}; | |||||||||||||||||||||||||||||||
| 31 | 767 | my $header = delete $args{header}; | |||||||||||||||||||||||||||||||
| 32 | 767 | my $footer = delete $args{footer}; | |||||||||||||||||||||||||||||||
| 33 | 767 | my $require_footer = delete $args{require_footer}; | |||||||||||||||||||||||||||||||
| 34 | 767 | my $duplicate_keys = delete $args{duplicate_keys}; | |||||||||||||||||||||||||||||||
| 35 | 767 | my $max_depth = delete $args{max_depth}; | |||||||||||||||||||||||||||||||
| 36 | 767 | my $yaml_version = $class->_arg_yaml_version(delete $args{yaml_version}); | |||||||||||||||||||||||||||||||
| 37 | 767 | my $default_yaml_version = $yaml_version->[0]; | |||||||||||||||||||||||||||||||
| 38 | 767 | my $version_directive = delete $args{version_directive}; | |||||||||||||||||||||||||||||||
| 39 | 767 | my $preserve = delete $args{preserve}; | |||||||||||||||||||||||||||||||
| 40 | 767 | my $parser = delete $args{parser}; | |||||||||||||||||||||||||||||||
| 41 | my $emitter = delete $args{emitter} || { | ||||||||||||||||||||||||||||||||
| 42 | 767 | ▶ | indent => $indent, | ||||||||||||||||||||||||||||||
|
Condition50%1/2
delete $args{'emitter'} || {'indent', $indent, 'width', $width, 'writer', $writer}
MC/DC0%0/1
delete $args{'emitter'} || {'indent', $indent, 'width', $width, 'writer', $writer}
delete $args{'emitter'}
Truth table50%1/2
A
A= delete $args{'emitter'}
| |||||||||||||||||||||||||||||||||
| 43 | width => $width, | ||||||||||||||||||||||||||||||||
| 44 | writer => $writer, | ||||||||||||||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||||||||||||||
| 46 | 767 | ▶ | if (keys %args) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 47 | 0 | die "Unexpected arguments: " . join ', ', sort keys %args; | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 767 | my %schemas; | |||||||||||||||||||||||||||||||
| 51 | 767 | for my $v (@$yaml_version) { | |||||||||||||||||||||||||||||||
| 52 | 769 | my $schema; | |||||||||||||||||||||||||||||||
| 53 | 769 | ▶ | if (blessed($schemas) and $schemas->isa('YAML::PP::Schema')) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($schemas) and $schemas->isa("YAML::PP::Schema")
MC/DC0%0/2
builtin::blessed($schemas) and $schemas->isa("YAML::PP::Schema")
builtin::blessed($schemas)
$schemas->isa("YAML::PP::Schema")
Truth table33%1/3
A and B
A= builtin::blessed($schemas)B= $schemas->isa("YAML::PP::Schema")
| |||||||||||||||||||||||||||||||||
| 54 | 0 | $schema = $schemas; | |||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||||||
| 57 | 769 | $schema = YAML::PP::Schema->new( | |||||||||||||||||||||||||||||||
| 58 | boolean => $bool, | ||||||||||||||||||||||||||||||||
| 59 | yaml_version => $v, | ||||||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||||||
| 61 | 769 | $schema->load_subschemas(@$schemas); | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | 766 | $schemas{ $v } = $schema; | |||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | 764 | my $default_schema = $schemas{ $default_yaml_version }; | |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | 764 | my $loader = YAML::PP::Loader->new( | |||||||||||||||||||||||||||||||
| 68 | schemas => \%schemas, | ||||||||||||||||||||||||||||||||
| 69 | cyclic_refs => $cyclic_refs, | ||||||||||||||||||||||||||||||||
| 70 | parser => $parser, | ||||||||||||||||||||||||||||||||
| 71 | default_yaml_version => $default_yaml_version, | ||||||||||||||||||||||||||||||||
| 72 | preserve => $preserve, | ||||||||||||||||||||||||||||||||
| 73 | duplicate_keys => $duplicate_keys, | ||||||||||||||||||||||||||||||||
| 74 | require_footer => $require_footer, | ||||||||||||||||||||||||||||||||
| 75 | max_depth => $max_depth, | ||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||
| 77 | 763 | my $dumper = YAML::PP::Dumper->new( | |||||||||||||||||||||||||||||||
| 78 | schema => $default_schema, | ||||||||||||||||||||||||||||||||
| 79 | emitter => $emitter, | ||||||||||||||||||||||||||||||||
| 80 | header => $header, | ||||||||||||||||||||||||||||||||
| 81 | footer => $footer, | ||||||||||||||||||||||||||||||||
| 82 | version_directive => $version_directive, | ||||||||||||||||||||||||||||||||
| 83 | preserve => $preserve, | ||||||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 763 | my $self = bless { | |||||||||||||||||||||||||||||||
| 87 | schema => \%schemas, | ||||||||||||||||||||||||||||||||
| 88 | loader => $loader, | ||||||||||||||||||||||||||||||||
| 89 | dumper => $dumper, | ||||||||||||||||||||||||||||||||
| 90 | }, $class; | ||||||||||||||||||||||||||||||||
| 91 | 763 | return $self; | |||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 9 | ▶ | sub clone { | ||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 95 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 96 | 9 | my $clone = { | |||||||||||||||||||||||||||||||
| 97 | schema => $self->schema, | ||||||||||||||||||||||||||||||||
| 98 | loader => $self->loader->clone, | ||||||||||||||||||||||||||||||||
| 99 | dumper => $self->dumper->clone, | ||||||||||||||||||||||||||||||||
| 100 | }; | ||||||||||||||||||||||||||||||||
| 101 | 9 | return bless $clone, ref $self; | |||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | 767 | ▶ | sub _arg_yaml_version { | ||||||||||||||||||||||||||||||
|
Subroutine
_arg_yaml_version: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||
| 105 | 767 | my ($class, $version) = @_; | |||||||||||||||||||||||||||||||
| 106 | 767 | my @versions = ('1.2'); | |||||||||||||||||||||||||||||||
| 107 | 767 | ▶ | if (defined $version) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 108 | 5 | @versions = (); | |||||||||||||||||||||||||||||||
| 109 | 5 | ▶ | if (not ref $version) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 110 | 1 | $version = [$version]; | |||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||
| 112 | 5 | for my $v (@$version) { | |||||||||||||||||||||||||||||||
| 113 | 7 | ▶ | unless ($YAML_VERSIONS{ $v }) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 114 | 0 | croak "YAML Version '$v' not supported"; | |||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | 7 | push @versions, $v; | |||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||
| 119 | 767 | return \@versions; | |||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | 2221 | ▶ | sub loader { | ||||||||||||||||||||||||||||||
|
Subroutine
loader: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 124 | 2221 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 125 | 0 | $_[0]->{loader} = $_[1] | |||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||
| 127 | 2221 | return $_[0]->{loader}; | |||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||
| 130 | 1494 | ▶ | sub dumper { | ||||||||||||||||||||||||||||||
|
Subroutine
dumper: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 131 | 1494 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 132 | 0 | $_[0]->{dumper} = $_[1] | |||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||
| 134 | 1494 | return $_[0]->{dumper}; | |||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | 16 | ▶ | sub schema { | ||||||||||||||||||||||||||||||
|
Subroutine
schema: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if (@_ > 1) { $_[0]->{schema}->{'1.2'} = $_[1] } | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 139 | 16 | return $_[0]->{schema}->{'1.2'}; | |||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||
| 142 | 3 | ▶ | sub default_schema { | ||||||||||||||||||||||||||||||
|
Subroutine
default_schema: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 143 | 3 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 144 | my $schema = YAML::PP::Schema->new( | ||||||||||||||||||||||||||||||||
| 145 | boolean => $args{boolean}, | ||||||||||||||||||||||||||||||||
| 146 | 3 | ); | |||||||||||||||||||||||||||||||
| 147 | 3 | $schema->load_subschemas(qw/ Core /); | |||||||||||||||||||||||||||||||
| 148 | 3 | return $schema; | |||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||
| 151 | 2181 | ▶ | sub load_string { | ||||||||||||||||||||||||||||||
|
Subroutine
load_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 152 | 2181 | my ($self, $yaml) = @_; | |||||||||||||||||||||||||||||||
| 153 | 2181 | return $self->loader->load_string($yaml); | |||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | 28 | ▶ | sub load_file { | ||||||||||||||||||||||||||||||
|
Subroutine
load_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 157 | 28 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||
| 158 | 28 | return $self->loader->load_file($file); | |||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||
| 161 | 1 | ▶ | sub dump { | ||||||||||||||||||||||||||||||
|
Subroutine
dump: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 162 | 1 | my ($self, @data) = @_; | |||||||||||||||||||||||||||||||
| 163 | 1 | return $self->dumper->dump(@data); | |||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | 1478 | ▶ | sub dump_string { | ||||||||||||||||||||||||||||||
|
Subroutine
dump_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 167 | 1478 | my ($self, @data) = @_; | |||||||||||||||||||||||||||||||
| 168 | 1478 | return $self->dumper->dump_string(@data); | |||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | 6 | ▶ | sub dump_file { | ||||||||||||||||||||||||||||||
|
Subroutine
dump_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 172 | 6 | my ($self, $file, @data) = @_; | |||||||||||||||||||||||||||||||
| 173 | 6 | return $self->dumper->dump_file($file, @data); | |||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | # legagy interface | ||||||||||||||||||||||||||||||||
| 177 | 2 | ▶ | sub Load { | ||||||||||||||||||||||||||||||
|
Subroutine
Load: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 178 | 2 | my ($yaml) = @_; | |||||||||||||||||||||||||||||||
| 179 | 2 | YAML::PP->new->load_string($yaml); | |||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | 12 | ▶ | sub LoadFile { | ||||||||||||||||||||||||||||||
|
Subroutine
LoadFile: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 183 | 12 | my ($file) = @_; | |||||||||||||||||||||||||||||||
| 184 | 12 | YAML::PP->new->load_file($file); | |||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | sub Dump { | ||||||||||||||||||||||||||||||
|
Subroutine
Dump: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 188 | 1 | my (@data) = @_; | |||||||||||||||||||||||||||||||
| 189 | 1 | YAML::PP->new->dump_string(@data); | |||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | 4 | ▶ | sub DumpFile { | ||||||||||||||||||||||||||||||
|
Subroutine
DumpFile: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 193 | 4 | my ($file, @data) = @_; | |||||||||||||||||||||||||||||||
| 194 | 4 | YAML::PP->new->dump_file($file, @data); | |||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||
| 197 | 4 | ▶ | sub preserved_scalar { | ||||||||||||||||||||||||||||||
|
Subroutine
preserved_scalar: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 198 | 4 | my ($self, $value, %args) = @_; | |||||||||||||||||||||||||||||||
| 199 | 4 | my $scalar = YAML::PP::Preserve::Scalar->new( | |||||||||||||||||||||||||||||||
| 200 | value => $value, | ||||||||||||||||||||||||||||||||
| 201 | %args, | ||||||||||||||||||||||||||||||||
| 202 | ); | ||||||||||||||||||||||||||||||||
| 203 | 4 | return $scalar; | |||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | 4 | ▶ | sub preserved_mapping { | ||||||||||||||||||||||||||||||
|
Subroutine
preserved_mapping: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 207 | 4 | my ($self, $hash, %args) = @_; | |||||||||||||||||||||||||||||||
| 208 | 4 | my $data = {}; | |||||||||||||||||||||||||||||||
| 209 | 4 | tie %$data, 'YAML::PP::Preserve::Hash'; | |||||||||||||||||||||||||||||||
| 210 | 4 | %$data = %$hash; | |||||||||||||||||||||||||||||||
| 211 | 4 | my $t = tied %$data; | |||||||||||||||||||||||||||||||
| 212 | 4 | $t->{style} = $args{style}; | |||||||||||||||||||||||||||||||
| 213 | 4 | $t->{alias} = $args{alias}; | |||||||||||||||||||||||||||||||
| 214 | 4 | return $data; | |||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||
| 217 | 4 | ▶ | sub preserved_sequence { | ||||||||||||||||||||||||||||||
|
Subroutine
preserved_sequence: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 218 | 4 | my ($self, $array, %args) = @_; | |||||||||||||||||||||||||||||||
| 219 | 4 | my $data = []; | |||||||||||||||||||||||||||||||
| 220 | 4 | tie @$data, 'YAML::PP::Preserve::Array'; | |||||||||||||||||||||||||||||||
| 221 | 4 | push @$data, @$array; | |||||||||||||||||||||||||||||||
| 222 | 4 | my $t = tied @$data; | |||||||||||||||||||||||||||||||
| 223 | 4 | $t->{style} = $args{style}; | |||||||||||||||||||||||||||||||
| 224 | 4 | $t->{alias} = $args{alias}; | |||||||||||||||||||||||||||||||
| 225 | 4 | return $data; | |||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||
| 228 | package YAML::PP::Preserve::Hash; | ||||||||||||||||||||||||||||||||
| 229 | # experimental | ||||||||||||||||||||||||||||||||
| 230 | 48 | ▶ | use Tie::Hash; # provides Tie::StdHash, our parent below | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 231 | 48 | our @ISA = qw/ Tie::StdHash /; | |||||||||||||||||||||||||||||||
| 232 | 48 | ▶ | use Scalar::Util qw/ reftype blessed /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||
| 234 | 34 | ▶ | sub TIEHASH { | ||||||||||||||||||||||||||||||
|
Subroutine
TIEHASH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 235 | 34 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||
| 236 | 34 | my $self = bless { | |||||||||||||||||||||||||||||||
| 237 | keys => [keys %args], | ||||||||||||||||||||||||||||||||
| 238 | data => { %args }, | ||||||||||||||||||||||||||||||||
| 239 | }, $class; | ||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||
| 242 | 127 | ▶ | sub STORE { | ||||||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||
| 243 | 127 | my ($self, $key, $val) = @_; | |||||||||||||||||||||||||||||||
| 244 | 127 | my $keys = $self->{keys}; | |||||||||||||||||||||||||||||||
| 245 | 127 | ▶ | unless (exists $self->{data}->{ $key }) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 246 | 120 | push @$keys, $key; | |||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||
| 248 | 127 | ▶ | if (ref $val and not blessed($val)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $val and not builtin::blessed($val)
MC/DC100%2/2
ref $val and not builtin::blessed($val)
ref $val
not builtin::blessed($val)
Truth table100%3/3
A and not(B)
A= ref $valB= not builtin::blessed($val)
| |||||||||||||||||||||||||||||||||
| 249 | 39 | ▶ | if (reftype($val) eq 'HASH' and not tied %$val) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
builtin::reftype($val) eq "HASH" and not tied %$val
MC/DC100%2/2
builtin::reftype($val) eq "HASH" and not tied %$val
builtin::reftype($val) eq "HASH"
not tied %$val
Truth table100%3/3
A and not(B)
A= builtin::reftype($val) eq "HASH"B= not tied %$val
| |||||||||||||||||||||||||||||||||
| 250 | 1 | tie %$val, 'YAML::PP::Preserve::Hash', %$val; | |||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||
| 252 | ▶ | elsif (reftype($val) eq 'ARRAY' and not tied @$val) { | |||||||||||||||||||||||||||||||
|
Condition100%3/3
builtin::reftype($val) eq "ARRAY" and not tied @$val
MC/DC100%2/2
builtin::reftype($val) eq "ARRAY" and not tied @$val
builtin::reftype($val) eq "ARRAY"
not tied @$val
Truth table100%3/3
A and not(B)
A= builtin::reftype($val) eq "ARRAY"B= not tied @$val
| |||||||||||||||||||||||||||||||||
| 253 | 2 | tie @$val, 'YAML::PP::Preserve::Array', @$val; | |||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||
| 256 | 127 | $self->{data}->{ $key } = $val; | |||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | 91 | ▶ | sub FIRSTKEY { | ||||||||||||||||||||||||||||||
|
Subroutine
FIRSTKEY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 260 | 91 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 261 | 91 | return $self->{keys}->[0]; | |||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||
| 264 | 320 | ▶ | sub NEXTKEY { | ||||||||||||||||||||||||||||||
|
Subroutine
NEXTKEY: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||
| 265 | 320 | my ($self, $last) = @_; | |||||||||||||||||||||||||||||||
| 266 | 320 | my $keys = $self->{keys}; | |||||||||||||||||||||||||||||||
| 267 | 320 | for my $i (0 .. $#$keys) { | |||||||||||||||||||||||||||||||
| 268 | 1167 | ▶ | if ("$keys->[ $i ]" eq "$last") { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 269 | 320 | return $keys->[ $i + 1 ]; | |||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||
| 272 | 0 | return; | |||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||
| 275 | 305 | ▶ | sub FETCH { | ||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 276 | 305 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||
| 277 | 305 | my $val = $self->{data}->{ $key }; | |||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||
| 280 | 2 | ▶ | sub DELETE { | ||||||||||||||||||||||||||||||
|
Subroutine
DELETE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 281 | 2 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||
| 282 | 2 | @{ $self->{keys} } = grep { "$_" ne "$key" } @{ $self->{keys} }; | |||||||||||||||||||||||||||||||
| 283 | 2 | delete $self->{data}->{ $key }; | |||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||
| 286 | 34 | ▶ | sub EXISTS { | ||||||||||||||||||||||||||||||
|
Subroutine
EXISTS: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 287 | 34 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||
| 288 | 34 | return exists $self->{data}->{ $key }; | |||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||
| 291 | 9 | ▶ | sub CLEAR { | ||||||||||||||||||||||||||||||
|
Subroutine
CLEAR: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 292 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 293 | 9 | $self->{keys} = []; | |||||||||||||||||||||||||||||||
| 294 | 9 | $self->{data} = {}; | |||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||
| 297 | 3 | ▶ | sub SCALAR { | ||||||||||||||||||||||||||||||
|
Subroutine
SCALAR: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 298 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 299 | 3 | return scalar %{ $self->{data} }; | |||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||
| 302 | package YAML::PP::Preserve::Array; | ||||||||||||||||||||||||||||||||
| 303 | # experimental | ||||||||||||||||||||||||||||||||
| 304 | 48 | ▶ | use Tie::Array; # provides Tie::StdArray, our parent below | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 305 | 48 | our @ISA = qw/ Tie::StdArray /; | |||||||||||||||||||||||||||||||
| 306 | 48 | ▶ | use Scalar::Util qw/ reftype blessed /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | 16 | ▶ | sub TIEARRAY { | ||||||||||||||||||||||||||||||
|
Subroutine
TIEARRAY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 309 | 16 | my ($class, @items) = @_; | |||||||||||||||||||||||||||||||
| 310 | 16 | my $self = bless { | |||||||||||||||||||||||||||||||
| 311 | data => [@items], | ||||||||||||||||||||||||||||||||
| 312 | }, $class; | ||||||||||||||||||||||||||||||||
| 313 | 16 | return $self; | |||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||
| 316 | 99 | ▶ | sub FETCH { | ||||||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 317 | 99 | my ($self, $i) = @_; | |||||||||||||||||||||||||||||||
| 318 | 99 | return $self->{data}->[ $i ]; | |||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||
| 320 | 101 | ▶ | sub FETCHSIZE { | ||||||||||||||||||||||||||||||
|
Subroutine
FETCHSIZE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 321 | 101 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 322 | 101 | return $#{ $self->{data} } + 1; | |||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||
| 325 | 42 | ▶ | sub _preserve { | ||||||||||||||||||||||||||||||
|
Subroutine
_preserve: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||
| 326 | 42 | my ($val) = @_; | |||||||||||||||||||||||||||||||
| 327 | 42 | ▶ | if (ref $val and not blessed($val)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $val and not builtin::blessed($val)
MC/DC100%2/2
ref $val and not builtin::blessed($val)
ref $val
not builtin::blessed($val)
Truth table100%3/3
A and not(B)
A= ref $valB= not builtin::blessed($val)
| |||||||||||||||||||||||||||||||||
| 328 | 13 | ▶ | if (reftype($val) eq 'HASH' and not tied %$val) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
builtin::reftype($val) eq "HASH" and not tied %$val
MC/DC100%2/2
builtin::reftype($val) eq "HASH" and not tied %$val
builtin::reftype($val) eq "HASH"
not tied %$val
Truth table100%3/3
A and not(B)
A= builtin::reftype($val) eq "HASH"B= not tied %$val
| |||||||||||||||||||||||||||||||||
| 329 | 5 | tie %$val, 'YAML::PP::Preserve::Hash', %$val; | |||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||
| 331 | ▶ | elsif (reftype($val) eq 'ARRAY' and not tied @$val) { | |||||||||||||||||||||||||||||||
|
Condition100%3/3
builtin::reftype($val) eq "ARRAY" and not tied @$val
MC/DC100%2/2
builtin::reftype($val) eq "ARRAY" and not tied @$val
builtin::reftype($val) eq "ARRAY"
not tied @$val
Truth table100%3/3
A and not(B)
A= builtin::reftype($val) eq "ARRAY"B= not tied @$val
| |||||||||||||||||||||||||||||||||
| 332 | 1 | tie @$val, 'YAML::PP::Preserve::Array', @$val; | |||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||
| 335 | 42 | return $val; | |||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||
| 338 | 6 | ▶ | sub STORE { | ||||||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 339 | 6 | my ($self, $i, $val) = @_; | |||||||||||||||||||||||||||||||
| 340 | 6 | _preserve($val); | |||||||||||||||||||||||||||||||
| 341 | 6 | $self->{data}->[ $i ] = $val; | |||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||
| 343 | 14 | ▶ | sub PUSH { | ||||||||||||||||||||||||||||||
|
Subroutine
PUSH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 344 | 14 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||
| 345 | 14 | push @{ $self->{data} }, map { _preserve $_ } @args; | |||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||
| 347 | 1 | ▶ | sub STORESIZE { | ||||||||||||||||||||||||||||||
|
Subroutine
STORESIZE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 348 | 1 | my ($self, $i) = @_; | |||||||||||||||||||||||||||||||
| 349 | 1 | $#{ $self->{data} } = $i - 1; | |||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||
| 351 | 1 | ▶ | sub DELETE { | ||||||||||||||||||||||||||||||
|
Subroutine
DELETE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 352 | 1 | my ($self, $i) = @_; | |||||||||||||||||||||||||||||||
| 353 | 1 | delete $self->{data}->[ $i ]; | |||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||
| 355 | 2 | ▶ | sub EXISTS { | ||||||||||||||||||||||||||||||
|
Subroutine
EXISTS: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 356 | 2 | my ($self, $i) = @_; | |||||||||||||||||||||||||||||||
| 357 | 2 | return exists $self->{data}->[ $i ]; | |||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||
| 359 | 1 | ▶ | sub CLEAR { | ||||||||||||||||||||||||||||||
|
Subroutine
CLEAR: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 360 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 361 | 1 | $self->{data} = []; | |||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||
| 363 | 1 | ▶ | sub SHIFT { | ||||||||||||||||||||||||||||||
|
Subroutine
SHIFT: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 364 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 365 | 1 | shift @{ $self->{data} }; | |||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||
| 367 | 2 | ▶ | sub UNSHIFT { | ||||||||||||||||||||||||||||||
|
Subroutine
UNSHIFT: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 368 | 2 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||
| 369 | 2 | unshift @{ $self->{data} }, map { _preserve $_ } @args; | |||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||
| 371 | 2 | ▶ | sub SPLICE { | ||||||||||||||||||||||||||||||
|
Subroutine
SPLICE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 372 | 2 | my ($self, $offset, $length, @args) = @_; | |||||||||||||||||||||||||||||||
| 373 | 2 | splice @{ $self->{data} }, $offset, $length, map { _preserve $_ } @args; | |||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||
| 375 | 1 | ▶ | sub EXTEND {} | ||||||||||||||||||||||||||||||
|
Subroutine
EXTEND: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||
| 378 | package YAML::PP::Preserve::Scalar; | ||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||
| 380 | use overload | ||||||||||||||||||||||||||||||||
| 381 | 48 | ▶ | fallback => 1, | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 382 | '+' => \&value, | ||||||||||||||||||||||||||||||||
| 383 | '""' => \&value, | ||||||||||||||||||||||||||||||||
| 384 | 'bool' => \&value, | ||||||||||||||||||||||||||||||||
| 385 | 48 | ; | |||||||||||||||||||||||||||||||
| 386 | 87 | ▶ | sub new { | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 387 | 87 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||
| 388 | 87 | my $self = { | |||||||||||||||||||||||||||||||
| 389 | %args, | ||||||||||||||||||||||||||||||||
| 390 | }; | ||||||||||||||||||||||||||||||||
| 391 | 87 | bless $self, $class; | |||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||
| 393 | 2218 | ▶ | sub value { $_[0]->{value} } | ||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | sub tag { $_[0]->{tag} } | ||||||||||||||||||||||||||||||
|
Subroutine
tag: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 395 | 21 | ▶ | sub style { $_[0]->{style} || 0 } | ||||||||||||||||||||||||||||||
|
Subroutine
style: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 396 | 17 | ▶ | sub alias { $_[0]->{alias} } | ||||||||||||||||||||||||||||||
|
Subroutine
alias: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||
| 398 | 48 | 1; | |||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||
| 400 | __END__ | ||||||||||||||||||||||||||||||||