Body/XFormsMultipart.pm

filter: Statementstmt 94.7% 36 / 38 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 91.2% 52 / 57 CC 5 SCAR 7.9
CC
5
Cov
89%
handler
4.0
init
2.1
BEGIN
1.0
CRAP 2.2
« Body/OctetStream.pm ↑ Summary Body/XForms.pm »
1 package HTTP::Body::XFormsMultipart;
2 25 $HTTP::Body::XFormsMultipart::VERSION = '1.24_02'; # TRIAL
3 25 $HTTP::Body::XFormsMultipart::VERSION = '1.2402';
4 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use base 'HTTP::Body::MultiPart';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 25 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 25 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 25 ▶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::XFormsMultipart;
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 Every other part is an upload named after its Content-ID: its data is
29 written to a temporary file like that of any multipart upload, and a NUL
30 in the Content-ID is stripped.
31  
32 =head1 METHODS
33  
34 =over 4
35  
36 =item init
37  
38 This function is overridden to detect the start part of the
39 multipart/related post.
40  
41 =cut
42  
43 2 ▶sub init {
Subroutine init: called CC=2 SCAR=7.6
Pod documented
44 2 my $self = shift;
45 2 $self->SUPER::init(@_);
46 2 ▶ unless ( $self->content_type =~ /start=\"?\<?([^\"\>;,]+)\>?\"?/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->content_type =~ /start=\"?\<?([^\"\>;,]+)\>?\"?/) 0 2 2
47 0 my $content_type = $self->content_type;
48 0 Carp::croak( "Invalid boundary in content_type: '$content_type'" );
49 }
50
51 2 $self->{start} = $1;
52  
53 2 return $self;
54 }
55  
56 =item start
57  
58 Defines the start part of the multipart/related body.
59  
60 =cut
61  
62 6 ▶sub start {
Subroutine start: called CC=1 SCAR=0.0
Pod documented
63 6 return shift->{start};
64 }
65  
66 =item handler
67  
68 This function is overridden to name the parts by their Content-ID: the
69 start part becomes the XForms:Model param, and its data the body; every
70 other part becomes an upload, as described above.
71  
72 =cut
73  
74 5 ▶sub handler {
Subroutine handler: called CC=4 SCAR=13.9
Pod documented
75 5 my ( $self, $part ) = @_;
76  
77 5 my $contentid = $part->{headers}{'Content-ID'};
78 5 $contentid =~ s/^.*[\<\"]//;
79 5 $contentid =~ s/[\>\"].*$//;
80 # It names the part and its file: a NUL would truncate that downstream.
81 5 $contentid =~ s/\0//g;
82  
83 5 ▶ if ( $contentid eq $self->start ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($contentid eq $self->start) { } 2 3 5
elsif (defined $contentid) { } 3 0 3
84 2 $part->{name} = 'XForms:Model';
85 2 ▶ if ($part->{done}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part->{"done"}) 2 0 2
86 2 $self->body($part->{data});
87 }
88 }
89 elsif ( defined $contentid ) {
90 3 $part->{name} = $contentid;
91 3 $part->{filename} = $contentid;
92 }
93  
94 5 return $self->SUPER::handler($part);
95 }
96  
97 =back
98  
99 =head1 SUPPORT
100  
101 See L<HTTP::Body>
102  
103 =head1 AUTHOR
104  
105 Daniel Ruoso C<daniel@ruoso.com>
106  
107 =head1 LICENSE
108  
109 This library is free software . You can redistribute it and/or modify
110 it under the same terms as perl itself.
111  
112 =cut
113  
114 25 1;
« Body/OctetStream.pm ↑ Summary Body/XForms.pm »