SOAPjr/response.pm

filter: Statementstmt 31.1% 14 / 45 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 50.0% 4 / 8 Podpod 0.0% 0 / 3 totaltotal 22.7% 18 / 79 CC 10 SCAR 30.2
CC
10
Cov
22%
add_error
42.0
output
20.0
_init
6.0
CRAP 20.6
« SOAPjr/base.pm ↑ Summary SOAPjr.pm »
1 package SOAPjr::response;
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  
6 =head1 NAME
7  
8 SOAPjr::response - the SOAPjr response object
9  
10 =head1 VERSION
11  
12 Version 1.1.2
13  
14 =cut
15  
16 1 our $VERSION = "1.1.2";
17  
18 =head1 SYNOPSIS
19  
20 See perldoc SOAPjr for more info.
21  
22 =cut
23  
24 1 ▶use base qw(SOAPjr::message);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 0 ▶sub _init {
Subroutine _init: not called CC=2 SCAR=17.9
28 0 my $self = shift;
29 0 my $config= shift;
30 0 $self = $self->SUPER::_init(@_);
31 0 ▶ if ($config) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config) 0 0 0
32 0 my $update_count = $self->set($config);
33 }
34 0 return $self;
35 }
36  
37 0 ▶sub add_error {
Subroutine add_error: not called CC=6 SCAR=37.4
Pod undocumented
38 0 my $self = shift;
39 0 my $error = shift;
40 0 ▶ if ($error->{property} && $error->{error}->{code} && $error->{error}->{message}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error->{'property'} and $error->{'error'}{'code'} and $error->{'error'}{'message'}) { } 0 0 0
Condition0%0/6
$error->{"property"} and $error->{"error"}{"code"} and $error->{"error"}{"message"}
!ll&&!rl&&r
000
$error->{"property"} and $error->{"error"}{"code"}
!ll&&!rl&&r
000
MC/DC0%0/3
$error->{"property"} and $error->{"error"}{"code"} and $error->{"error"}{"message"}
$error->{"property"} $error->{"error"}{"code"} $error->{"error"}{"message"}
Truth table0%0/4
A and B and C
A= $error->{"property"}B= $error->{"error"}{"code"}C= $error->{"error"}{"message"}
ABCresult
0XX0
10X0
1100
1111
41 0 ▶ if (!$error->{context}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($error->{"context"}) 0 0 0
42 0 $error->{context} = "BODY";
43 }
44 0 ▶ if (!$self->{_data}->{HEAD}->{errors}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_data"}{"HEAD"}{"errors"}) 0 0 0
45 0 $self->{_data}->{HEAD}->{errors} = {};
46 }
47 0 $self->{_data}->{HEAD}->{errors}->{$error->{context}}->{$error->{property}} = $error->{error};
48 0 return $self->output();
49 } else {
50 0 carp "property and an error with { code => NNN, message => xxx } is required for response::add_message()";
51 0 return 0;
52 }
53 }
54  
55 0 ▶sub output {
Subroutine output: not called CC=4 SCAR=30.0
Pod undocumented
56 0 my $self = shift;
57 0 my $json;
58 0 my $body = $self->get("BODY");
59 0 ▶ if ($self->get("HEAD")->{errors}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get('HEAD')->{'errors'}) { } 0 0 0
60 0 $self->set({ HEAD => { "result" => 0 } });
61 0 $body = {};
62 } else {
63 0 $self->set({ HEAD => { "result" => 1 } });
64 }
65 0 ▶ if ($self->{json}->can("encode")) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'json'}->can('encode')) { } 0 0 0
elsif ($self->{'json'}->can('objToJson')) { } 0 0 0
66 # Modern-ish 2.x JSON API
67 0 $json = $self->{json}->encode( { HEAD => $self->get("HEAD"), BODY => $body } );
68 } elsif ($self->{json}->can("objToJson")) {
69 # Olde Version 1.x JSON API
70 0 $json = $self->{json}->objToJson( { HEAD => $self->get("HEAD"), BODY => $body } );
71 } else {
72 # TODO: handle unknown JSON API
73 }
74 0 return $json;
75 }
76  
77 0 ▶sub send {
Subroutine send: not called CC=1 SCAR=6.9
Pod undocumented
78 0 my $self = shift;
79 0 print $self->output();
80 0 return 1;
81 }
82  
83 =head1 AUTHOR
84  
85 Rob Manson, <robman[at]cpan.org>
86  
87 =head1 BUGS
88  
89 Please report any bugs or feature requests to C<bug-soapjr at rt.cpan.org>, or through
90 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SOAPjr>. I will be notified, and then you'll
91 automatically be notified of progress on your bug as I make changes.
92  
93  
94  
95  
96 =head1 SUPPORT
97  
98 You can find documentation for this module with the perldoc command.
99  
100 perldoc SOAPjr
101  
102  
103 You can also look for information at:
104  
105 =over 4
106  
107 =item * SOAPjr.org
108  
109 L<http://SOAPjr.org>
110  
111 =item * RT: CPAN's request tracker
112  
113 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SOAPjr>
114  
115 =item * AnnoCPAN: Annotated CPAN documentation
116  
117 L<http://annocpan.org/dist/SOAPjr>
118  
119 =item * CPAN Ratings
120  
121 L<http://cpanratings.perl.org/d/SOAPjr>
122  
123 =item * Search CPAN
124  
125 L<http://search.cpan.org/dist/SOAPjr/>
126  
127 =back
128  
129 =head1 ACKNOWLEDGEMENTS
130  
131 See L<http://SOAPjr.org/specs.html> for further information on related RFC's and specifications.
132  
133 =head1 COPYRIGHT & LICENSE
134  
135 Copyright 2008 Rob Manson, Sean McCarthy and http://SOAPjr.org, some rights reserved.
136  
137 This file is part of SOAPjr.
138  
139 SOAPjr is free software: you can redistribute it and/or modify
140 it under the terms of the GNU General Public License as published by
141 the Free Software Foundation, either version 3 of the License, or
142 (at your option) any later version.
143  
144 SOAPjr is distributed in the hope that it will be useful,
145 but WITHOUT ANY WARRANTY; without even the implied warranty of
146 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
147 GNU General Public License for more details.
148  
149 You should have received a copy of the GNU General Public License
150 along with SOAPjr. If not, see <http://www.gnu.org/licenses/>.
151  
152 =cut
153  
154 1 1;
« SOAPjr/base.pm ↑ Summary SOAPjr.pm »