| 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
| |||||||||||
| 40 | 5 | $self->body( File::Temp->new( DIR => $self->tmpdir ) ); | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 21 | ▶ | if ( my $length = length( $self->{buffer} ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 20 | ▶ | $self->body->write( substr( $self->{buffer}, 0, $length, '' ), $length ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | or Carp::croak("Can't write to temporary file: $!"); | ||||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 20 | ▶ | if ( $self->length == $self->content_length ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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; | |||||||||