| 1 | 12 | ▶ | use 5.008001; # sane UTF-8 support | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 2 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | package CPAN::Meta::YAML; # git description: v1.68-2-gcc5324e | ||||||||||||||||||||||||||||||||||||||||
| 5 | # XXX-INGY is 5.8.1 too old/broken for utf8? | ||||||||||||||||||||||||||||||||||||||||
| 6 | # XXX-XDG Lancaster consensus was that it was sufficient until | ||||||||||||||||||||||||||||||||||||||||
| 7 | # proven otherwise | ||||||||||||||||||||||||||||||||||||||||
| 8 | 12 | $CPAN::Meta::YAML::VERSION = '0.018'; | |||||||||||||||||||||||||||||||||||||||
| 9 | ; # original $VERSION removed by Doppelgaenger | ||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||
| 11 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||
| 12 | # The CPAN::Meta::YAML API. | ||||||||||||||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||||||||||||||
| 14 | # These are the currently documented API functions/methods and | ||||||||||||||||||||||||||||||||||||||||
| 15 | # exports: | ||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||
| 17 | 12 | ▶ | use Exporter; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 18 | 12 | our @ISA = qw{ Exporter }; | |||||||||||||||||||||||||||||||||||||||
| 19 | 12 | our @EXPORT = qw{ Load Dump }; | |||||||||||||||||||||||||||||||||||||||
| 20 | 12 | our @EXPORT_OK = qw{ LoadFile DumpFile freeze thaw }; | |||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||
| 22 | ### | ||||||||||||||||||||||||||||||||||||||||
| 23 | # Functional/Export API: | ||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||
| 25 | sub Dump { | ||||||||||||||||||||||||||||||||||||||||
| 26 | 160 | ▶ | return CPAN::Meta::YAML->new(@_)->_dump_string; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
Dump: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||
| 29 | # XXX-INGY Returning last document seems a bad behavior. | ||||||||||||||||||||||||||||||||||||||||
| 30 | # XXX-XDG I think first would seem more natural, but I don't know | ||||||||||||||||||||||||||||||||||||||||
| 31 | # that it's worth changing now | ||||||||||||||||||||||||||||||||||||||||
| 32 | sub Load { | ||||||||||||||||||||||||||||||||||||||||
| 33 | 112 | ▶ | my $self = CPAN::Meta::YAML->_load_string(@_); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
Load: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 34 | 111 | ▶ | if ( wantarray ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 35 | 54 | return @$self; | |||||||||||||||||||||||||||||||||||||||
| 36 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 37 | # To match YAML.pm, return the last document | ||||||||||||||||||||||||||||||||||||||||
| 38 | 57 | return $self->[-1]; | |||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||
| 42 | # XXX-INGY Do we really need freeze and thaw? | ||||||||||||||||||||||||||||||||||||||||
| 43 | # XXX-XDG I don't think so. I'd support deprecating them. | ||||||||||||||||||||||||||||||||||||||||
| 44 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
| 45 | 12 | ▶ | *freeze = \&Dump; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 46 | 12 | *thaw = \&Load; | |||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||
| 49 | sub DumpFile { | ||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | my $file = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
DumpFile: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | return CPAN::Meta::YAML->new(@_)->_dump_file($file); | |||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||
| 54 | sub LoadFile { | ||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | my $file = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
LoadFile: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | my $self = CPAN::Meta::YAML->_load_file($file); | |||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | if ( wantarray ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | return @$self; | |||||||||||||||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 60 | # Return only the last document to match YAML.pm, | ||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | return $self->[-1]; | |||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||
| 66 | ### | ||||||||||||||||||||||||||||||||||||||||
| 67 | # Object Oriented API: | ||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||
| 69 | # Create an empty CPAN::Meta::YAML object | ||||||||||||||||||||||||||||||||||||||||
| 70 | # XXX-INGY Why do we use ARRAY object? | ||||||||||||||||||||||||||||||||||||||||
| 71 | # NOTE: I get it now, but I think it's confusing and not needed. | ||||||||||||||||||||||||||||||||||||||||
| 72 | # Will change it on a branch later, for review. | ||||||||||||||||||||||||||||||||||||||||
| 73 | # | ||||||||||||||||||||||||||||||||||||||||
| 74 | # XXX-XDG I don't support changing it yet. It's a very well-documented | ||||||||||||||||||||||||||||||||||||||||
| 75 | # "API" of CPAN::Meta::YAML. I'd support deprecating it, but Adam suggested | ||||||||||||||||||||||||||||||||||||||||
| 76 | # we not change it until YAML.pm's own OO API is established so that | ||||||||||||||||||||||||||||||||||||||||
| 77 | # users only have one API change to digest, not two | ||||||||||||||||||||||||||||||||||||||||
| 78 | sub new { | ||||||||||||||||||||||||||||||||||||||||
| 79 | 172 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 80 | 172 | bless [ @_ ], $class; | |||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||
| 83 | # XXX-INGY It probably doesn't matter, and it's probably too late to | ||||||||||||||||||||||||||||||||||||||||
| 84 | # change, but 'read/write' are the wrong names. Read and Write | ||||||||||||||||||||||||||||||||||||||||
| 85 | # are actions that take data from storage to memory | ||||||||||||||||||||||||||||||||||||||||
| 86 | # characters/strings. These take the data to/from storage to native | ||||||||||||||||||||||||||||||||||||||||
| 87 | # Perl objects, which the terms dump and load are meant. As long as | ||||||||||||||||||||||||||||||||||||||||
| 88 | # this is a legacy quirk to CPAN::Meta::YAML it's ok, but I'd prefer not | ||||||||||||||||||||||||||||||||||||||||
| 89 | # to add new {read,write}_* methods to this API. | ||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||
| 91 | sub read_string { | ||||||||||||||||||||||||||||||||||||||||
| 92 | 218 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 93 | 218 | $self->_load_string(@_); | |||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||
| 96 | sub write_string { | ||||||||||||||||||||||||||||||||||||||||
| 97 | 105 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 98 | 105 | $self->_dump_string(@_); | |||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||
| 101 | sub read { | ||||||||||||||||||||||||||||||||||||||||
| 102 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 103 | 14 | $self->_load_file(@_); | |||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||
| 106 | sub write { | ||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 108 | 4 | $self->_dump_file(@_); | |||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||
| 114 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||
| 115 | # Constants | ||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||
| 117 | # Printed form of the unprintable characters in the lowest range | ||||||||||||||||||||||||||||||||||||||||
| 118 | # of ASCII characters, listed by ASCII ordinal position. | ||||||||||||||||||||||||||||||||||||||||
| 119 | 12 | my @UNPRINTABLE = qw( | |||||||||||||||||||||||||||||||||||||||
| 120 | 0 x01 x02 x03 x04 x05 x06 a | ||||||||||||||||||||||||||||||||||||||||
| 121 | b t n v f r x0E x0F | ||||||||||||||||||||||||||||||||||||||||
| 122 | x10 x11 x12 x13 x14 x15 x16 x17 | ||||||||||||||||||||||||||||||||||||||||
| 123 | x18 x19 x1A e x1C x1D x1E x1F | ||||||||||||||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||
| 126 | # Printable characters for escapes | ||||||||||||||||||||||||||||||||||||||||
| 127 | 12 | my %UNESCAPES = ( | |||||||||||||||||||||||||||||||||||||||
| 128 | 0 => "\x00", z => "\x00", N => "\x85", | ||||||||||||||||||||||||||||||||||||||||
| 129 | a => "\x07", b => "\x08", t => "\x09", | ||||||||||||||||||||||||||||||||||||||||
| 130 | n => "\x0a", v => "\x0b", f => "\x0c", | ||||||||||||||||||||||||||||||||||||||||
| 131 | r => "\x0d", e => "\x1b", '\\' => '\\', | ||||||||||||||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||
| 134 | # XXX-INGY | ||||||||||||||||||||||||||||||||||||||||
| 135 | # I(ngy) need to decide if these values should be quoted in | ||||||||||||||||||||||||||||||||||||||||
| 136 | # CPAN::Meta::YAML or not. Probably yes. | ||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||
| 138 | # These 3 values have special meaning when unquoted and using the | ||||||||||||||||||||||||||||||||||||||||
| 139 | # default YAML schema. They need quotes if they are strings. | ||||||||||||||||||||||||||||||||||||||||
| 140 | 12 | my %QUOTE = map { $_ => 1 } qw{ | |||||||||||||||||||||||||||||||||||||||
| 141 | null true false | ||||||||||||||||||||||||||||||||||||||||
| 142 | }; | ||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||
| 144 | # The commented out form is simpler, but overloaded the Perl regex | ||||||||||||||||||||||||||||||||||||||||
| 145 | # engine due to recursion and backtracking problems on strings | ||||||||||||||||||||||||||||||||||||||||
| 146 | # larger than 32,000ish characters. Keep it for reference purposes. | ||||||||||||||||||||||||||||||||||||||||
| 147 | # qr/\"((?:\\.|[^\"])*)\"/ | ||||||||||||||||||||||||||||||||||||||||
| 148 | 12 | my $re_capture_double_quoted = qr/\"([^\\"]*(?:\\.[^\\"]*)*)\"/; | |||||||||||||||||||||||||||||||||||||||
| 149 | 12 | my $re_capture_single_quoted = qr/\'([^\']*(?:\'\'[^\']*)*)\'/; | |||||||||||||||||||||||||||||||||||||||
| 150 | # unquoted re gets trailing space that needs to be stripped | ||||||||||||||||||||||||||||||||||||||||
| 151 | 12 | my $re_capture_unquoted_key = qr/([^:]+(?::+\S(?:[^:]*|.*?(?=:)))*)(?=\s*\:(?:\s+|$))/; | |||||||||||||||||||||||||||||||||||||||
| 152 | 12 | my $re_trailing_comment = qr/(?:\s+\#.*)?/; | |||||||||||||||||||||||||||||||||||||||
| 153 | 12 | my $re_key_value_separator = qr/\s*:(?:\s+(?:\#.*)?|$)/; | |||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||
| 159 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||
| 160 | # CPAN::Meta::YAML Implementation. | ||||||||||||||||||||||||||||||||||||||||
| 161 | # | ||||||||||||||||||||||||||||||||||||||||
| 162 | # These are the private methods that do all the work. They may change | ||||||||||||||||||||||||||||||||||||||||
| 163 | # at any time. | ||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||
| 166 | ### | ||||||||||||||||||||||||||||||||||||||||
| 167 | # Loader functions: | ||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||
| 169 | # Create an object from a file | ||||||||||||||||||||||||||||||||||||||||
| 170 | sub _load_file { | ||||||||||||||||||||||||||||||||||||||||
| 171 | 15 | ▶ | my $class = ref $_[0] ? ref shift : shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_file: called CC=11 SCAR=24.4
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||
| 173 | # Check the file | ||||||||||||||||||||||||||||||||||||||||
| 174 | 15 | ▶ | my $file = shift or $class->_error( 'You did not specify a file name' ); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 175 | 14 | ▶ | $class->_error( "File '$file' does not exist" ) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 176 | unless -e $file; | ||||||||||||||||||||||||||||||||||||||||
| 177 | 13 | ▶ | $class->_error( "'$file' is a directory, not a file" ) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 178 | unless -f _; | ||||||||||||||||||||||||||||||||||||||||
| 179 | 12 | ▶ | $class->_error( "Insufficient permissions to read '$file'" ) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 180 | unless -r _; | ||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||
| 182 | # Open unbuffered with strict UTF-8 decoding and no translation layers | ||||||||||||||||||||||||||||||||||||||||
| 183 | 12 | ▶ | open( my $fh, "<:unix:encoding(UTF-8)", $file ); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 184 | 12 | ▶ | unless ( $fh ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $class->_error("Failed to open file '$file': $!"); | |||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||
| 188 | # flock if available (or warn if not possible for OS-specific reasons) | ||||||||||||||||||||||||||||||||||||||||
| 189 | 12 | ▶ | if ( _can_flock() ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 190 | 12 | ▶ | flock( $fh, Fcntl::LOCK_SH() ) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 191 | or warn "Couldn't lock '$file' for reading: $!"; | ||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||
| 194 | # slurp the contents | ||||||||||||||||||||||||||||||||||||||||
| 195 | 12 | my $contents = eval { | |||||||||||||||||||||||||||||||||||||||
| 196 | 12 | ▶ | use warnings FATAL => 'utf8'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 197 | 12 | local $/; | |||||||||||||||||||||||||||||||||||||||
| 198 | <$fh> | ||||||||||||||||||||||||||||||||||||||||
| 199 | 12 | }; | |||||||||||||||||||||||||||||||||||||||
| 200 | 12 | ▶ | if ( my $err = $@ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | $class->_error("Error reading from file '$file': $err"); | |||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||
| 204 | # close the file (release the lock) | ||||||||||||||||||||||||||||||||||||||||
| 205 | 10 | ▶ | unless ( close $fh ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $class->_error("Failed to close file '$file': $!"); | |||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||
| 209 | 10 | $class->_load_string( $contents ); | |||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||
| 212 | # Create an object from a string | ||||||||||||||||||||||||||||||||||||||||
| 213 | sub _load_string { | ||||||||||||||||||||||||||||||||||||||||
| 214 | 340 | ▶ | my $class = ref $_[0] ? ref shift : shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_string: called CC=22 SCAR=31.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 215 | 340 | my $self = bless [], $class; | |||||||||||||||||||||||||||||||||||||||
| 216 | 340 | my $string = $_[0]; | |||||||||||||||||||||||||||||||||||||||
| 217 | 340 | eval { | |||||||||||||||||||||||||||||||||||||||
| 218 | 340 | ▶ | unless ( defined $string ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | die \"Did not provide a string to load"; | |||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||
| 222 | # Check if Perl has it marked as characters, but it's internally | ||||||||||||||||||||||||||||||||||||||||
| 223 | # inconsistent. E.g. maybe latin1 got read on a :utf8 layer | ||||||||||||||||||||||||||||||||||||||||
| 224 | 339 | ▶ | if ( utf8::is_utf8($string) && ! utf8::valid($string) ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
utf8::is_utf8($string) and not utf8::valid($string)
MC/DC100%2/2
utf8::is_utf8($string) and not utf8::valid($string)
utf8::is_utf8($string)
not utf8::valid($string)
Truth table100%3/3
A and not(B)
A= utf8::is_utf8($string)B= not utf8::valid($string)
| |||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | die \<<'...'; | |||||||||||||||||||||||||||||||||||||||
| 226 | Read an invalid UTF-8 string (maybe mixed UTF-8 and 8-bit character set). | ||||||||||||||||||||||||||||||||||||||||
| 227 | Did you decode with lax ":utf8" instead of strict ":encoding(UTF-8)"? | ||||||||||||||||||||||||||||||||||||||||
| 228 | ... | ||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||
| 231 | # Ensure Unicode character semantics, even for 0x80-0xff | ||||||||||||||||||||||||||||||||||||||||
| 232 | 338 | utf8::upgrade($string); | |||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||
| 234 | # Check for and strip any leading UTF-8 BOM | ||||||||||||||||||||||||||||||||||||||||
| 235 | 338 | $string =~ s/^\x{FEFF}//; | |||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||
| 237 | # Check for some special cases | ||||||||||||||||||||||||||||||||||||||||
| 238 | 338 | ▶ | return $self unless length $string; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||
| 240 | # Split the file into lines | ||||||||||||||||||||||||||||||||||||||||
| 241 | 334 | my @lines = grep { ! /^\s*(?:\#.*)?\z/ } | |||||||||||||||||||||||||||||||||||||||
| 242 | split /(?:\015{1,2}\012|\015|\012)/, $string; | ||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||
| 244 | # Strip the initial YAML header | ||||||||||||||||||||||||||||||||||||||||
| 245 | 334 | ▶ | @lines and $lines[0] =~ /^\%YAML[: ][\d\.]+.*\z/ and shift @lines; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@lines and $lines[0] =~ /^\%YAML[: ][\d\.]+.*\z/
MC/DC100%2/2
@lines and $lines[0] =~ /^\%YAML[: ][\d\.]+.*\z/
@lines
$lines[0] =~ /^\%YAML[: ][\d\.]+.*\z/
Truth table100%3/3
A and B
A= @linesB= $lines[0] =~ /^\%YAML[: ][\d\.]+.*\z/
| |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||
| 247 | # A nibbling parser | ||||||||||||||||||||||||||||||||||||||||
| 248 | 334 | my $in_document = 0; | |||||||||||||||||||||||||||||||||||||||
| 249 | 334 | ▶ | while ( @lines ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 250 | # Do we have a document header? | ||||||||||||||||||||||||||||||||||||||||
| 251 | 358 | ▶ | if ( $lines[0] =~ /^---\s*(?:(.+)\s*)?\z/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 252 | # Handle scalar documents | ||||||||||||||||||||||||||||||||||||||||
| 253 | 278 | shift @lines; | |||||||||||||||||||||||||||||||||||||||
| 254 | 278 | ▶ | if ( defined $1 and $1 !~ /^(?:\#.+|\%YAML[: ][\d\.]+)\z/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $1 and not $1 =~ /^(?:\#.+|\%YAML[: ][\d\.]+)\z/
MC/DC100%2/2
defined $1 and not $1 =~ /^(?:\#.+|\%YAML[: ][\d\.]+)\z/
defined $1
not $1 =~ /^(?:\#.+|\%YAML[: ][\d\.]+)\z/
Truth table100%3/3
A and not(B)
A= defined $1B= not $1 =~ /^(?:\#.+|\%YAML[: ][\d\.]+)\z/
| |||||||||||||||||||||||||||||||||||||||||
| 255 | 43 | push @$self, | |||||||||||||||||||||||||||||||||||||||
| 256 | $self->_load_scalar( "$1", [ undef ], \@lines ); | ||||||||||||||||||||||||||||||||||||||||
| 257 | 43 | next; | |||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||
| 259 | 235 | $in_document = 1; | |||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||
| 262 | 315 | ▶ | if ( ! @lines or $lines[0] =~ /^(?:---|\.\.\.)/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition100%3/3
not @lines or $lines[0] =~ /^(?:---|\.\.\.)/
MC/DC100%2/2
not @lines or $lines[0] =~ /^(?:---|\.\.\.)/
not @lines
$lines[0] =~ /^(?:---|\.\.\.)/
Truth table100%3/3
not(A) or B
A= not @linesB= $lines[0] =~ /^(?:---|\.\.\.)/
| |||||||||||||||||||||||||||||||||||||||||
| 263 | # A naked document | ||||||||||||||||||||||||||||||||||||||||
| 264 | 12 | push @$self, undef; | |||||||||||||||||||||||||||||||||||||||
| 265 | 12 | ▶ | while ( @lines and $lines[0] !~ /^---/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@lines and not $lines[0] =~ /^---/
MC/DC0%0/2
@lines and not $lines[0] =~ /^---/
@lines
not $lines[0] =~ /^---/
Truth table66%2/3
A and not(B)
A= @linesB= not $lines[0] =~ /^---/
| |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | shift @lines; | |||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||
| 268 | 12 | $in_document = 0; | |||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||
| 270 | # XXX The final '-+$' is to look for -- which ends up being an | ||||||||||||||||||||||||||||||||||||||||
| 271 | # error later. | ||||||||||||||||||||||||||||||||||||||||
| 272 | ▶ | } elsif ( ! $in_document && @$self ) { | |||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not $in_document and @$self
MC/DC100%2/2
not $in_document and @$self
not $in_document
@$self
Truth table100%3/3
not(A) and B
A= not $in_documentB= @$self
| |||||||||||||||||||||||||||||||||||||||||
| 273 | # only the first document can be explicit | ||||||||||||||||||||||||||||||||||||||||
| 274 | 2 | die \"CPAN::Meta::YAML failed to classify the line '$lines[0]'"; | |||||||||||||||||||||||||||||||||||||||
| 275 | } elsif ( $lines[0] =~ /^\s*\-(?:\s|$|-+$)/ ) { | ||||||||||||||||||||||||||||||||||||||||
| 276 | # An array at the root | ||||||||||||||||||||||||||||||||||||||||
| 277 | 65 | my $document = [ ]; | |||||||||||||||||||||||||||||||||||||||
| 278 | 65 | push @$self, $document; | |||||||||||||||||||||||||||||||||||||||
| 279 | 65 | $self->_load_array( $document, [ 0 ], \@lines ); | |||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||
| 281 | } elsif ( $lines[0] =~ /^(\s*)\S/ ) { | ||||||||||||||||||||||||||||||||||||||||
| 282 | # A hash at the root | ||||||||||||||||||||||||||||||||||||||||
| 283 | 236 | my $document = { }; | |||||||||||||||||||||||||||||||||||||||
| 284 | 236 | push @$self, $document; | |||||||||||||||||||||||||||||||||||||||
| 285 | 236 | $self->_load_hash( $document, [ length($1) ], \@lines ); | |||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||
| 287 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 288 | # Shouldn't get here. @lines have whitespace-only lines | ||||||||||||||||||||||||||||||||||||||||
| 289 | # stripped, and previous match is a line with any | ||||||||||||||||||||||||||||||||||||||||
| 290 | # non-whitespace. So this clause should only be reachable via | ||||||||||||||||||||||||||||||||||||||||
| 291 | # a perlbug where \s is not symmetric with \S | ||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||
| 293 | # uncoverable statement | ||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | die \"CPAN::Meta::YAML failed to classify the line '$lines[0]'"; | |||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||
| 297 | }; | ||||||||||||||||||||||||||||||||||||||||
| 298 | 340 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||
| 299 | 340 | ▶ | if ( ref $err eq 'SCALAR' ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 300 | 15 | $self->_error(${$err}); | |||||||||||||||||||||||||||||||||||||||
| 301 | } elsif ( $err ) { | ||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $self->_error($err); | |||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||
| 305 | 325 | return $self; | |||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||
| 308 | sub _unquote_single { | ||||||||||||||||||||||||||||||||||||||||
| 309 | 232 | ▶ | my ($self, $string) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unquote_single: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||
| 310 | 232 | ▶ | return '' unless length $string; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 311 | 227 | $string =~ s/\'\'/\'/g; | |||||||||||||||||||||||||||||||||||||||
| 312 | 227 | return $string; | |||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||
| 315 | sub _unquote_double { | ||||||||||||||||||||||||||||||||||||||||
| 316 | 87 | ▶ | my ($self, $string) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unquote_double: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||
| 317 | 87 | ▶ | return '' unless length $string; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 318 | 86 | $string =~ s/\\"/"/g; | |||||||||||||||||||||||||||||||||||||||
| 319 | 86 | $string =~ | |||||||||||||||||||||||||||||||||||||||
| 320 | s{\\([Nnever\\fartz0b]|x([0-9a-fA-F]{2}))} | ||||||||||||||||||||||||||||||||||||||||
| 321 | 74 | ▶ | {(length($1)>1)?pack("H2",$2):$UNESCAPES{$1}}gex; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 322 | 86 | return $string; | |||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||
| 325 | # Load a YAML scalar string to the actual Perl scalar | ||||||||||||||||||||||||||||||||||||||||
| 326 | sub _load_scalar { | ||||||||||||||||||||||||||||||||||||||||
| 327 | 926 | ▶ | my ($self, $string, $indent, $lines) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_scalar: called CC=17 SCAR=28.4
| |||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||
| 329 | # Trim trailing whitespace | ||||||||||||||||||||||||||||||||||||||||
| 330 | 926 | $string =~ s/\s*\z//; | |||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||
| 332 | # Explitic null/undef | ||||||||||||||||||||||||||||||||||||||||
| 333 | 926 | ▶ | return undef if $string eq '~'; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||
| 335 | # Single quote | ||||||||||||||||||||||||||||||||||||||||
| 336 | 888 | ▶ | if ( $string =~ /^$re_capture_single_quoted$re_trailing_comment\z/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 337 | 185 | return $self->_unquote_single($1); | |||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||
| 340 | # Double quote. | ||||||||||||||||||||||||||||||||||||||||
| 341 | 703 | ▶ | if ( $string =~ /^$re_capture_double_quoted$re_trailing_comment\z/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 342 | 58 | return $self->_unquote_double($1); | |||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||
| 345 | # Special cases | ||||||||||||||||||||||||||||||||||||||||
| 346 | 645 | ▶ | if ( $string =~ /^[\'\"!&]/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 347 | 2 | die \"CPAN::Meta::YAML does not support a feature in line '$string'"; | |||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||
| 349 | 643 | ▶ | return {} if $string =~ /^{}(?:\s+\#.*)?\z/; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 350 | 633 | ▶ | return [] if $string =~ /^\[\](?:\s+\#.*)?\z/; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||
| 352 | # Regular unquoted string | ||||||||||||||||||||||||||||||||||||||||
| 353 | 623 | ▶ | if ( $string !~ /^[>|]/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 354 | 614 | ▶ | die \"CPAN::Meta::YAML found illegal characters in plain scalar: '$string'" | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$string =~ /^(?:-(?:\s|$)|[\@\%\`])/ or $string =~ /:(?:\s|$)/
MC/DC100%2/2
$string =~ /^(?:-(?:\s|$)|[\@\%\`])/ or $string =~ /:(?:\s|$)/
$string =~ /^(?:-(?:\s|$)|[\@\%\`])/
$string =~ /:(?:\s|$)/
Truth table100%3/3
A or B
A= $string =~ /^(?:-(?:\s|$)|[\@\%\`])/B= $string =~ /:(?:\s|$)/
| |||||||||||||||||||||||||||||||||||||||||
| 355 | if $string =~ /^(?:-(?:\s|$)|[\@\%\`])/ or | ||||||||||||||||||||||||||||||||||||||||
| 356 | $string =~ /:(?:\s|$)/; | ||||||||||||||||||||||||||||||||||||||||
| 357 | 606 | $string =~ s/\s+#.*\z//; | |||||||||||||||||||||||||||||||||||||||
| 358 | 606 | return $string; | |||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||
| 361 | # Error | ||||||||||||||||||||||||||||||||||||||||
| 362 | 9 | ▶ | die \"CPAN::Meta::YAML failed to find multi-line scalar content" unless @$lines; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||
| 364 | # Check the indent depth | ||||||||||||||||||||||||||||||||||||||||
| 365 | 9 | $lines->[0] =~ /^(\s*)/; | |||||||||||||||||||||||||||||||||||||||
| 366 | 9 | $indent->[-1] = length("$1"); | |||||||||||||||||||||||||||||||||||||||
| 367 | 9 | ▶ | if ( defined $indent->[-2] and $indent->[-1] <= $indent->[-2] ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $indent->[-2] and $indent->[-1] <= $indent->[-2]
MC/DC0%0/2
defined $indent->[-2] and $indent->[-1] <= $indent->[-2]
defined $indent->[-2]
$indent->[-1] <= $indent->[-2]
Truth table33%1/3
A and B
A= defined $indent->[-2]B= $indent->[-1] <= $indent->[-2]
| |||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | die \"CPAN::Meta::YAML found bad indenting in line '$lines->[0]'"; | |||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||
| 371 | # Pull the lines | ||||||||||||||||||||||||||||||||||||||||
| 372 | 9 | my @multiline = (); | |||||||||||||||||||||||||||||||||||||||
| 373 | 9 | ▶ | while ( @$lines ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 374 | 23 | $lines->[0] =~ /^(\s*)/; | |||||||||||||||||||||||||||||||||||||||
| 375 | 23 | ▶ | last unless length($1) >= $indent->[-1]; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 376 | 17 | push @multiline, substr(shift(@$lines), length($1)); | |||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||
| 379 | 9 | ▶ | my $j = (substr($string, 0, 1) eq '>') ? ' ' : "\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 380 | 9 | ▶ | my $t = (substr($string, 1, 1) eq '-') ? '' : "\n"; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 381 | 9 | return join( $j, @multiline ) . $t; | |||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||
| 384 | # Load an array | ||||||||||||||||||||||||||||||||||||||||
| 385 | sub _load_array { | ||||||||||||||||||||||||||||||||||||||||
| 386 | 109 | ▶ | my ($self, $array, $indent, $lines) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_array: called CC=16 SCAR=28.5
| |||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||
| 388 | 109 | ▶ | while ( @$lines ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 389 | # Check for a new document | ||||||||||||||||||||||||||||||||||||||||
| 390 | 285 | ▶ | if ( $lines->[0] =~ /^(?:---|\.\.\.)/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 391 | 15 | ▶ | while ( @$lines and $lines->[0] !~ /^---/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$lines and not $lines->[0] =~ /^---/
MC/DC100%2/2
@$lines and not $lines->[0] =~ /^---/
@$lines
not $lines->[0] =~ /^---/
Truth table100%3/3
A and not(B)
A= @$linesB= not $lines->[0] =~ /^---/
| |||||||||||||||||||||||||||||||||||||||||
| 392 | 5 | shift @$lines; | |||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||
| 394 | 15 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||
| 397 | # Check the indent level | ||||||||||||||||||||||||||||||||||||||||
| 398 | 270 | $lines->[0] =~ /^(\s*)/; | |||||||||||||||||||||||||||||||||||||||
| 399 | 270 | ▶ | if ( length($1) < $indent->[-1] ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 400 | 24 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 401 | } elsif ( length($1) > $indent->[-1] ) { | ||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | die \"CPAN::Meta::YAML found bad indenting in line '$lines->[0]'"; | |||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||
| 405 | 246 | ▶ | if ( $lines->[0] =~ /^(\s*\-\s+)[^\'\"]\S*\s*:(?:\s+|$)/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||
| 406 | # Inline nested hash | ||||||||||||||||||||||||||||||||||||||||
| 407 | 26 | my $indent2 = length("$1"); | |||||||||||||||||||||||||||||||||||||||
| 408 | 26 | $lines->[0] =~ s/-/ /; | |||||||||||||||||||||||||||||||||||||||
| 409 | 26 | push @$array, { }; | |||||||||||||||||||||||||||||||||||||||
| 410 | 26 | $self->_load_hash( $array->[-1], [ @$indent, $indent2 ], $lines ); | |||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||
| 412 | } elsif ( $lines->[0] =~ /^\s*\-\s*\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
| 413 | 38 | shift @$lines; | |||||||||||||||||||||||||||||||||||||||
| 414 | 38 | ▶ | unless ( @$lines ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 415 | 2 | push @$array, undef; | |||||||||||||||||||||||||||||||||||||||
| 416 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||
| 418 | 36 | ▶ | if ( $lines->[0] =~ /^(\s*)\-/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 419 | 4 | my $indent2 = length("$1"); | |||||||||||||||||||||||||||||||||||||||
| 420 | 4 | ▶ | if ( $indent->[-1] == $indent2 ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 421 | # Null array entry | ||||||||||||||||||||||||||||||||||||||||
| 422 | 4 | push @$array, undef; | |||||||||||||||||||||||||||||||||||||||
| 423 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 424 | # Naked indenter | ||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | push @$array, [ ]; | |||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $self->_load_array( | |||||||||||||||||||||||||||||||||||||||
| 427 | $array->[-1], [ @$indent, $indent2 ], $lines | ||||||||||||||||||||||||||||||||||||||||
| 428 | ); | ||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||
| 431 | } elsif ( $lines->[0] =~ /^(\s*)\S/ ) { | ||||||||||||||||||||||||||||||||||||||||
| 432 | 32 | push @$array, { }; | |||||||||||||||||||||||||||||||||||||||
| 433 | 32 | $self->_load_hash( | |||||||||||||||||||||||||||||||||||||||
| 434 | $array->[-1], [ @$indent, length("$1") ], $lines | ||||||||||||||||||||||||||||||||||||||||
| 435 | ); | ||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||
| 437 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | die \"CPAN::Meta::YAML failed to classify line '$lines->[0]'"; | |||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||
| 441 | } elsif ( $lines->[0] =~ /^\s*\-(\s*)(.+?)\s*\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
| 442 | # Array entry with a value | ||||||||||||||||||||||||||||||||||||||||
| 443 | 178 | shift @$lines; | |||||||||||||||||||||||||||||||||||||||
| 444 | 178 | push @$array, $self->_load_scalar( | |||||||||||||||||||||||||||||||||||||||
| 445 | "$2", [ @$indent, undef ], $lines | ||||||||||||||||||||||||||||||||||||||||
| 446 | ); | ||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||
| 448 | ▶ | } elsif ( defined $indent->[-2] and $indent->[-1] == $indent->[-2] ) { | |||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $indent->[-2] and $indent->[-1] == $indent->[-2]
MC/DC0%0/2
defined $indent->[-2] and $indent->[-1] == $indent->[-2]
defined $indent->[-2]
$indent->[-1] == $indent->[-2]
Truth table33%1/3
A and B
A= defined $indent->[-2]B= $indent->[-1] == $indent->[-2]
| |||||||||||||||||||||||||||||||||||||||||
| 449 | # This is probably a structure like the following... | ||||||||||||||||||||||||||||||||||||||||
| 450 | # --- | ||||||||||||||||||||||||||||||||||||||||
| 451 | # foo: | ||||||||||||||||||||||||||||||||||||||||
| 452 | # - list | ||||||||||||||||||||||||||||||||||||||||
| 453 | # bar: value | ||||||||||||||||||||||||||||||||||||||||
| 454 | # | ||||||||||||||||||||||||||||||||||||||||
| 455 | # ... so lets return and let the hash parser handle it | ||||||||||||||||||||||||||||||||||||||||
| 456 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||
| 458 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | die \"CPAN::Meta::YAML failed to classify line '$lines->[0]'"; | |||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||
| 463 | 61 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||
| 466 | # Load a hash | ||||||||||||||||||||||||||||||||||||||||
| 467 | sub _load_hash { | ||||||||||||||||||||||||||||||||||||||||
| 468 | 416 | ▶ | my ($self, $hash, $indent, $lines) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_load_hash: called CC=17 SCAR=28.4
| |||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||
| 470 | 416 | ▶ | while ( @$lines ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 471 | # Check for a new document | ||||||||||||||||||||||||||||||||||||||||
| 472 | 1037 | ▶ | if ( $lines->[0] =~ /^(?:---|\.\.\.)/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 473 | 3 | ▶ | while ( @$lines and $lines->[0] !~ /^---/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$lines and not $lines->[0] =~ /^---/
MC/DC100%2/2
@$lines and not $lines->[0] =~ /^---/
@$lines
not $lines->[0] =~ /^---/
Truth table100%3/3
A and not(B)
A= @$linesB= not $lines->[0] =~ /^---/
| |||||||||||||||||||||||||||||||||||||||||
| 474 | 1 | shift @$lines; | |||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||
| 476 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||
| 479 | # Check the indent level | ||||||||||||||||||||||||||||||||||||||||
| 480 | 1034 | $lines->[0] =~ /^(\s*)/; | |||||||||||||||||||||||||||||||||||||||
| 481 | 1034 | ▶ | if ( length($1) < $indent->[-1] ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 482 | 155 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 483 | } elsif ( length($1) > $indent->[-1] ) { | ||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | die \"CPAN::Meta::YAML found bad indenting in line '$lines->[0]'"; | |||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||
| 487 | # Find the key | ||||||||||||||||||||||||||||||||||||||||
| 488 | 879 | my $key; | |||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||
| 490 | # Quoted keys | ||||||||||||||||||||||||||||||||||||||||
| 491 | 879 | ▶ | if ( $lines->[0] =~ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||
| 492 | s/^\s*$re_capture_single_quoted$re_key_value_separator// | ||||||||||||||||||||||||||||||||||||||||
| 493 | ) { | ||||||||||||||||||||||||||||||||||||||||
| 494 | 47 | $key = $self->_unquote_single($1); | |||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||
| 496 | elsif ( $lines->[0] =~ | ||||||||||||||||||||||||||||||||||||||||
| 497 | s/^\s*$re_capture_double_quoted$re_key_value_separator// | ||||||||||||||||||||||||||||||||||||||||
| 498 | ) { | ||||||||||||||||||||||||||||||||||||||||
| 499 | 29 | $key = $self->_unquote_double($1); | |||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||
| 501 | elsif ( $lines->[0] =~ | ||||||||||||||||||||||||||||||||||||||||
| 502 | s/^\s*$re_capture_unquoted_key$re_key_value_separator// | ||||||||||||||||||||||||||||||||||||||||
| 503 | ) { | ||||||||||||||||||||||||||||||||||||||||
| 504 | 802 | $key = $1; | |||||||||||||||||||||||||||||||||||||||
| 505 | 802 | $key =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||
| 507 | elsif ( $lines->[0] =~ /^\s*\?/ ) { | ||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | die \"CPAN::Meta::YAML does not support a feature in line '$lines->[0]'"; | |||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||
| 510 | else { | ||||||||||||||||||||||||||||||||||||||||
| 511 | 1 | die \"CPAN::Meta::YAML failed to classify line '$lines->[0]'"; | |||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||
| 514 | 878 | ▶ | if ( exists $hash->{$key} ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 515 | 1 | warn "CPAN::Meta::YAML found a duplicate key '$key' in line '$lines->[0]'"; | |||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||
| 518 | # Do we have a value? | ||||||||||||||||||||||||||||||||||||||||
| 519 | 878 | ▶ | if ( length $lines->[0] ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 520 | # Yes | ||||||||||||||||||||||||||||||||||||||||
| 521 | 705 | $hash->{$key} = $self->_load_scalar( | |||||||||||||||||||||||||||||||||||||||
| 522 | shift(@$lines), [ @$indent, undef ], $lines | ||||||||||||||||||||||||||||||||||||||||
| 523 | ); | ||||||||||||||||||||||||||||||||||||||||
| 524 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 525 | # An indent | ||||||||||||||||||||||||||||||||||||||||
| 526 | 173 | shift @$lines; | |||||||||||||||||||||||||||||||||||||||
| 527 | 173 | ▶ | unless ( @$lines ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 528 | 1 | $hash->{$key} = undef; | |||||||||||||||||||||||||||||||||||||||
| 529 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||
| 531 | 172 | ▶ | if ( $lines->[0] =~ /^(\s*)-/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 532 | 44 | $hash->{$key} = []; | |||||||||||||||||||||||||||||||||||||||
| 533 | $self->_load_array( | ||||||||||||||||||||||||||||||||||||||||
| 534 | 44 | $hash->{$key}, [ @$indent, length($1) ], $lines | |||||||||||||||||||||||||||||||||||||||
| 535 | ); | ||||||||||||||||||||||||||||||||||||||||
| 536 | } elsif ( $lines->[0] =~ /^(\s*)./ ) { | ||||||||||||||||||||||||||||||||||||||||
| 537 | 128 | my $indent2 = length("$1"); | |||||||||||||||||||||||||||||||||||||||
| 538 | 128 | ▶ | if ( $indent->[-1] >= $indent2 ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 539 | # Null hash entry | ||||||||||||||||||||||||||||||||||||||||
| 540 | 6 | $hash->{$key} = undef; | |||||||||||||||||||||||||||||||||||||||
| 541 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 542 | 122 | $hash->{$key} = {}; | |||||||||||||||||||||||||||||||||||||||
| 543 | $self->_load_hash( | ||||||||||||||||||||||||||||||||||||||||
| 544 | 122 | $hash->{$key}, [ @$indent, length($1) ], $lines | |||||||||||||||||||||||||||||||||||||||
| 545 | ); | ||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||
| 551 | 249 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||
| 555 | ### | ||||||||||||||||||||||||||||||||||||||||
| 556 | # Dumper functions: | ||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||
| 558 | # Save an object to a file | ||||||||||||||||||||||||||||||||||||||||
| 559 | sub _dump_file { | ||||||||||||||||||||||||||||||||||||||||
| 560 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dump_file: called CC=6 SCAR=18.7
| |||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||
| 562 | 5 | require Fcntl; | |||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||
| 564 | # Check the file | ||||||||||||||||||||||||||||||||||||||||
| 565 | 5 | ▶ | my $file = shift or $self->_error( 'You did not specify a file name' ); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||
| 567 | 4 | my $fh; | |||||||||||||||||||||||||||||||||||||||
| 568 | # flock if available (or warn if not possible for OS-specific reasons) | ||||||||||||||||||||||||||||||||||||||||
| 569 | 4 | ▶ | if ( _can_flock() ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 570 | # Open without truncation (truncate comes after lock) | ||||||||||||||||||||||||||||||||||||||||
| 571 | 4 | my $flags = Fcntl::O_WRONLY()|Fcntl::O_CREAT(); | |||||||||||||||||||||||||||||||||||||||
| 572 | 4 | sysopen( $fh, $file, $flags ); | |||||||||||||||||||||||||||||||||||||||
| 573 | 4 | ▶ | unless ( $fh ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | $self->_error("Failed to open file '$file' for writing: $!"); | |||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||
| 577 | # Use no translation and strict UTF-8 | ||||||||||||||||||||||||||||||||||||||||
| 578 | 4 | binmode( $fh, ":raw:encoding(UTF-8)"); | |||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||
| 580 | 4 | ▶ | flock( $fh, Fcntl::LOCK_EX() ) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 581 | or warn "Couldn't lock '$file' for reading: $!"; | ||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||
| 583 | # truncate and spew contents | ||||||||||||||||||||||||||||||||||||||||
| 584 | 4 | truncate $fh, 0; | |||||||||||||||||||||||||||||||||||||||
| 585 | 4 | seek $fh, 0, 0; | |||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||
| 587 | else { | ||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | open $fh, ">:unix:encoding(UTF-8)", $file; | |||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||
| 591 | # serialize and spew to the handle | ||||||||||||||||||||||||||||||||||||||||
| 592 | 4 | print {$fh} $self->_dump_string; | |||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||
| 594 | # close the file (release the lock) | ||||||||||||||||||||||||||||||||||||||||
| 595 | 4 | ▶ | unless ( close $fh ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | $self->_error("Failed to close file '$file': $!"); | |||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||
| 599 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||
| 602 | # Save an object to a string | ||||||||||||||||||||||||||||||||||||||||
| 603 | sub _dump_string { | ||||||||||||||||||||||||||||||||||||||||
| 604 | 269 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dump_string: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||||||||||||||
| 605 | 269 | ▶ | return '' unless ref $self && @$self; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $self and @$self
MC/DC100%2/2
ref $self and @$self
ref $self
@$self
Truth table100%3/3
A and B
A= ref $selfB= @$self
| |||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||
| 607 | # Iterate over the documents | ||||||||||||||||||||||||||||||||||||||||
| 608 | 265 | my $indent = 0; | |||||||||||||||||||||||||||||||||||||||
| 609 | 265 | my @lines = (); | |||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||
| 611 | 265 | eval { | |||||||||||||||||||||||||||||||||||||||
| 612 | 265 | foreach my $cursor ( @$self ) { | |||||||||||||||||||||||||||||||||||||||
| 613 | 278 | push @lines, '---'; | |||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||
| 615 | # An empty document | ||||||||||||||||||||||||||||||||||||||||
| 616 | 278 | ▶ | if ( ! defined $cursor ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||
| 617 | # Do nothing | ||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||
| 619 | # A scalar document | ||||||||||||||||||||||||||||||||||||||||
| 620 | } elsif ( ! ref $cursor ) { | ||||||||||||||||||||||||||||||||||||||||
| 621 | 19 | $lines[-1] .= ' ' . $self->_dump_scalar( $cursor ); | |||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||
| 623 | # A list at the root | ||||||||||||||||||||||||||||||||||||||||
| 624 | } elsif ( ref $cursor eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
| 625 | 33 | ▶ | unless ( @$cursor ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 626 | 1 | $lines[-1] .= ' []'; | |||||||||||||||||||||||||||||||||||||||
| 627 | 1 | next; | |||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||
| 629 | 32 | push @lines, $self->_dump_array( $cursor, $indent, {} ); | |||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||
| 631 | # A hash at the root | ||||||||||||||||||||||||||||||||||||||||
| 632 | } elsif ( ref $cursor eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
| 633 | 219 | ▶ | unless ( %$cursor ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 634 | 1 | $lines[-1] .= ' {}'; | |||||||||||||||||||||||||||||||||||||||
| 635 | 1 | next; | |||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||
| 637 | 218 | push @lines, $self->_dump_hash( $cursor, $indent, {} ); | |||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||
| 639 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | die \("Cannot serialize " . ref($cursor)); | |||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||
| 642 | } | ||||||||||||||||||||||||||||||||||||||||
| 643 | }; | ||||||||||||||||||||||||||||||||||||||||
| 644 | 265 | ▶ | if ( ref $@ eq 'SCALAR' ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 645 | 1 | $self->_error(${$@}); | |||||||||||||||||||||||||||||||||||||||
| 646 | } elsif ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | $self->_error($@); | |||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||
| 650 | 264 | join '', map { "$_\n" } @lines; | |||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||
| 653 | sub _has_internal_string_value { | ||||||||||||||||||||||||||||||||||||||||
| 654 | 1105 | ▶ | my $value = shift; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_has_internal_string_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 655 | 1105 | my $b_obj = B::svref_2object(\$value); # for round trip problem | |||||||||||||||||||||||||||||||||||||||
| 656 | 1105 | return $b_obj->FLAGS & B::SVf_POK(); | |||||||||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||
| 659 | sub _dump_scalar { | ||||||||||||||||||||||||||||||||||||||||
| 660 | 1105 | ▶ | my $string = $_[1]; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dump_scalar: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||
| 661 | 1105 | my $is_key = $_[2]; | |||||||||||||||||||||||||||||||||||||||
| 662 | # Check this before checking length or it winds up looking like a string! | ||||||||||||||||||||||||||||||||||||||||
| 663 | 1105 | my $has_string_flag = _has_internal_string_value($string); | |||||||||||||||||||||||||||||||||||||||
| 664 | 1105 | ▶ | return '~' unless defined $string; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 665 | 1081 | ▶ | return "''" unless length $string; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 666 | 1078 | ▶ | if (Scalar::Util::looks_like_number($string)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 667 | # keys and values that have been used as strings get quoted | ||||||||||||||||||||||||||||||||||||||||
| 668 | 90 | ▶ | if ( $is_key || $has_string_flag ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$is_key or $has_string_flag
MC/DC100%2/2
$is_key or $has_string_flag
$is_key
$has_string_flag
Truth table100%3/3
A or B
A= $is_keyB= $has_string_flag
| |||||||||||||||||||||||||||||||||||||||||
| 669 | 56 | return qq['$string']; | |||||||||||||||||||||||||||||||||||||||
| 670 | } | ||||||||||||||||||||||||||||||||||||||||
| 671 | else { | ||||||||||||||||||||||||||||||||||||||||
| 672 | 34 | return $string; | |||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||
| 675 | 988 | ▶ | if ( $string =~ /[\x00-\x09\x0b-\x0d\x0e-\x1f\x7f-\x9f\'\n]/ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 676 | 98 | $string =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||||||||||||||
| 677 | 98 | $string =~ s/"/\\"/g; | |||||||||||||||||||||||||||||||||||||||
| 678 | 98 | $string =~ s/\n/\\n/g; | |||||||||||||||||||||||||||||||||||||||
| 679 | 98 | $string =~ s/[\x85]/\\N/g; | |||||||||||||||||||||||||||||||||||||||
| 680 | 98 | $string =~ s/([\x00-\x1f])/\\$UNPRINTABLE[ord($1)]/g; | |||||||||||||||||||||||||||||||||||||||
| 681 | 98 | $string =~ s/([\x7f-\x9f])/'\x' . sprintf("%X",ord($1))/ge; | |||||||||||||||||||||||||||||||||||||||
| 682 | 98 | return qq|"$string"|; | |||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||
| 684 | 890 | ▶ | if ( $string =~ /(?:^[~!@#%&*|>?:,'"`{}\[\]]|^-+$|\s|:\z)/ or | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$string =~ /(?:^[~!\@#%&*|>?:,'"`{}\[\]]|^-+$|\s|:\z)/ or $QUOTE{$string}
MC/DC100%2/2
$string =~ /(?:^[~!\@#%&*|>?:,'"`{}\[\]]|^-+$|\s|:\z)/ or $QUOTE{$string}
$string =~ /(?:^[~!\@#%&*|>?:,'"`{}\[\]]|^-+$|\s|:\z)/
$QUOTE{$string}
Truth table100%3/3
A or B
A= $string =~ /(?:^[~!\@#%&*|>?:,'"`{}\[\]]|^-+$|\s|:\z)/B= $QUOTE{$string}
| |||||||||||||||||||||||||||||||||||||||||
| 685 | $QUOTE{$string} | ||||||||||||||||||||||||||||||||||||||||
| 686 | ) { | ||||||||||||||||||||||||||||||||||||||||
| 687 | 193 | return "'$string'"; | |||||||||||||||||||||||||||||||||||||||
| 688 | } | ||||||||||||||||||||||||||||||||||||||||
| 689 | 697 | return $string; | |||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||
| 692 | sub _dump_array { | ||||||||||||||||||||||||||||||||||||||||
| 693 | 55 | ▶ | my ($self, $array, $indent, $seen) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dump_array: called CC=8 SCAR=21.5
| |||||||||||||||||||||||||||||||||||||||||
| 694 | 55 | ▶ | if ( $seen->{refaddr($array)}++ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | die \"CPAN::Meta::YAML does not support circular references"; | |||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||
| 697 | 55 | my @lines = (); | |||||||||||||||||||||||||||||||||||||||
| 698 | 55 | foreach my $el ( @$array ) { | |||||||||||||||||||||||||||||||||||||||
| 699 | 127 | my $line = (' ' x $indent) . '-'; | |||||||||||||||||||||||||||||||||||||||
| 700 | 127 | my $type = ref $el; | |||||||||||||||||||||||||||||||||||||||
| 701 | 127 | ▶ | if ( ! $type ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||
| 702 | 94 | $line .= ' ' . $self->_dump_scalar( $el ); | |||||||||||||||||||||||||||||||||||||||
| 703 | 94 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||
| 705 | } elsif ( $type eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
| 706 | 1 | ▶ | if ( @$el ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 707 | 0 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||
| 708 | 0 | push @lines, $self->_dump_array( $el, $indent + 1, $seen ); | |||||||||||||||||||||||||||||||||||||||
| 709 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 710 | 1 | $line .= ' []'; | |||||||||||||||||||||||||||||||||||||||
| 711 | 1 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||
| 714 | } elsif ( $type eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
| 715 | 32 | ▶ | if ( keys %$el ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 716 | 31 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||
| 717 | 31 | push @lines, $self->_dump_hash( $el, $indent + 1, $seen ); | |||||||||||||||||||||||||||||||||||||||
| 718 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 719 | 1 | $line .= ' {}'; | |||||||||||||||||||||||||||||||||||||||
| 720 | 1 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||
| 721 | } | ||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||
| 723 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 724 | 0 | die \"CPAN::Meta::YAML does not support $type references"; | |||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||
| 728 | 53 | @lines; | |||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||
| 731 | sub _dump_hash { | ||||||||||||||||||||||||||||||||||||||||
| 732 | 310 | ▶ | my ($self, $hash, $indent, $seen) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dump_hash: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||
| 733 | 310 | ▶ | if ( $seen->{refaddr($hash)}++ ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 734 | 1 | die \"CPAN::Meta::YAML does not support circular references"; | |||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||
| 736 | 309 | my @lines = (); | |||||||||||||||||||||||||||||||||||||||
| 737 | 309 | foreach my $name ( sort keys %$hash ) { | |||||||||||||||||||||||||||||||||||||||
| 738 | 542 | my $el = $hash->{$name}; | |||||||||||||||||||||||||||||||||||||||
| 739 | 542 | my $line = (' ' x $indent) . $self->_dump_scalar($name, 1) . ":"; | |||||||||||||||||||||||||||||||||||||||
| 740 | 542 | my $type = ref $el; | |||||||||||||||||||||||||||||||||||||||
| 741 | 542 | ▶ | if ( ! $type ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||
| 742 | 452 | $line .= ' ' . $self->_dump_scalar( $el ); | |||||||||||||||||||||||||||||||||||||||
| 743 | 452 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||
| 745 | } elsif ( $type eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
| 746 | 26 | ▶ | if ( @$el ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 747 | 23 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||
| 748 | 23 | push @lines, $self->_dump_array( $el, $indent + 1, $seen ); | |||||||||||||||||||||||||||||||||||||||
| 749 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 750 | 3 | $line .= ' []'; | |||||||||||||||||||||||||||||||||||||||
| 751 | 3 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||
| 754 | } elsif ( $type eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
| 755 | 64 | ▶ | if ( keys %$el ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 756 | 61 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||
| 757 | 61 | push @lines, $self->_dump_hash( $el, $indent + 1, $seen ); | |||||||||||||||||||||||||||||||||||||||
| 758 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 759 | 3 | $line .= ' {}'; | |||||||||||||||||||||||||||||||||||||||
| 760 | 3 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||
| 763 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 764 | 0 | die \"CPAN::Meta::YAML does not support $type references"; | |||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||
| 768 | 308 | @lines; | |||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||
| 771 | |||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||
| 773 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||
| 774 | # DEPRECATED API methods: | ||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||
| 776 | # Error storage (DEPRECATED as of 1.57) | ||||||||||||||||||||||||||||||||||||||||
| 777 | 12 | our $errstr = ''; | |||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||
| 779 | # Set error | ||||||||||||||||||||||||||||||||||||||||
| 780 | sub _error { | ||||||||||||||||||||||||||||||||||||||||
| 781 | 22 | ▶ | require Carp; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 782 | 22 | $errstr = $_[1]; | |||||||||||||||||||||||||||||||||||||||
| 783 | 22 | $errstr =~ s/ at \S+ line \d+.*//; | |||||||||||||||||||||||||||||||||||||||
| 784 | 22 | Carp::croak( $errstr ); | |||||||||||||||||||||||||||||||||||||||
| 785 | } | ||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||
| 787 | # Retrieve error | ||||||||||||||||||||||||||||||||||||||||
| 788 | 12 | my $errstr_warned; | |||||||||||||||||||||||||||||||||||||||
| 789 | sub errstr { | ||||||||||||||||||||||||||||||||||||||||
| 790 | 0 | ▶ | require Carp; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
errstr: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 791 | 0 | ▶ | Carp::carp( "CPAN::Meta::YAML->errstr and \$CPAN::Meta::YAML::errstr is deprecated" ) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 792 | unless $errstr_warned++; | ||||||||||||||||||||||||||||||||||||||||
| 793 | 0 | $errstr; | |||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||
| 799 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||
| 800 | # Helper functions. Possibly not needed. | ||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||
| 803 | # Use to detect nv or iv | ||||||||||||||||||||||||||||||||||||||||
| 804 | 12 | ▶ | use B; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||
| 806 | # XXX-INGY Is flock CPAN::Meta::YAML's responsibility? | ||||||||||||||||||||||||||||||||||||||||
| 807 | # Some platforms can't flock :-( | ||||||||||||||||||||||||||||||||||||||||
| 808 | # XXX-XDG I think it is. When reading and writing files, we ought | ||||||||||||||||||||||||||||||||||||||||
| 809 | # to be locking whenever possible. People (foolishly) use YAML | ||||||||||||||||||||||||||||||||||||||||
| 810 | # files for things like session storage, which has race issues. | ||||||||||||||||||||||||||||||||||||||||
| 811 | my $HAS_FLOCK; | ||||||||||||||||||||||||||||||||||||||||
| 812 | sub _can_flock { | ||||||||||||||||||||||||||||||||||||||||
| 813 | 16 | ▶ | if ( defined $HAS_FLOCK ) { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
_can_flock: called CC=3 SCAR=11.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 814 | 13 | return $HAS_FLOCK; | |||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||
| 816 | else { | ||||||||||||||||||||||||||||||||||||||||
| 817 | 3 | require Config; | |||||||||||||||||||||||||||||||||||||||
| 818 | 3 | my $c = \%Config::Config; | |||||||||||||||||||||||||||||||||||||||
| 819 | 3 | $HAS_FLOCK = grep { $c->{$_} } qw/d_flock d_fcntl_can_lock d_lockf/; | |||||||||||||||||||||||||||||||||||||||
| 820 | 3 | ▶ | require Fcntl if $HAS_FLOCK; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 821 | 3 | return $HAS_FLOCK; | |||||||||||||||||||||||||||||||||||||||
| 822 | } | ||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||
| 826 | # XXX-INGY Is this core in 5.8.1? Can we remove this? | ||||||||||||||||||||||||||||||||||||||||
| 827 | # XXX-XDG Scalar::Util 1.18 didn't land until 5.8.8, so we need this | ||||||||||||||||||||||||||||||||||||||||
| 828 | ##################################################################### | ||||||||||||||||||||||||||||||||||||||||
| 829 | # Use Scalar::Util if possible, otherwise emulate it | ||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||
| 831 | 12 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 832 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
| 833 | 12 | ▶ | local $@; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||||||||
| 834 | 12 | ▶ | if ( eval { Scalar::Util->VERSION(1.18); } ) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 835 | 12 | *refaddr = *Scalar::Util::refaddr; | |||||||||||||||||||||||||||||||||||||||
| 836 | } | ||||||||||||||||||||||||||||||||||||||||
| 837 | else { | ||||||||||||||||||||||||||||||||||||||||
| 838 | 0 | eval <<'END_PERL'; | |||||||||||||||||||||||||||||||||||||||
| 839 | # Scalar::Util failed to load or too old | ||||||||||||||||||||||||||||||||||||||||
| 840 | sub refaddr { | ||||||||||||||||||||||||||||||||||||||||
| 841 | my $pkg = ref($_[0]) or return undef; | ||||||||||||||||||||||||||||||||||||||||
| 842 | if ( !! UNIVERSAL::can($_[0], 'can') ) { | ||||||||||||||||||||||||||||||||||||||||
| 843 | bless $_[0], 'Scalar::Util::Fake'; | ||||||||||||||||||||||||||||||||||||||||
| 844 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 845 | $pkg = undef; | ||||||||||||||||||||||||||||||||||||||||
| 846 | } | ||||||||||||||||||||||||||||||||||||||||
| 847 | "$_[0]" =~ /0x(\w+)/; | ||||||||||||||||||||||||||||||||||||||||
| 848 | my $i = do { no warnings 'portable'; hex $1 }; | ||||||||||||||||||||||||||||||||||||||||
| 849 | bless $_[0], $pkg if defined $pkg; | ||||||||||||||||||||||||||||||||||||||||
| 850 | $i; | ||||||||||||||||||||||||||||||||||||||||
| 851 | } | ||||||||||||||||||||||||||||||||||||||||
| 852 | END_PERL | ||||||||||||||||||||||||||||||||||||||||
| 853 | } | ||||||||||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||
| 856 | 12 | delete $CPAN::Meta::YAML::{refaddr}; | |||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||
| 858 | 12 | 1; | |||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||
| 860 | # XXX-INGY Doc notes I'm putting up here. Changing the doc when it's wrong | ||||||||||||||||||||||||||||||||||||||||
| 861 | # but leaving grey area stuff up here. | ||||||||||||||||||||||||||||||||||||||||
| 862 | # | ||||||||||||||||||||||||||||||||||||||||
| 863 | # I would like to change Read/Write to Load/Dump below without | ||||||||||||||||||||||||||||||||||||||||
| 864 | # changing the actual API names. | ||||||||||||||||||||||||||||||||||||||||
| 865 | # | ||||||||||||||||||||||||||||||||||||||||
| 866 | # It might be better to put Load/Dump API in the SYNOPSIS instead of the | ||||||||||||||||||||||||||||||||||||||||
| 867 | # dubious OO API. | ||||||||||||||||||||||||||||||||||||||||
| 868 | # | ||||||||||||||||||||||||||||||||||||||||
| 869 | # null and bool explanations may be outdated. | ||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||
| 871 | =pod | ||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||
| 873 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||
| 875 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||
| 877 | CPAN::Meta::YAML - Read and write a subset of YAML for CPAN Meta files | ||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||
| 879 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||
| 881 | version 0.018 | ||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||
| 883 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||
| 885 | use CPAN::Meta::YAML; | ||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||
| 887 | # reading a META file | ||||||||||||||||||||||||||||||||||||||||
| 888 | open $fh, "<:utf8", "META.yml"; | ||||||||||||||||||||||||||||||||||||||||
| 889 | $yaml_text = do { local $/; <$fh> }; | ||||||||||||||||||||||||||||||||||||||||
| 890 | $yaml = CPAN::Meta::YAML->read_string($yaml_text) | ||||||||||||||||||||||||||||||||||||||||
| 891 | or die CPAN::Meta::YAML->errstr; | ||||||||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||||||||
| 893 | # finding the metadata | ||||||||||||||||||||||||||||||||||||||||
| 894 | $meta = $yaml->[0]; | ||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||
| 896 | # writing a META file | ||||||||||||||||||||||||||||||||||||||||
| 897 | $yaml_text = $yaml->write_string | ||||||||||||||||||||||||||||||||||||||||
| 898 | or die CPAN::Meta::YAML->errstr; | ||||||||||||||||||||||||||||||||||||||||
| 899 | open $fh, ">:utf8", "META.yml"; | ||||||||||||||||||||||||||||||||||||||||
| 900 | print $fh $yaml_text; | ||||||||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||||||||
| 902 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||
| 904 | This module implements a subset of the YAML specification for use in reading | ||||||||||||||||||||||||||||||||||||||||
| 905 | and writing CPAN metadata files like F<META.yml> and F<MYMETA.yml>. It should | ||||||||||||||||||||||||||||||||||||||||
| 906 | not be used for any other general YAML parsing or generation task. | ||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||
| 908 | NOTE: F<META.yml> (and F<MYMETA.yml>) files should be UTF-8 encoded. Users are | ||||||||||||||||||||||||||||||||||||||||
| 909 | responsible for proper encoding and decoding. In particular, the C<read> and | ||||||||||||||||||||||||||||||||||||||||
| 910 | C<write> methods do B<not> support UTF-8 and should not be used. | ||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||
| 912 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||
| 914 | This module is currently derived from L<YAML::Tiny> by Adam Kennedy. If | ||||||||||||||||||||||||||||||||||||||||
| 915 | there are bugs in how it parses a particular META.yml file, please file | ||||||||||||||||||||||||||||||||||||||||
| 916 | a bug report in the YAML::Tiny bugtracker: | ||||||||||||||||||||||||||||||||||||||||
| 917 | L<https://github.com/Perl-Toolchain-Gang/YAML-Tiny/issues> | ||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||
| 919 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||
| 921 | L<YAML::Tiny>, L<YAML>, L<YAML::XS> | ||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||
| 923 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||
| 925 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||
| 927 | =item * | ||||||||||||||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||||||||||||||
| 929 | Adam Kennedy <adamk@cpan.org> | ||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||
| 931 | =item * | ||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||
| 933 | David Golden <dagolden@cpan.org> | ||||||||||||||||||||||||||||||||||||||||
| 934 | |||||||||||||||||||||||||||||||||||||||||
| 935 | =back | ||||||||||||||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||||||||||||||
| 937 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||||||||||||||
| 939 | This software is copyright (c) 2010 by Adam Kennedy. | ||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||
| 941 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||
| 942 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||
| 944 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||||||||||||||
| 946 | __END__ | ||||||||||||||||||||||||||||||||||||||||