blib/lib/Froody/Response.pm

filter: Statementstmt 88.6% 39 / 44 Branchbran 100% 4 / 4 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 75.0% 9 / 12 Podpod 80.0% 4 / 5 totaltotal 82.1% 60 / 73 CC 5 SCAR 7.2
CC
5
Cov
87%
structure
4.0
add_cookie
2.0
method
2.0
CRAP 2.1
« blib/lib/Froody/Plugin.pm ↑ Summary blib/lib/Froody/DocServer.pm »
1 package Froody::Response;
2 45 ▶use base qw(Froody::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 45 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 45 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 45 ▶use Params::Validate qw(SCALAR);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 45 ▶use CGI;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 45 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 45 ▶use Froody::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 45 my $logger = get_logger('froody.response');
13  
14 45 __PACKAGE__->mk_accessors(qw( cookie ));
15  
16 =head1 NAME
17  
18 Froody::Response - result of a Froody::Method executing
19  
20 =head1 SYNOPSIS
21  
22 my $response = Froody::Response::String
23 ->new()
24 ->structure($froody_method)
25 ->set_string($string);
26 print $response->render;
27  
28 =head1 DESCRIPTION
29  
30 This class encapsulates a response from the Froody server, and are what the
31 Invokers must return when Froody::Methods are called. You normally don't have
32 to construct these yourself, as they're built by
33 Froody::Invoker::Implementation for you from the data structure your code
34 returned.
35  
36 This class is an abstract class, with a couple of implementations on
37 the system. Basically, responses are something that when you call C<render>
38 on them produce something that look like this:
39  
40 <?xml version="1.0" encoding="utf-8" ?>
41 <rsp stat="ok">
42 <foo>bar</foo>
43 </rsp>
44  
45 Or this, if an error has occured:
46  
47 <?xml version="1.0" encoding="utf-8" ?>
48 <rsp stat="fail">
49 <err code="947" message="Frobinator insufficiently Bamboozled" />
50 </rsp>
51  
52 =head1 METHODS
53  
54 =over
55  
56 =item render
57  
58 Abstract instance method, this method should return a byte encoded XML string
59 in the standard response format. By "byte encoded" string we mean that
60 the characters in the string should contain the bytes corrisponsing the the
61 encoding scheme mentioned in the returned xml declaration.
62  
63 =item cookie
64  
65 Get/set an arrayref of CGI::cookie instances associated with the response.
66  
67 =cut
68  
69 =item add_cookie( name => 'name', value =>'value', expires => 'expires', domain => 'domain' )
70  
71 Adds an associated a cookie to the response. Takes the following arguments:
72  
73 =over
74  
75 =item name
76  
77 The name of the cookie (required). This can be any string at all.
78 Although browsers limit their cookie names to non-whitespace
79 alphanumeric characters, CGI.pm removes this restriction by escaping and
80 unescaping cookies behind the scenes.
81  
82 =item value
83  
84 The value of the cookie. This can be any scalar value, array reference,
85 or even associative array reference. For example, you can store an
86 entire associative array into a cookie this way:
87  
88 $cookie=$query->cookie(-name=>'family information',
89 -value=>\%childrens_ages);
90 =item path
91  
92 The optional partial path for which this cookie will be valid, as
93 described above.
94  
95 =item domain
96  
97 The optional partial domain for which this cookie will be valid, as
98 described above.
99  
100 =item expires
101  
102 The optional expiration date for this cookie. The format is as described
103 in the section on the header() method:
104  
105 "+1h" one hour from now
106  
107 =item secure
108  
109 If set to true, this cookie will only be used within a secure SSL session.
110  
111 =back
112  
113 (these docs from the L<CGI> docs)
114  
115 =cut
116  
117 1 ▶sub add_cookie {
Subroutine add_cookie: called CC=2 SCAR=7.0
Pod documented
118 1 my $self = shift;
119 1 my %args = $self->validate_object(@_, {
120 name => { type => SCALAR },
121 value => { type => SCALAR },
122 expires => { type => SCALAR, optional => 1 },
123 domain => { type => SCALAR, optional => 1 },
124 path => { type => SCALAR, optional => 1 },
125 secure => { type => SCALAR, optional => 1 },
126 });
127  
128 my $cookie = CGI::cookie(
129 1 map { "-".$_ => $args{$_} } keys %args
130 );
131  
132 1 ▶ my $list = $self->cookie || [];
Condition50%1/2
$self->cookie || []
l!l
01
MC/DC0%0/1
$self->cookie || []
$self->cookie
Truth table50%1/2
A
A= $self->cookie
Aresult
11
00
133 1 push @$list, $cookie;
134 1 $self->cookie($list);
135 1 return $self;
136 }
137  
138 =item structure
139  
140 The Froody::Method or Froody::ErrorType associated with this response.
141 Something that has a 'structure' method, anyhows.
142  
143 =cut
144  
145 # method is documented
146 sub method
147 0 ▶{
Subroutine method: not called CC=1 SCAR=6.9
Pod undocumented
148 0 my $self = shift;
149 0 print STDERR "Froody::Response->method deprecated (".caller().")\n";
150 0 return $self->structure(@_)
151 }
152  
153 sub structure
154 513 ▶{
Subroutine structure: called CC=4 SCAR=13.9
Pod documented
155 513 my $self = shift;
156 513 ▶ return $self->{structure} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 233 280 513
157 280 my $struct = shift;
158
159 280 ▶ unless (blessed($struct) && $struct->isa("Froody::Structure")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($struct) and $struct->isa("Froody::Structure")) 2 278 280
Condition66%2/3
builtin::blessed($struct) and $struct->isa("Froody::Structure")
!ll&&!rl&&r
20278
MC/DC50%1/2
builtin::blessed($struct) and $struct->isa("Froody::Structure")
builtin::blessed($struct) $struct->isa("Froody::Structure")
Truth table66%2/3
A and B
A= builtin::blessed($struct)B= $struct->isa("Froody::Structure")
ABresult
0X0
100
111
160 2 Froody::Error->throw("perl.methodcall.param", "structure only accepts Froody::Structure instances (e.g. Froody::Method or Froody::ErrorType")
161 }
162
163 278 $self->{structure} = $struct;
164 278 return $self;
165 }
166  
167 =item render
168  
169 abstract method. Returns a froody-formatted XML response as a byte-sequence,
170 used as a fall-back to convert between L<Froody::Response> types.
171  
172 =cut
173  
174 0 ▶sub render { Froody::Error->throw("perl.methodcall.unimplemented") }
Subroutine render: not called CC=1 SCAR=6.9
Pod documented
175  
176 =item render_xml
177  
178 Synonym for C<render>.
179  
180 =cut
181  
182 0 ▶sub render_xml { shift->render }
Subroutine render_xml: not called CC=1 SCAR=6.9
Pod documented
183  
184 =back
185  
186 =head1 CONVERSION METHODS
187  
188 =over
189  
190 =item as_string
191  
192 =item as_perlds
193  
194 =item as_xml
195  
196 =item as_terse
197  
198 =item as_error
199  
200 =back
201  
202 =head1 BUGS
203  
204 None known.
205  
206 Please report any bugs you find via the CPAN RT system.
207 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Froody>
208  
209 =head1 AUTHOR
210  
211 Copyright Fotango 2005. All rights reserved.
212  
213 Please see the main L<Froody> documentation for details of who has worked
214 on this project.
215  
216 This module is free software; you can redistribute it and/or modify it under
217 the same terms as Perl itself.
218  
219 =head1 SEE ALSO
220  
221 L<Froody>, L<Froody::Response>
222  
223 =cut
224  
225 45 1;
226  
« blib/lib/Froody/Plugin.pm ↑ Summary blib/lib/Froody/DocServer.pm »