Body/OctetStream.pm

filter: Statementstmt 100% 22 / 22 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 100% 36 / 36 CC 5 SCAR 11.7
CC
5
Cov
100%
spin
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.2
« Body/UrlEncoded.pm ↑ Summary Body/XFormsMultipart.pm »
1 package HTTP::Body::OctetStream;
2 25 $HTTP::Body::OctetStream::VERSION = '1.25';
3 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use base 'HTTP::Body';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 25 ▶use File::Temp 0.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 HTTP::Body::OctetStream - HTTP Body OctetStream Parser
12  
13 =head1 SYNOPSIS
14  
15 use HTTP::Body::OctetStream;
16  
17 =head1 DESCRIPTION
18  
19 HTTP Body OctetStream Parser. It stores the body unparsed in a temporary
20 file, for application/octet-stream, application/json and any content type
21 HTTP::Body has no other parser for.
22  
23 =head1 METHODS
24  
25 =over 4
26  
27 =item spin
28  
29 Writes the data that has arrived to a temporary file in
30 L<tmpdir|HTTP::Body/tmpdir>, which is the L<body|HTTP::Body/body>. Once the
31 whole body is there, it seeks the file back to its start and sets the state to
32 done. Croaks when the file can not be written.
33  
34 =cut
35  
36 21 ▶sub spin {
Subroutine spin: called CC=5 SCAR=16.1
Pod documented
37 21 my $self = shift;
38  
39 21 ▶ unless ( $self->body ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->body) 5 16 21
40 5 $self->body( File::Temp->new( DIR => $self->tmpdir ) );
41 }
42  
43 21 ▶ if ( my $length = length( $self->{buffer} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $length = length $self->{"buffer"}) 20 1 21
44 20 ▶ $self->body->write( substr( $self->{buffer}, 0, $length, '' ), $length )
Branch: 1 branch
BranchTrueFalseTotal
$self->body->write(substr($self->{"buffer"}, 0, $length, ""), $length) or Carp::croak("Can't write to temporary file: $!") 19 1 20
45 or Carp::croak("Can't write to temporary file: $!");
46 }
47  
48 20 ▶ if ( $self->length == $self->content_length ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->length == $self->content_length) 3 17 20
49 3 seek( $self->body, 0, 0 );
50 3 $self->state('done');
51 }
52 }
53  
54 =back
55  
56 =head1 SUPPORT
57  
58 See L<HTTP::Body>
59  
60 =head1 AUTHOR
61  
62 Christian Hansen, C<ch@ngmedia.com>
63  
64 =head1 LICENSE
65  
66 This library is free software . You can redistribute it and/or modify
67 it under the same terms as perl itself.
68  
69 =cut
70  
71 25 1;
« Body/UrlEncoded.pm ↑ Summary Body/XFormsMultipart.pm »