| 1 | package HTTP::Parser::XS::PP; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 16 | ▶ | sub HTTP::Parser::XS::parse_http_request { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_http_request: called CC=5 SCAR=16.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 16 | my($chunk, $env) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 8 | 16 | ▶ | Carp::croak("second param to parse_http_request should be a hashref") unless (ref $env|| '') eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $env || ''
MC/DC100%1/1
ref $env || ''
ref $env
Truth table100%2/2
A
A= ref $env
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | # pre-header blank lines are allowed (RFC 2616 4.1) | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 15 | $chunk =~ s/^(\x0d?\x0a)+//; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 15 | ▶ | return -2 unless length $chunk; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | # double line break indicates end of header; parse it | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 15 | ▶ | if ($chunk =~ /^(.*?\x0d?\x0a\x0d?\x0a)/s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 15 | return _parse_header($chunk, length $1, $env); | |||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | return -2; # still waiting for unknown amount of header lines | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 15 | ▶ | sub _parse_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_header: called CC=14 SCAR=26.7
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 15 | my($chunk, $eoh, $env) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 15 | my $header = substr($chunk, 0, $eoh,''); | |||||||||||||||||||||||||||||||||||||||||
| 25 | 15 | $chunk =~ s/^\x0d?\x0a\x0d?\x0a//; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | # parse into lines | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 15 | my @header = split /\x0d?\x0a/,$header; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 15 | my $request = shift @header; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # join folded lines | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 15 | my @out; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 15 | for(@header) { | |||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | ▶ | if(/^[ \t]+/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | return -1 unless @out; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | $out[-1] .= $_; | |||||||||||||||||||||||||||||||||||||||||
| 37 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 7 | push @out, $_; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # parse request or response line | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 15 | my $obj; | |||||||||||||||||||||||||||||||||||||||||
| 44 | my $minor; | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 15 | my ($method,$uri,$http) = split / /,$request; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 15 | ▶ | return -1 unless $http and $http =~ /^HTTP\/1\.(\d+)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$http and $http =~ m[^HTTP/1\.(\d+)$]
MC/DC0%0/2
$http and $http =~ m[^HTTP/1\.(\d+)$]
$http
$http =~ m[^HTTP/1\.(\d+)$]
Truth table33%1/3
A and B
A= $httpB= $http =~ m[^HTTP/1\.(\d+)$]
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 15 | $minor = $1; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 15 | my($path, $query) = ( $uri =~ /^([^?#]*)(?:\?([^#]*))?/s ); | |||||||||||||||||||||||||||||||||||||||||
| 51 | # following validations are just needed to pass t/01simple.t | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 15 | ▶ | if ($path =~ /%(?:[0-9a-f][^0-9a-f]|[^0-9a-f][0-9a-f])/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | # invalid char in url-encoded path | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | return -1; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 14 | ▶ | if ($path =~ /%(?:[0-9a-f])$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | # partially url-encoded | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | return -1; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 13 | $env->{REQUEST_METHOD} = $method; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 13 | $env->{REQUEST_URI} = $uri; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 13 | $env->{SERVER_PROTOCOL} = "HTTP/1.$minor"; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 13 | ($env->{PATH_INFO} = $path) =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 13 | ▶ | $env->{QUERY_STRING} = $query || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$query || ''
MC/DC100%1/1
$query || ''
$query
Truth table100%2/2
A
A= $query
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 13 | $env->{SCRIPT_NAME} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # import headers | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 13 | my $token = qr/[^][\x00-\x1f\x7f()<>@,;:\\"\/?={} \t]+/; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 13 | my $k; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 13 | for my $header (@out) { | |||||||||||||||||||||||||||||||||||||||||
| 72 | 7 | ▶ | if ( $header =~ s/^($token): ?// ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 7 | $k = $1; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 7 | $k =~ s/-/_/g; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 7 | $k = uc $k; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 7 | ▶ | if ($k !~ /^(?:CONTENT_LENGTH|CONTENT_TYPE)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 5 | $k = "HTTP_$k"; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } elsif ( $header =~ /^\s+/) { | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # multiline header | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | ▶ | if (exists $env->{$k}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | $env->{$k} .= ", $header"; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 5 | $env->{$k} = $header; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 13 | return $eoh; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | # ---------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 7 | my %PARSER_FUNC = ( | |||||||||||||||||||||||||||||||||||||||||
| 99 | HTTP::Parser::XS::HEADERS_NONE() => \&_parse_as_none, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | HTTP::Parser::XS::HEADERS_AS_HASHREF() => \&_parse_as_hashref, | ||||||||||||||||||||||||||||||||||||||||||
| 101 | HTTP::Parser::XS::HEADERS_AS_ARRAYREF() => \&_parse_as_arrayref, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 37 | ▶ | sub HTTP::Parser::XS::parse_http_response { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_http_response: called CC=10 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 37 | my ($str, $header_format, $special_headers) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 37 | ▶ | return -2 unless $str; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 37 | my $len = length $str; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 37 | my ($sl, $remain) = split /\r?\n/, $_[0], 2; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 37 | my ($proto, $rc, $msg) = split(' ', $sl, 3); | |||||||||||||||||||||||||||||||||||||||||
| 112 | 37 | ▶ | return -1 unless $proto =~m{^HTTP/1.(\d)}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 36 | my $minor_version = $1; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 36 | ▶ | return -1 unless $rc =~m/^\d+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 36 | my ($header_str, $content) = split /\r?\n\r?\n/, $remain, 2; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 36 | my $parser_func = $PARSER_FUNC{$header_format}; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 36 | ▶ | die 'unknown header format: '. $header_format unless $parser_func; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 36 | ▶ | my $header = $parser_func->($header_str, $special_headers || +{}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$special_headers || {}
MC/DC0%0/1
$special_headers || {}
$special_headers
Truth table50%1/2
A
A= $special_headers
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 36 | ▶ | return -2 if ($str !~/\r?\n\r?\n/ && $remain !~/\r?\n\r?\n/ && !defined $content); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$str =~ /\r?\n\r?\n/ or $remain =~ /\r?\n\r?\n/ or defined $content
$str =~ /\r?\n\r?\n/ or $remain =~ /\r?\n\r?\n/
MC/DC33%1/3
$str =~ /\r?\n\r?\n/ or $remain =~ /\r?\n\r?\n/ or defined $content
$str =~ /\r?\n\r?\n/
$remain =~ /\r?\n\r?\n/
defined $content
Truth table50%2/4
A or B or C
A= $str =~ /\r?\n\r?\n/B= $remain =~ /\r?\n\r?\n/C= defined $content
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 34 | ▶ | my $parsed = $len - (defined $content ? length $content : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 34 | return ($parsed, $minor_version, $rc, $msg, $header); | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | # return special headers only | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 8 | ▶ | sub _parse_as_none { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_as_none: called CC=10 SCAR=42.5
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 8 | my ($str, $special) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 8 | ▶ | return unless defined $str; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 8 | ▶ | return unless keys %$special; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my ($field, $value, $f); | |||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | for ( split /\r?\n/, $str ) { | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ( defined $field ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ( ord == 9 || ord == 32 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ord $_ == 9 or ord $_ == 32
MC/DC0%0/2
ord $_ == 9 or ord $_ == 32
ord $_ == 9
ord $_ == 32
Truth table0%0/3
A or B
A= ord $_ == 9B= ord $_ == 32
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $value .= "\n$_"; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $f = lc($field); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | exists $special->{$f} and $special->{$f} = $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ( $field, $value ) = split /[ \t]*: ?/, $_, 2; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if ( defined $field ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | $f = lc($field); | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | exists $special->{$f} and $special->{$f} = $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | # return headers as arrayref | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 8 | ▶ | sub _parse_as_arrayref { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_as_arrayref: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 8 | my ($str, $special) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 8 | ▶ | return [] unless defined $str; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 8 | my (@headers, $field, $value, $f ); | |||||||||||||||||||||||||||||||||||||||||
| 159 | 8 | for ( split /\r?\n/, $str ) { | |||||||||||||||||||||||||||||||||||||||||
| 160 | 12 | ▶ | if ( defined $field ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 5 | ▶ | if ( ord == 9 || ord == 32 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ord $_ == 9 or ord $_ == 32
MC/DC50%1/2
ord $_ == 9 or ord $_ == 32
ord $_ == 9
ord $_ == 32
Truth table66%2/3
A or B
A= ord $_ == 9B= ord $_ == 32
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | $value .= "\n$_"; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 4 | $f = lc($field); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 4 | push @headers, $f, $value; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 4 | ▶ | exists $special->{$f} and $special->{$f} = $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 11 | ( $field, $value ) = split /[ \t]*: ?/, $_, 2; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 8 | ▶ | if ( defined $field ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 7 | $f = lc($field); | |||||||||||||||||||||||||||||||||||||||||
| 173 | 7 | push @headers, $f, $value; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 7 | ▶ | exists $special->{$f} and $special->{$f} = $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 8 | return \@headers; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | # return headers as HTTP::Header compatible HashRef | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 20 | ▶ | sub _parse_as_hashref { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_as_hashref: called CC=13 SCAR=26.6
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 20 | my ($str, $special) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 20 | ▶ | return +{} unless defined $str; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 19 | my ( %self, $field, $value, $f ); | |||||||||||||||||||||||||||||||||||||||||
| 185 | 19 | for ( split /\r?\n/, $str ) { | |||||||||||||||||||||||||||||||||||||||||
| 186 | 31 | ▶ | if ( defined $field ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 14 | ▶ | if ( ord == 9 || ord == 32 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ord $_ == 9 or ord $_ == 32
MC/DC50%1/2
ord $_ == 9 or ord $_ == 32
ord $_ == 9
ord $_ == 32
Truth table66%2/3
A or B
A= ord $_ == 9B= ord $_ == 32
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 3 | $value .= "\n$_"; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | next; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 11 | $f = lc($field); | |||||||||||||||||||||||||||||||||||||||||
| 192 | 11 | ▶ | if ( defined $self{$f} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $h = $self{$f}; | |||||||||||||||||||||||||||||||||||||||||
| 194 | ref($h) eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 195 | ? push( @$h, $value ) | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | : ( $self{$f} = [ $h, $value ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 11 | ▶ | else { $self{$f} = $value; exists $special->{$f} and $special->{$f} = $value; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 28 | ( $field, $value ) = split /[ \t]*: ?/, $_, 2; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 19 | ▶ | if ( defined $field ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 17 | $f = lc($field); | |||||||||||||||||||||||||||||||||||||||||
| 204 | 17 | ▶ | if ( defined $self{$f} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 3 | my $h = $self{$f}; | |||||||||||||||||||||||||||||||||||||||||
| 206 | ref($h) eq 'ARRAY' | ||||||||||||||||||||||||||||||||||||||||||
| 207 | ? push( @$h, $value ) | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 3 | ▶ | : ( $self{$f} = [ $h, $value ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 14 | ▶ | else { $self{$f} = $value; exists $special->{$f} and $special->{$f} = $value; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 19 | return \%self; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||