Body/OctetStream.pm

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