Body/MultiPart.pm

filter: Statementstmt 96.3% 160 / 166 Branchbran 87.8% 72 / 82 Conditioncond 80.9% 17 / 21 MC/DCmcdc 71.4% 10 / 14 Subroutinesub 100% 20 / 20 Podpod 100% 13 / 13 totaltotal 92.4% 292 / 316 CC 52 SCAR 23.9
CC
52
Cov
93%
handler
20.1
parse_header
16.1
parse_boundary
7.0
CRAP 10.9
« Body.pm ↑ Summary Body/UrlEncoded.pm »
1 package HTTP::Body::MultiPart;
2 25 $HTTP::Body::MultiPart::VERSION = '1.24_02'; # TRIAL
3 25 $HTTP::Body::MultiPart::VERSION = '1.2402';
4 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use base 'HTTP::Body';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 25 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 25 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 25 ▶use File::Temp 0.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 25 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 HTTP::Body::MultiPart - HTTP Body Multipart Parser
15  
16 =head1 SYNOPSIS
17  
18 use HTTP::Body::MultiPart;
19  
20 =head1 DESCRIPTION
21  
22 HTTP Body Multipart Parser for multipart/form-data bodies.
23  
24 A part with a non-empty filename in its Content-Disposition is an upload: its
25 data is written to a temporary file as it arrives, and the part is stored with
26 L<HTTP::Body/upload> once it is complete. Every other part is stored with
27 L<HTTP::Body/param> and L<HTTP::Body/part_data>, except a part with an empty
28 filename (a file field left empty), which is dropped.
29  
30 See L<HTTP::Body/Limits> for the limits on parts and their headers, and
31 L<HTTP::Body/CONFIGURING UPLOAD TEMPORARY FILES> for the temporary files.
32  
33 =head1 METHODS
34  
35 =over 4
36  
37 =item init
38  
39 Takes the boundary from the content type, croaking if it has none, and starts
40 the parser in the preamble state.
41  
42 =cut
43  
44 45 ▶sub init {
Subroutine init: called CC=2 SCAR=7.6
Pod documented
45 45 my $self = shift;
46  
47 45 ▶ unless ( $self->content_type =~ /boundary=\"?([^\";]+)\"?/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->content_type =~ /boundary=\"?([^\";]+)\"?/) 0 45 45
48 0 my $content_type = $self->content_type;
49 0 Carp::croak("Invalid boundary in content_type: '$content_type'");
50 }
51  
52 45 $self->{boundary} = $1;
53 45 $self->{state} = 'preamble';
54  
55 45 return $self;
56 }
57  
58 =item spin
59  
60 Runs the parse method of the current state (parse_preamble, parse_boundary,
61 parse_header or parse_body) until one of them needs more data or the body is
62 done.
63  
64 =cut
65  
66 1142 ▶sub spin {
Subroutine spin: called CC=3 SCAR=11.2
Pod documented
67 1142 my $self = shift;
68  
69 1142 while (1) {
70  
71 4777 ▶ if ( $self->{state} =~ /^(preamble|boundary|header|body)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'state'} =~ /^(preamble|boundary|header|body)$/) { } 4777 0 4777
72 4777 my $method = "parse_$1";
73 4777 ▶ return unless $self->$method;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->$method 1137 3635 4772
74 }
75  
76 else {
77 0 Carp::croak('Unknown state');
78 }
79 }
80 }
81  
82 =item boundary
83  
84 The boundary parameter of the content type.
85  
86 =cut
87  
88 5839 ▶sub boundary {
Subroutine boundary: called CC=1 SCAR=0.0
Pod documented
89 5839 return shift->{boundary};
90 }
91  
92 =item boundary_begin
93  
94 C<--> followed by the boundary.
95  
96 =cut
97  
98 5839 ▶sub boundary_begin {
Subroutine boundary_begin: called CC=1 SCAR=0.0
Pod documented
99 5839 return "--" . shift->boundary;
100 }
101  
102 =item boundary_end
103  
104 boundary_begin followed by C<-->.
105  
106 =cut
107  
108 119 ▶sub boundary_end {
Subroutine boundary_end: called CC=1 SCAR=0.0
Pod documented
109 119 return shift->boundary_begin . "--";
110 }
111  
112 =item crlf
113  
114 The line ending of a multipart body, C<"\x0D\x0A">.
115  
116 =cut
117  
118 6383 ▶sub crlf () {
Subroutine crlf: called CC=1 SCAR=0.0
Pod documented
119 6383 return "\x0d\x0a";
120 }
121  
122 =item delimiter_begin
123  
124 crlf followed by boundary_begin: the delimiter that ends the data of a part.
125  
126 =cut
127  
128 3663 ▶sub delimiter_begin {
Subroutine delimiter_begin: called CC=1 SCAR=0.0
Pod documented
129 3663 my $self = shift;
130 3663 return $self->crlf . $self->boundary_begin;
131 }
132  
133 =item delimiter_end
134  
135 crlf followed by boundary_end: the close delimiter that ends the body.
136  
137 =cut
138  
139 119 ▶sub delimiter_end {
Subroutine delimiter_end: called CC=1 SCAR=0.0
Pod documented
140 119 my $self = shift;
141 119 return $self->crlf . $self->boundary_end;
142 }
143  
144 =item parse_preamble
145  
146 Drops the preamble before the first boundary and moves on to the boundary
147 state. Until the boundary is found, only as many bytes are kept as could be
148 its start.
149  
150 =cut
151  
152 1051 ▶sub parse_preamble {
Subroutine parse_preamble: called CC=3 SCAR=11.0
Pod documented
153 1051 my $self = shift;
154  
155 1051 my $index = index( $self->{buffer}, $self->boundary_begin );
156  
157 1051 ▶ unless ( $index >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($index >= 0) 1006 45 1051
158 # keep only what may be the start of a dash-boundary split across chunks
159 1006 my $keep = length( $self->boundary_begin ) - 1;
160 1006 ▶ substr( $self->{buffer}, 0, -$keep, '' ) if length( $self->{buffer} ) > $keep;
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"buffer"} > $keep 1002 4 1006
161 1006 return 0;
162 }
163  
164 # replace preamble with CRLF so we can match dash-boundary as delimiter
165 45 substr( $self->{buffer}, 0, $index, $self->crlf );
166  
167 45 $self->{state} = 'boundary';
168  
169 45 return 1;
170 }
171  
172 =item parse_boundary
173  
174 Reads a delimiter line. A delimiter starts the next part and the header
175 state; a close delimiter ends the body, and whatever follows it (padding, an
176 epilogue) is ignored. Croaks on a line that is neither, and when the body has
177 more than C<$HTTP::Body::MultiPart::max_parts> parts.
178  
179 =cut
180  
181 25 our $max_parts = 1000;
182  
183 1247 ▶sub parse_boundary {
Subroutine parse_boundary: called CC=7 SCAR=19.5
Pod documented
184 1247 my $self = shift;
185  
186 1247 ▶ if ( index( $self->{buffer}, $self->delimiter_begin . $self->crlf ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($self->{"buffer"}, $self->delimiter_begin . $self->crlf) == 0) 1200 47 1247
187  
188 1200 ▶ if ( $max_parts && ++$self->{part_count} > $max_parts ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HTTP::Body::MultiPart::max_parts and ++$self->{"part_count"} > $HTTP::Body::MultiPart::max_parts) 1 1199 1200
Condition66%2/3
$HTTP::Body::MultiPart::max_parts and ++$self->{"part_count"} > $HTTP::Body::MultiPart::max_parts
!ll&&!rl&&r
011991
MC/DC50%1/2
$HTTP::Body::MultiPart::max_parts and ++$self->{"part_count"} > $HTTP::Body::MultiPart::max_parts
$HTTP::Body::MultiPart::max_parts ++$self->{"part_count"} > $HTTP::Body::MultiPart::max_parts
Truth table66%2/3
A and B
A= $HTTP::Body::MultiPart::max_partsB= ++$self->{"part_count"} > $HTTP::Body::MultiPart::max_parts
ABresult
0X0
100
111
189 1 Carp::croak("Too many parts in multipart body (limit $max_parts)");
190 }
191  
192 1199 substr( $self->{buffer}, 0, length( $self->delimiter_begin ) + 2, '' );
193 1199 $self->{part} = {};
194 1199 $self->{state} = 'header';
195  
196 1199 return 1;
197 }
198  
199 47 ▶ if ( index( $self->{buffer}, $self->delimiter_end . $self->crlf ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($self->{"buffer"}, $self->delimiter_end . $self->crlf) == 0) 36 11 47
200  
201 36 substr( $self->{buffer}, 0, length( $self->delimiter_end ) + 2, '' );
202 36 $self->{part} = {};
203 36 $self->{state} = 'done';
204  
205 36 return 0;
206 }
207  
208 11 ▶ if ( length( $self->{buffer} ) >= length( $self->delimiter_end ) + 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->{"buffer"} >= length($self->delimiter_end) + 2) 2 9 11
209 # a close delimiter ends the body whatever follows it (padding, epilogue)
210 2 ▶ unless ( index( $self->{buffer}, $self->delimiter_end ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (index($self->{"buffer"}, $self->delimiter_end) == 0) 1 1 2
211 1 Carp::croak('Invalid multipart boundary delimiter');
212 }
213 1 substr( $self->{buffer}, 0, length( $self->delimiter_end ), '' );
214 1 $self->{part} = {};
215 1 $self->{state} = 'done';
216 }
217  
218 10 return 0;
219 }
220  
221 =item parse_header
222  
223 Reads a part's header block, up to the blank line, into C<< $part->{headers} >>,
224 keyed by field name with the first letter of each word upper-cased; a field
225 that occurs more than once gets an array reference. A continuation line is
226 joined to the line before it, and a line that is no header field is dropped.
227 Croaks when the block exceeds C<$HTTP::Body::MultiPart::max_header_size> bytes
228 or C<$HTTP::Body::MultiPart::max_header_lines> lines.
229  
230 =cut
231  
232 25 our $max_header_size = 32 * 1024;
233 25 our $max_header_lines = 100;
234  
235 1262 ▶sub parse_header {
Subroutine parse_header: called CC=15 SCAR=27.8
Pod documented
236 1262 my $self = shift;
237  
238 1262 my $crlf = $self->crlf;
239 1262 my $index = index( $self->{buffer}, $crlf . $crlf );
240  
241 # Without the blank line yet, the last 3 bytes may be its start.
242 1262 ▶ my $size = $index >= 0 ? $index : length( $self->{buffer} ) - 3;
Branch: 1 branch
BranchTrueFalseTotal
$index >= 0 ? : 1198 64 1262
243 1262 ▶ if ( $max_header_size && $size > $max_header_size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HTTP::Body::MultiPart::max_header_size and $size > $HTTP::Body::MultiPart::max_header_size) 2 1260 1262
Condition66%2/3
$HTTP::Body::MultiPart::max_header_size and $size > $HTTP::Body::MultiPart::max_header_size
!ll&&!rl&&r
012602
MC/DC50%1/2
$HTTP::Body::MultiPart::max_header_size and $size > $HTTP::Body::MultiPart::max_header_size
$HTTP::Body::MultiPart::max_header_size $size > $HTTP::Body::MultiPart::max_header_size
Truth table66%2/3
A and B
A= $HTTP::Body::MultiPart::max_header_sizeB= $size > $HTTP::Body::MultiPart::max_header_size
ABresult
0X0
100
111
244 2 Carp::croak("Multipart part header exceeds $max_header_size bytes");
245 }
246  
247 1260 ▶ unless ( $index >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($index >= 0) 63 1197 1260
248 63 return 0;
249 }
250  
251 1197 my $header = substr( $self->{buffer}, 0, $index );
252  
253 1197 ▶ if ( $max_header_lines && ( $header =~ tr/\n// ) >= $max_header_lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HTTP::Body::MultiPart::max_header_lines and $header =~ tr/\n// >= $HTTP::Body::MultiPart::max_header_lines) 1 1196 1197
Condition66%2/3
$HTTP::Body::MultiPart::max_header_lines and $header =~ tr/\n// >= $HTTP::Body::MultiPart::max_header_lines
!ll&&!rl&&r
011961
MC/DC50%1/2
$HTTP::Body::MultiPart::max_header_lines and $header =~ tr/\n// >= $HTTP::Body::MultiPart::max_header_lines
$HTTP::Body::MultiPart::max_header_lines $header =~ tr/\n// >= $HTTP::Body::MultiPart::max_header_lines
Truth table66%2/3
A and B
A= $HTTP::Body::MultiPart::max_header_linesB= $header =~ tr/\n// >= $HTTP::Body::MultiPart::max_header_lines
ABresult
0X0
100
111
254 1 Carp::croak("Multipart part header exceeds $max_header_lines lines");
255 }
256  
257 1196 substr( $self->{buffer}, 0, $index + 4, '' );
258  
259 1196 my @headers;
260 1196 for ( split /$crlf/, $header ) {
261 1286 ▶ if (s/^[ \t]+//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^[ \t]+//) { } 1 1285 1286
262 # a continuation line; with no line to continue it is dropped
263 1 ▶ $headers[-1] .= $_ if @headers;
Branch: 1 branch
BranchTrueFalseTotal
if @headers 0 1 1
264 }
265 else {
266 1285 push @headers, $_;
267 }
268 }
269  
270 1196 my $token = qr/[^][\x00-\x1f\x7f()<>@,;:\\"\/?={} \t]+/;
271  
272 1196 for my $header (@headers) {
273  
274 # A line that is no header field is dropped: without a match $1 would
275 # still hold whatever the last successful match captured.
276 1285 ▶ next unless $header =~ s/^($token):[\t ]*//;
Branch: 1 branch
BranchTrueFalseTotal
unless $header =~ s/^($token):[\t ]*// 1 1284 1285
277  
278 1284 ( my $field = $1 ) =~ s/\b(\w)/uc($1)/eg;
279  
280 1284 ▶ if ( exists $self->{part}->{headers}->{$field} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'part'}{'headers'}{$field}) { } 0 1284 1284
281 0 for ( $self->{part}->{headers}->{$field} ) {
282 0 ▶ $_ = [$_] unless ref($_) eq "ARRAY";
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_ eq "ARRAY" 0 0 0
283 0 push( @$_, $header );
284 }
285 }
286 else {
287 1284 $self->{part}->{headers}->{$field} = $header;
288 }
289 }
290  
291 1196 $self->{state} = 'body';
292  
293 1196 return 1;
294 }
295  
296 =item parse_body
297  
298 Passes a part's data on to handler as it arrives, holding back only as many
299 bytes as could be the start of the next delimiter. At the delimiter it sets
300 C<< $part->{done} >>, calls handler a last time and moves on to the boundary
301 state.
302  
303 =cut
304  
305 1217 ▶sub parse_body {
Subroutine parse_body: called CC=3 SCAR=11.0
Pod documented
306 1217 my $self = shift;
307  
308 1217 my $index = index( $self->{buffer}, $self->delimiter_begin );
309  
310 1217 ▶ if ( $index < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index < 0) 22 1195 1217
311  
312 # make sure we have enough buffer to detect end delimiter
313 22 my $length = length( $self->{buffer} ) - ( length( $self->delimiter_end ) + 2 );
314  
315 22 ▶ unless ( $length > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($length > 0) 15 7 22
316 15 return 0;
317 }
318  
319 7 $self->{part}->{data} .= substr( $self->{buffer}, 0, $length, '' );
320 7 $self->{part}->{size} += $length;
321 7 $self->{part}->{done} = 0;
322  
323 7 $self->handler( $self->{part} );
324  
325 7 return 0;
326 }
327  
328 1195 $self->{part}->{data} .= substr( $self->{buffer}, 0, $index, '' );
329 1195 $self->{part}->{size} += $index;
330 1195 $self->{part}->{done} = 1;
331  
332 1195 $self->handler( $self->{part} );
333  
334 1195 $self->{state} = 'boundary';
335  
336 1195 return 1;
337 }
338  
339 =item handler
340  
341 Called by parse_body with the part each time data arrives. On the first call
342 it takes the part's name and filename from its Content-Disposition, unless a
343 subclass has named the part already, and strips any NUL from the filename. A
344 part with a non-empty filename gets a temporary file, and its data is written
345 there as it arrives. Once the part is done it is stored as described under
346 L</DESCRIPTION>. Croaks when the temporary file can not be written.
347  
348 =cut
349  
350 # The default is also kept here: while $basename_regexp still holds it, the
351 # suffix is found by _default_suffix, a string search with the same result.
352 25 my $default_basename_regexp = qr/[^.]+(\.[^\\\/]+)$/;
353  
354 25 our $basename_regexp = $default_basename_regexp;
355 25 our $file_temp_suffix = '.upload';
356 25 our $file_temp_template;
357 25 our %file_temp_parameters;
358  
359 1202 ▶sub handler {
Subroutine handler: called CC=20 SCAR=30.0
Pod documented
360 1202 my ( $self, $part ) = @_;
361  
362 1202 ▶ unless ( exists $part->{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $part->{"name"}) 1191 11 1202
363  
364 1191 my $disposition = $part->{headers}->{'Content-Disposition'};
365 1191 my ($name) = $disposition =~ / name="?([^\";]+)"?/;
366 1191 my ($filename) = $disposition =~ / filename="?([^\"]*)"?/;
367 # Need to match empty filenames above, so this part is flagged as an upload type
368  
369 1191 $part->{name} = $name;
370 1191 ▶ $part->{filename} = $filename if defined $filename;
Branch: 1 branch
BranchTrueFalseTotal
if defined $filename 99 1092 1191
371 }
372  
373 # A file part gets its temporary file on the first call, also when a
374 # subclass has named the part and set its filename itself.
375 1202 ▶ if ( defined $part->{filename} && !exists $part->{tempname} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $part->{"filename"} and not exists $part->{"tempname"}) 102 1100 1202
Condition100%3/3
defined $part->{"filename"} and not exists $part->{"tempname"}
!ll&&!rl&&r
10955102
MC/DC100%2/2
defined $part->{"filename"} and not exists $part->{"tempname"}
defined $part->{"filename"} not exists $part->{"tempname"}
Truth table100%3/3
A and not(B)
A= defined $part->{"filename"}B= not exists $part->{"tempname"}
ABresult
0X0
100
111
376  
377 # A NUL in the filename truncates the path for anything downstream that
378 # hands it to the C layer, so strip it before the name is used or stored.
379 102 $part->{filename} =~ s/\0//g;
380  
381 102 ▶ if ( $part->{filename} ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part->{"filename"} ne "") 86 16 102
382 86 my $suffix = $file_temp_suffix;
383  
384 86 ▶ unless ($suffix) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($suffix) 24 62 86
385 24 my $basename = (File::Spec->splitpath($part->{filename}))[2];
386  
387 # A suffix can be no longer than a file name, so only the end
388 # of a long basename is looked at. On the whole of a hostile
389 # one a regexp like the default backtracks in time quadratic
390 # in its length: seconds per part, once for every part.
391 24 ▶ $basename = substr( $basename, -255 ) if length($basename) > 255;
Branch: 1 branch
BranchTrueFalseTotal
if length $basename > 255 5 19 24
392  
393 24 ▶ if ( ref $basename_regexp && $basename_regexp == $default_basename_regexp ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $HTTP::Body::MultiPart::basename_regexp and $HTTP::Body::MultiPart::basename_regexp == $default_basename_regexp) { } 14 10 24
Condition66%2/3
ref $HTTP::Body::MultiPart::basename_regexp and $HTTP::Body::MultiPart::basename_regexp == $default_basename_regexp
!ll&&!rl&&r
01014
MC/DC50%1/2
ref $HTTP::Body::MultiPart::basename_regexp and $HTTP::Body::MultiPart::basename_regexp == $default_basename_regexp
ref $HTTP::Body::MultiPart::basename_regexp $HTTP::Body::MultiPart::basename_regexp == $default_basename_regexp
Truth table66%2/3
A and B
A= ref $HTTP::Body::MultiPart::basename_regexpB= $HTTP::Body::MultiPart::basename_regexp == $default_basename_regexp
ABresult
0X0
100
111
394 14 $suffix = _default_suffix($basename);
395 }
396 else {
397 10 ▶ $suffix = $basename =~ $basename_regexp ? $1 : q{};
Branch: 1 branch
BranchTrueFalseTotal
$basename =~ /$HTTP::Body::MultiPart::basename_regexp/ ? : 8 2 10
398 }
399 }
400  
401 86 ▶ my $fh = File::Temp->new(
Branch: 1 branch
BranchTrueFalseTotal
$HTTP::Body::MultiPart::file_temp_template ? : 0 86 86
402 UNLINK => 0, DIR => $self->tmpdir, SUFFIX => $suffix,
403 ( $file_temp_template ? ( TEMPLATE => $file_temp_template ) : () ),
404 %file_temp_parameters,
405 );
406  
407 86 $part->{fh} = $fh;
408 86 $part->{tempname} = $fh->filename;
409 }
410 }
411  
412 1202 ▶ if ( $part->{fh} && ( my $length = length( $part->{data} ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part->{"fh"} and my $length = length $part->{"data"}) 85 1117 1202
Condition100%3/3
$part->{"fh"} and my $length = length $part->{"data"}
!ll&&!rl&&r
1111685
MC/DC100%2/2
$part->{"fh"} and my $length = length $part->{"data"}
$part->{"fh"} my $length = length $part->{"data"}
Truth table100%3/3
A and B
A= $part->{"fh"}B= my $length = length $part->{"data"}
ABresult
0X0
100
111
413 85 ▶ $part->{fh}->write( substr( $part->{data}, 0, $length, '' ), $length )
Branch: 1 branch
BranchTrueFalseTotal
$part->{"fh"}->write(substr($part->{"data"}, 0, $length, ""), $length) or Carp::croak("Can't write to temporary file: $!") 85 0 85
414 or Carp::croak("Can't write to temporary file: $!");
415 }
416  
417 1202 ▶ if ( $part->{done} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part->{"done"}) 1195 7 1202
418  
419 1195 ▶ if ( exists $part->{filename} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $part->{'filename'}) { } 101 1094 1195
420 101 ▶ if ( $part->{filename} ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part->{"filename"} ne "") 85 16 101
421 # A buffered write error often surfaces only here, at close.
422 85 ▶ if ( defined $part->{fh} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $part->{"fh"}) 85 0 85
423 $part->{fh}->close
424 85 ▶ or Carp::croak("Can't close temporary file: $!");
Branch: 1 branch
BranchTrueFalseTotal
$part->{"fh"}->close or Carp::croak("Can't close temporary file: $!") 85 0 85
425 }
426  
427 85 delete @{$part}{qw[ data done fh ]};
428  
429 85 $self->upload( $part->{name}, $part );
430 }
431 }
432 # If we have more than the content-disposition, we need to create a
433 # data key so that we don't waste the headers.
434 else {
435 1094 $self->param( $part->{name}, $part->{data} );
436 1094 $self->part_data( $part->{name}, $part )
437 }
438 }
439 }
440  
441 # The suffix the default $basename_regexp captures, found without a regexp,
442 # in time linear in the basename's length. It starts at the first dot after
443 # the last slash or backslash that follows a byte other than a dot, and runs
444 # to the end; a dot that is the last byte gives no suffix.
445 100035 ▶sub _default_suffix {
Subroutine _default_suffix: called CC=6 SCAR=17.9
446 100035 my ($basename) = @_;
447  
448 100035 my $last = length($basename) - 1;
449 100035 my $dot = rindex( $basename, '/' );
450 100035 my $back = rindex( $basename, '\\' );
451 100035 ▶ $dot = $back if $back > $dot;
Branch: 1 branch
BranchTrueFalseTotal
if $back > $dot 30742 69293 100035
452  
453 100035 ▶ while ( ( $dot = index( $basename, '.', $dot + 1 ) ) >= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($dot = index($basename, ".", $dot + 1)) >= 0) 58709 53789 112498
454 58709 ▶ return q{} if $dot == $last;
Branch: 1 branch
BranchTrueFalseTotal
if $dot == $last 16070 42639 58709
455 42639 ▶ return substr( $basename, $dot )
Branch: 1 branch
BranchTrueFalseTotal
if $dot > 0 and substr($basename, $dot - 1, 1) ne "." 30176 12463 42639
Condition100%3/3
$dot > 0 and substr($basename, $dot - 1, 1) ne "."
!ll&&!rl&&r
8849361430176
MC/DC100%2/2
$dot > 0 and substr($basename, $dot - 1, 1) ne "."
$dot > 0 substr($basename, $dot - 1, 1) ne "."
Truth table100%3/3
A and B
A= $dot > 0B= substr($basename, $dot - 1, 1) ne "."
ABresult
0X0
100
111
456 if $dot > 0 && substr( $basename, $dot - 1, 1 ) ne '.';
457 }
458  
459 53789 return q{};
460 }
461  
462 =back
463  
464 =head1 SUPPORT
465  
466 See L<HTTP::Body>
467  
468 =head1 AUTHOR
469  
470 Christian Hansen, C<ch@ngmedia.com>
471  
472 =head1 LICENSE
473  
474 This library is free software . You can redistribute it and/or modify
475 it under the same terms as perl itself.
476  
477 =cut
478  
479 25 1;
« Body.pm ↑ Summary Body/UrlEncoded.pm »