File Coverage

blib/lib/SOAPjr/response.pm
Criterion Covered Total %
statement 12 43 27.9
branch 0 14 0.0
condition 0 6 0.0
subroutine 4 8 50.0
pod 0 3 0.0
total 16 74 21.6


line stmt bran cond sub pod time code
1             package SOAPjr::response;
2              
3 1     1   6 use strict;
  1         2  
  1         36  
4 1     1   5 use warnings;
  1         2  
  1         45  
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             our $VERSION = "1.1.2";
17              
18             =head1 SYNOPSIS
19              
20             See perldoc SOAPjr for more info.
21              
22             =cut
23              
24 1     1   5 use base qw(SOAPjr::message);
  1         2  
  1         97  
25 1     1   5 use Carp;
  1         1  
  1         916  
26              
27             sub _init {
28 0     0     my $self = shift;
29 0           my $config= shift;
30 0           $self = $self->SUPER::_init(@_);
31 0 0         if ($config) {
32 0           my $update_count = $self->set($config);
33             }
34 0           return $self;
35             }
36              
37             sub add_error {
38 0     0 0   my $self = shift;
39 0           my $error = shift;
40 0 0 0       if ($error->{property} && $error->{error}->{code} && $error->{error}->{message}) {
      0        
41 0 0         if (!$error->{context}) {
42 0           $error->{context} = "BODY";
43             }
44 0 0         if (!$self->{_data}->{HEAD}->{errors}) {
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             sub output {
56 0     0 0   my $self = shift;
57 0           my $json;
58 0           my $body = $self->get("BODY");
59 0 0         if ($self->get("HEAD")->{errors}) {
60 0           $self->set({ HEAD => { "result" => 0 } });
61 0           $body = {};
62             } else {
63 0           $self->set({ HEAD => { "result" => 1 } });
64             }
65 0 0         if ($self->{json}->can("encode")) {
    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             sub send {
78 0     0 0   my $self = shift;
79 0           print $self->output();
80 0           return 1;
81             }
82              
83             =head1 AUTHOR
84              
85             Rob Manson,
86              
87             =head1 BUGS
88              
89             Please report any bugs or feature requests to C, or through
90             the web interface at L. 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
110              
111             =item * RT: CPAN's request tracker
112              
113             L
114              
115             =item * AnnoCPAN: Annotated CPAN documentation
116              
117             L
118              
119             =item * CPAN Ratings
120              
121             L
122              
123             =item * Search CPAN
124              
125             L
126              
127             =back
128              
129             =head1 ACKNOWLEDGEMENTS
130              
131             See L 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 .
151              
152             =cut
153              
154             1;