RPC/Request.pm

filter: Statementstmt 25.4% 14 / 55 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 25.0% 4 / 16 Podpod 58.3% 7 / 12 totaltotal 27.1% 25 / 92 CC 5 SCAR 17.6
CC
5
Cov
23%
new
20.0
method_name
6.0
parameters
2.0
CRAP 5.8
« RPC/Value.pm ↑ Summary RPC/Fault.pm »
1 package POE::Filter::XML::RPC::Request;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use POE::Filter::XML::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use base('POE::Filter::XML::Node');
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '0.04';
11  
12 sub new()
13 0 ▶{
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
14 0 my ($class, $methodname, $params) = @_;
15
16 0 my $self = POE::Filter::XML::Node->new('methodCall');
17 0 $self->appendChild('methodName');
18 0 $self->appendChild('params');
19  
20 0 bless($self, $class);
21  
22 0 $self->method_name($methodname);
23  
24 0 ▶ if(defined($params) and ref($params) eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $params and ref $params eq "ARRAY") 0 0 0
Condition0%0/3
defined $params and ref $params eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $params and ref $params eq "ARRAY"
defined $params ref $params eq "ARRAY"
Truth table0%0/3
A and B
A= defined $paramsB= ref $params eq "ARRAY"
ABresult
0X0
100
111
25 {
26 0 foreach my $param (@$params)
27 {
28 0 $self->add_parameter($param);
29 }
30 }
31  
32 0 return $self;
33 }
34  
35 sub method_name()
36 0 ▶{
Subroutine method_name: not called CC=2 SCAR=17.9
Pod documented
37 0 my ($self, $arg) = @_;
38  
39 0 ▶ if(defined($arg))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $arg) { } 0 0 0
40 {
41 0 ($self->findnodes('child::methodName'))[0]->appendText($arg);
42 0 return $arg;
43
44 } else {
45  
46 0 return $self->findvalue('child::methodName/child::text()');
47 }
48 }
49  
50 sub parameters()
51 0 ▶{
Subroutine parameters: not called CC=1 SCAR=6.9
Pod documented
52 0 return [ map { bless($_, 'POE::Filter::XML::RPC::Value') } shift(@_)->findnodes('child::params/child::param/child::value') ];
53 }
54  
55 sub add_parameter()
56 0 ▶{
Subroutine add_parameter: not called CC=1 SCAR=6.9
Pod documented
57 0 my ($self, $val) = @_;
58  
59 0 $self->add($self->wrap($val));
60
61 0 return bless($val, 'POE::Filter::XML::RPC::Value');
62 }
63  
64 sub insert_parameter()
65 0 ▶{
Subroutine insert_parameter: not called CC=1 SCAR=6.9
Pod documented
66 0 my ($self, $val, $index) = @_;
67
68 0 $self->insert($self->wrap($val), $index);
69  
70 0 return bless($val, 'POE::Filter::XML::RPC::Value');
71 }
72  
73 sub delete_parameter()
74 0 ▶{
Subroutine delete_parameter: not called CC=1 SCAR=6.9
Pod documented
75 0 my ($self, $index) = @_;
76  
77 0 my $val = ($self->delete($index)->findnodes('child::value'))[0];
78  
79 0 return bless($val, 'POE::Filter::XML::RPC::Value');
80 }
81  
82 sub get_parameter()
83 0 ▶{
Subroutine get_parameter: not called CC=1 SCAR=6.9
Pod documented
84 0 my ($self, $index) = @_;
85
86 0 my $val = ($self->get($index)->findnodes('child::value'))[0];
87
88 0 return bless($val, 'POE::Filter::XML::RPC::Value');
89 }
90  
91 sub add()
92 0 ▶{
Subroutine add: not called CC=1 SCAR=6.9
Pod undocumented
93 0 my ($self, $val) = @_;
94 0 return ($self->findnodes('child::params'))[0]->appendChild($val);
95 }
96  
97 sub delete()
98 0 ▶{
Subroutine delete: not called CC=1 SCAR=6.9
Pod undocumented
99 0 my ($self, $index) = @_;
100 0 return ($self->findnodes('child::params'))[0]->removeChild($self->get($index));
101 }
102  
103 sub insert()
104 0 ▶{
Subroutine insert: not called CC=1 SCAR=6.9
Pod undocumented
105 0 my ($self, $val, $index) = @_;
106 0 return ($self->findnodes('child::params'))[0]->insertBefore($val, $self->get($index));
107 }
108  
109 sub get()
110 0 ▶{
Subroutine get: not called CC=1 SCAR=6.9
Pod undocumented
111 0 my ($self, $index) = @_;
112 0 return ($self->findnodes("child::params/child::param[position()=$index]"))[0];
113 }
114  
115 sub wrap()
116 0 ▶{
Subroutine wrap: not called CC=1 SCAR=6.9
Pod undocumented
117 0 my ($self, $val) = @_;
118  
119 0 my $param = POE::Filter::XML::Node->new('param');
120
121 0 $param->appendChild($val);
122  
123 0 return $param;
124 }
125  
126 =pod
127  
128 =head1 NAME
129  
130 POE::Filter::XML::RPC::Request - An abstracted XMLRPC request
131  
132 =head1 SYNOPSIS
133  
134 use 5.010;
135 use POE::Filter::XML::RPC::Request;
136 use POE::Filter::XML::RPC::Value;
137  
138 my $request = POE::Filter::XML::RPC::Request->new
139 (
140 'SomeRemoteMethod',
141 [
142 POE::Filter::XML::RPC::Value->new('Some Argument')
143 ]
144 );
145  
146 say $request->method_name(); # SomeRemoteMethod
147 say $request->get_parameter(1)->value(); # Some Argument
148  
149 =head1 DESCRIPTION
150  
151 POE::Filter::XML::RPC::Request provides and abstracted XMLRPC request object
152 to use when constructing requests to a remote server.
153  
154 =head1 PUBLIC METHODS
155  
156 =over 4
157  
158 =item new()
159  
160 new() accepts two arguments, one, the method name to be used, and two, an array
161 reference of POE::Filter::XML::RPC::Value objects that are the positional
162 arguments to the method in question.
163  
164 =item method_name()
165  
166 method_name() returns the current method name of the request. Can also take an
167 argument that will change the method name to the provided argument.
168  
169 =item parameters()
170  
171 parameters() returns an array reference of all of the Values currently stored
172 in the request in the order they were provided. This is a zero based array.
173  
174 =item get_parameter()
175  
176 get_parameter() takes a one based index into the positional parameters of the
177 request. Returns the Value object at that position.
178  
179 =item insert_parameter()
180  
181 insert_parameter() takes two arguments, one, the Value object to be inserted and
182 two, the one based index to which the Value should be associated.
183  
184 =item delete_parameter()
185  
186 delete_parameter() takes a one based index into the positional parameters of the
187 request. Returns the deleted Value.
188  
189 =item add_parameter()
190  
191 add_parameter() takes a Value object as its sole argument and appends it to the
192 end of the parameters of the request.
193  
194 =back
195  
196 =head1 Notes
197  
198 Request is actually a subclass of POE::Filter::XML::Node and so all of its
199 methods, including XML::LibXML::Element's, are available for use. This could
200 ultimately be useful to avoid marshalling all of the data out of the Node and
201 instead apply an XPATH expression to target specifically what is desired deep
202 within a nested structure.
203  
204 The reason the parameter methods are one based indexed is because of how XPATH
205 works and what the spec calls out for when it comes to the position()
206 predicate.
207  
208 =head1 AUTHOR
209  
210 Copyright 2009 Nicholas Perez.
211 Licensed and distributed under the GPL.
212  
213 =cut
214  
215 2 1;
« RPC/Value.pm ↑ Summary RPC/Fault.pm »