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