| 1 | package HTTP::Body::XFormsMultipart; | ||||||||||||||
| 2 | 25 | $HTTP::Body::XFormsMultipart::VERSION = '1.25'; | |||||||||||||
| 3 | 25 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 25 | ▶ | use base 'HTTP::Body::MultiPart'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 25 | ▶ | use bytes; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 25 | ▶ | use IO::File; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 25 | ▶ | use File::Temp 0.14; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | =head1 NAME | ||||||||||||||
| 11 | |||||||||||||||
| 12 | HTTP::Body::XFormsMultipart - HTTP Body XForms multipart/related submission Parser | ||||||||||||||
| 13 | |||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||
| 15 | |||||||||||||||
| 16 | use HTTP::Body::XFormsMultipart; | ||||||||||||||
| 17 | |||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||
| 19 | |||||||||||||||
| 20 | HTTP Body XForms submission Parser. Inherits HTTP::Body::MultiPart. | ||||||||||||||
| 21 | |||||||||||||||
| 22 | This body type is used to parse XForms submission. In this case, the | ||||||||||||||
| 23 | XML part that contains the model is indicated by the start attribute | ||||||||||||||
| 24 | in the content-type. The XML content is stored unparsed on the | ||||||||||||||
| 25 | parameter XForms:Model. | ||||||||||||||
| 26 | |||||||||||||||
| 27 | Every other part is an upload named after its Content-ID: its data is | ||||||||||||||
| 28 | written to a temporary file like that of any multipart upload, and a NUL | ||||||||||||||
| 29 | in the Content-ID is stripped. | ||||||||||||||
| 30 | |||||||||||||||
| 31 | =head1 METHODS | ||||||||||||||
| 32 | |||||||||||||||
| 33 | =over 4 | ||||||||||||||
| 34 | |||||||||||||||
| 35 | =item init | ||||||||||||||
| 36 | |||||||||||||||
| 37 | This function is overridden to detect the start part of the | ||||||||||||||
| 38 | multipart/related post. | ||||||||||||||
| 39 | |||||||||||||||
| 40 | =cut | ||||||||||||||
| 41 | |||||||||||||||
| 42 | 2 | ▶ | sub init { | ||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||
| 43 | 2 | my $self = shift; | |||||||||||||
| 44 | 2 | $self->SUPER::init(@_); | |||||||||||||
| 45 | 2 | ▶ | unless ( $self->content_type =~ /start=\"?\<?([^\"\>;,]+)\>?\"?/ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | 0 | my $content_type = $self->content_type; | |||||||||||||
| 47 | 0 | Carp::croak( "Invalid boundary in content_type: '$content_type'" ); | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 2 | $self->{start} = $1; | |||||||||||||
| 51 | |||||||||||||||
| 52 | 2 | return $self; | |||||||||||||
| 53 | } | ||||||||||||||
| 54 | |||||||||||||||
| 55 | =item start | ||||||||||||||
| 56 | |||||||||||||||
| 57 | Defines the start part of the multipart/related body. | ||||||||||||||
| 58 | |||||||||||||||
| 59 | =cut | ||||||||||||||
| 60 | |||||||||||||||
| 61 | 6 | ▶ | sub start { | ||||||||||||
|
Subroutine
start: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 62 | 6 | return shift->{start}; | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | |||||||||||||||
| 65 | =item handler | ||||||||||||||
| 66 | |||||||||||||||
| 67 | This function is overridden to name the parts by their Content-ID: the | ||||||||||||||
| 68 | start part becomes the XForms:Model param, and its data the body; every | ||||||||||||||
| 69 | other part becomes an upload, as described above. | ||||||||||||||
| 70 | |||||||||||||||
| 71 | =cut | ||||||||||||||
| 72 | |||||||||||||||
| 73 | 5 | ▶ | sub handler { | ||||||||||||
|
Subroutine
handler: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||
| 74 | 5 | my ( $self, $part ) = @_; | |||||||||||||
| 75 | |||||||||||||||
| 76 | 5 | my $contentid = $part->{headers}{'Content-ID'}; | |||||||||||||
| 77 | 5 | $contentid =~ s/^.*[\<\"]//; | |||||||||||||
| 78 | 5 | $contentid =~ s/[\>\"].*$//; | |||||||||||||
| 79 | # It names the part and its file: a NUL would truncate that downstream. | ||||||||||||||
| 80 | 5 | $contentid =~ s/\0//g; | |||||||||||||
| 81 | |||||||||||||||
| 82 | 5 | ▶ | if ( $contentid eq $self->start ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 83 | 2 | $part->{name} = 'XForms:Model'; | |||||||||||||
| 84 | 2 | ▶ | if ($part->{done}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 85 | 2 | $self->body($part->{data}); | |||||||||||||
| 86 | } | ||||||||||||||
| 87 | } | ||||||||||||||
| 88 | elsif ( defined $contentid ) { | ||||||||||||||
| 89 | 3 | $part->{name} = $contentid; | |||||||||||||
| 90 | 3 | $part->{filename} = $contentid; | |||||||||||||
| 91 | } | ||||||||||||||
| 92 | |||||||||||||||
| 93 | 5 | return $self->SUPER::handler($part); | |||||||||||||
| 94 | } | ||||||||||||||
| 95 | |||||||||||||||
| 96 | =back | ||||||||||||||
| 97 | |||||||||||||||
| 98 | =head1 SUPPORT | ||||||||||||||
| 99 | |||||||||||||||
| 100 | See L<HTTP::Body> | ||||||||||||||
| 101 | |||||||||||||||
| 102 | =head1 AUTHOR | ||||||||||||||
| 103 | |||||||||||||||
| 104 | Daniel Ruoso C<daniel@ruoso.com> | ||||||||||||||
| 105 | |||||||||||||||
| 106 | =head1 LICENSE | ||||||||||||||
| 107 | |||||||||||||||
| 108 | This library is free software . You can redistribute it and/or modify | ||||||||||||||
| 109 | it under the same terms as perl itself. | ||||||||||||||
| 110 | |||||||||||||||
| 111 | =cut | ||||||||||||||
| 112 | |||||||||||||||
| 113 | 25 | 1; | |||||||||||||