SOAPjr/request.pm

filter: Statementstmt 37.1% 26 / 70 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 1 totaltotal 30.9% 34 / 110 CC 14 SCAR 48.5
CC
14
Cov
27%
set
210.0
_init
2.0
BEGIN
1.0
CRAP 128.3
↑ Summary SOAPjr/base.pm »
1 package SOAPjr::request;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 SOAPjr::request - the SOAPjr request object
13  
14 =head1 VERSION
15  
16 Version 1.0.3
17  
18 =cut
19  
20 1 our $VERSION = "1.0.3";
21  
22 =head1 SYNOPSIS
23  
24 See perldoc SOAPjr for more info.
25  
26 =cut
27  
28 1 ▶use base qw(SOAPjr::message);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 0 ▶sub _init {
Subroutine _init: not called CC=1 SCAR=6.9
32 0 my $self = shift;
33 0 $self->{server} = shift;
34 0 my $query = shift;
35 0 $self = $self->SUPER::_init(@_);
36 0 my $update_count = $self->set($query);
37 0 return $self;
38 }
39  
40 0 ▶sub set {
Subroutine set: not called CC=14 SCAR=53.5
Pod undocumented
41 0 my $self = shift;
42 0 my $query = shift;
43 0 my $cgi_query;
44 0 my $count = 0;
45 0 my $json;
46 0 ▶ if (ref($query) ne 'HASH' && $query->can("param")) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $query ne "HASH" and $query->can("param")) 0 0 0
Condition0%0/3
ref $query ne "HASH" and $query->can("param")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $query ne "HASH" and $query->can("param")
ref $query ne "HASH" $query->can("param")
Truth table0%0/3
A and B
A= ref $query ne "HASH"B= $query->can("param")
ABresult
0X0
100
111
47 # Make a copy
48 0 $cgi_query = $query;
49 0 my @names = $query->param;
50 0 my %params = ( map { $_ => $query->param($_) } @names );
51 0 $query = { params => \%params };
52 }
53 0 ▶ if (exists $query->{params}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $query->{"params"}) 0 0 0
54 0 ▶ if (exists $query->{params}->{json} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $query->{"params"}{"json"}) 0 0 0
55 0 my $url_decoded_json = uri_unescape($query->{params}->{json});
56 0 ▶ if ($self->{json}->can("decode")) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'json'}->can('decode')) { } 0 0 0
elsif ($self->{'json'}->can('jsonToObj')) { } 0 0 0
57 # Modern-ish 2.x JSON API
58 0 $json = $self->{json}->decode( $url_decoded_json );
59 } elsif ($self->{json}->can("jsonToObj")) {
60 # Olde Version 1.x JSON API
61 0 $json = $self->{json}->jsonToObj( $url_decoded_json );
62 } else {
63 # TODO: handle unknown JSON API
64 0 carp "WARNING: unknown JSON API";
65 }
66 0 ▶ if ( $json->{HEAD} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{'HEAD'}) { } 0 0 0
67 0 $self->{_data}->{HEAD} = $json->{HEAD};
68 } else {
69 0 carp "WARNING: HEAD missing";
70 }
71 0 ▶ if ( $json->{BODY} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($json->{'BODY'}) { } 0 0 0
72 0 $self->{_data}->{BODY} = $json->{BODY};
73 } else {
74 0 carp "WARNING: BODY missing";
75 }
76 # TODO: what about json_type
77  
78 # Check for "RELATED" components
79 0 ▶ if (exists $json->{HEAD}->{related}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $json->{"HEAD"}{"related"}) 0 0 0
80 0 ▶ while (my ($k, $v) = each %{$json->{HEAD}->{related}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$json{"HEAD"}{"related"};}) 0 0 0
81 # TODO: handle other types of related content
82 0 ▶ next unless ($v eq 'binary');
Branch: 1 branch
BranchTrueFalseTotal
unless $v eq "binary" 0 0 0
83 # Append file data
84 0 ▶ unless ($cgi_query) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cgi_query) 0 0 0
85 0 carp "WARNING: related item is a file but query not a CGI object";
86 }
87 0 my $filename = $cgi_query->param($k);
88 0 my $fh = $cgi_query->upload($k);
89 # Save CGI tmp file into our own tmp file (for lifecycle
90 # reasons)
91 0 my $tmp_fh = File::Temp->new(UNLINK => 0);
92 0 my $tmp_file = $tmp_fh->filename;
93 0 ▶ copy ($fh, $tmp_file) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
copy($fh, $tmp_file) or die $! 0 0 0
94 0 close $tmp_fh;
95 0 $self->{_data}->{BODY}->{$k}->{filepath} = $tmp_file;
96 }
97 }
98 }
99 }
100  
101 0 return $self->SUPER::set( $query, $count );
102 }
103  
104 =head1 AUTHOR
105  
106 Rob Manson, <robman[at]cpan.org>
107  
108 =head1 BUGS
109  
110 Please report any bugs or feature requests to C<bug-soapjr at rt.cpan.org>, or through
111 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SOAPjr>. I will be notified, and then you'll
112 automatically be notified of progress on your bug as I make changes.
113  
114  
115  
116  
117 =head1 SUPPORT
118  
119 You can find documentation for this module with the perldoc command.
120  
121 perldoc SOAPjr
122  
123  
124 You can also look for information at:
125  
126 =over 4
127  
128 =item * SOAPjr.org
129  
130 L<http://SOAPjr.org>
131  
132 =item * RT: CPAN's request tracker
133  
134 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SOAPjr>
135  
136 =item * AnnoCPAN: Annotated CPAN documentation
137  
138 L<http://annocpan.org/dist/SOAPjr>
139  
140 =item * CPAN Ratings
141  
142 L<http://cpanratings.perl.org/d/SOAPjr>
143  
144 =item * Search CPAN
145  
146 L<http://search.cpan.org/dist/SOAPjr/>
147  
148 =back
149  
150 =head1 ACKNOWLEDGEMENTS
151  
152 See L<http://SOAPjr.org/specs.html> for further information on related RFC's and specifications.
153  
154 =head1 COPYRIGHT & LICENSE
155  
156 Copyright 2008 Rob Manson, Sean McCarthy and http://SOAPjr.org, some rights reserved.
157  
158 This file is part of SOAPjr.
159  
160 SOAPjr is free software: you can redistribute it and/or modify
161 it under the terms of the GNU General Public License as published by
162 the Free Software Foundation, either version 3 of the License, or
163 (at your option) any later version.
164  
165 SOAPjr is distributed in the hope that it will be useful,
166 but WITHOUT ANY WARRANTY; without even the implied warranty of
167 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
168 GNU General Public License for more details.
169  
170 You should have received a copy of the GNU General Public License
171 along with SOAPjr. If not, see <http://www.gnu.org/licenses/>.
172  
173 =cut
174  
175 1 1;
↑ Summary SOAPjr/base.pm »