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 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
BranchTrueFalseTotal
unless ($self->content_type =~ /start=\"?\<?([^\"\>;,]+)\>?\"?/) 0 2 2
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
BranchTrueFalseTotal
if ($contentid eq $self->start) { } 2 3 5
elsif (defined $contentid) { } 3 0 3
79 2 $part->{name} = 'XForms:Model';
80 2 ▶ if ($part->{done}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($part->{"done"}) 2 0 2
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;
« Body/OctetStream.pm ↑ Summary Body/XForms.pm »