blib/lib/WebService/AngelXML/Auth.pm

filter: Statementstmt 80.0% 80 / 100 Branchbran 98.0% 51 / 52 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.0% 18 / 20 Podpod 93.3% 14 / 15 totaltotal 85.4% 164 / 192 CC 28 SCAR 14.8
CC
28
Cov
85%
initialize
11.0
allow
4.0
deny
4.0
CRAP 4.4
↑ Summary
1 package WebService::AngelXML::Auth;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use XML::Writer qw{};
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use CGI qw{};
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶ use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 $VERSION = '0.14';
9 }
10  
11 =head1 NAME
12  
13 WebService::AngelXML::Auth - Generates XML Authentication Document for Angel Web service
14  
15 =head1 SYNOPSIS
16  
17 use WebService::AngelXML::Auth;
18 my $ws = WebService::AngelXML::Auth->new();
19 $ws->allow(1) if "test";
20 print $ws->header, $ws->response;
21  
22 =head1 DESCRIPTION
23  
24 WebService::AngelXML::Auth is a Perl object oriented interface that allows for the creation of the XML response required for AngleXML Authentication.
25  
26 =head1 USAGE
27  
28 use WebService::AngelXML::Auth;
29 my $ws=WebService::AngelXML::Auth->new();
30 if ("Some test here") {
31 $ws->allow(1);
32 } else {
33 $ws->deny(1); #default
34 }
35 print $ws->header, $ws->response;
36  
37 =head1 CONSTRUCTOR
38  
39 =head2 new
40  
41 my $ws=WebService::AngelXML::Auth->new(
42 cgi => $query, #pass this if already constructed else will construct
43 allow => 0, #allow and deny are both stored in $ws->{'deny'};
44 deny => 1, #default is deny=1 only set deny=0 if you are permissive
45 mimetype => "text/xml", #default is application/vnd.angle-xml.xml+xml
46 page => "/1000", #default next page is "/1000"
47 );
48  
49 =cut
50  
51 14 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
52 14 my $this = shift();
53 14 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0140
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
54 14 my $self = {};
55 14 bless $self, $class;
56 14 $self->initialize(@_);
57 14 return $self;
58 }
59  
60 =head1 METHODS
61  
62 =cut
63  
64 14 ▶sub initialize {
Subroutine initialize: called CC=11 SCAR=24.0
Pod undocumented
65 14 my $self=shift;
66 14 %$self=@_;
67 14 ▶ $self->allow(delete $self->{'allow'}) if defined $self->{'allow'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"allow"} 2 12 14
68 14 ▶ $self->deny(1) unless defined $self->{'deny'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"deny"} 10 4 14
69 14 ▶ $self->cgi(CGI->new) unless ref($self->cgi) eq 'CGI';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->cgi eq "CGI" 11 3 14
70 14 ▶ $self->mimetype("application/vnd.angle-xml.xml+xml")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->mimetype 13 1 14
71 unless defined $self->mimetype;
72 14 ▶ $self->param_id("id") unless defined $self->param_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->param_id 13 1 14
73 14 ▶ $self->param_pin("pin") unless defined $self->param_pin;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->param_pin 13 1 14
74 14 ▶ $self->param_page("page") unless defined $self->param_page;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->param_page 13 1 14
75 14 ▶ $self->prompt(".") unless defined $self->prompt;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->prompt 13 1 14
76 14 ▶ $self->page(delete $self->{'page'}) if defined $self->{'page'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"page"} 1 13 14
77 14 ▶ $self->page("/1000") unless defined $self->page;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->page 12 2 14
78 }
79  
80 =head2 allow
81  
82 Set or returns the current allow state. Allow and deny methods are inversly related.
83  
84 You may set the allow and deny methods with any value that Perl evaluates to true or false. However, they will always return "-1" for true and "0" for false.
85  
86 if ($ws->allow) { "Do something!" }
87 print $ws->allow; #will always return "-1" for true and "0" for false
88 $ws->allow(0); #will set the allow to "0" and the deny to "-1"
89 $ws->allow(1); #will set the allow to "-1" and the deny to "0"
90  
91 =cut
92  
93 14 ▶sub allow {
Subroutine allow: called CC=4 SCAR=13.9
Pod documented
94 14 my $self=shift;
95 14 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 10 14
96 4 my $value=shift;
97 4 ▶ $self->{'deny'} = $value ? "0" : "-1";
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 2 2 4
98 }
99 14 ▶ return $self->{'deny'} ? "0" : "-1";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'deny'} ? : 8 6 14
100 }
101  
102 =head2 deny
103  
104 Set or returns the current deny state. Allow and deny methods are inversly related.
105  
106 You may set the allow and deny methods with any value that Perl evaluates to true or false. However, they will always return -1 for true and 0 for false.
107  
108 if ($ws->deny) { "Do something!" }
109 print $ws->deny; #will always return -1 for true and 0 for false
110 $ws->deny(0); #will set the deny to "0" and the allow to "-1"
111 $ws->deny(1); #will set the deny to "-1" and the allow to "0"
112  
113 =cut
114  
115 22 ▶sub deny {
Subroutine deny: called CC=4 SCAR=13.9
Pod documented
116 22 my $self=shift;
117 22 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 12 10 22
118 12 my $value=shift;
119 12 ▶ $self->{'deny'} = $value ? "-1" : "0";
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 11 1 12
120 }
121 22 ▶ return $self->{'deny'} ? "-1" : "0";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'deny'} ? : 17 5 22
122 }
123  
124 =head2 response
125  
126 Returns an XML document with an XML declaration and a root name of "ANGELXML"
127  
128 print $ws->response;
129  
130 Example (Deny):
131  
132 <ANGELXML>
133 <MESSAGE>
134 <PLAY>
135 <PROMPT type="text">.</PROMPT>
136 </PLAY>
137 <GOTO destination="/1000" />
138 </MESSAGE>
139 <VARIABLES>
140 <VAR name="status_code" value="-1" />
141 </VARIABLES>
142 </ANGELXML>
143  
144 =cut
145  
146 0 ▶sub response {
Subroutine response: not called CC=1 SCAR=6.9
Pod documented
147 0 my $self=shift;
148 0 my $document='';
149 0 my $writer=XML::Writer->new(OUTPUT=>\$document, DATA_MODE=>1, DATA_INDENT=>2);
150
151 0 $writer->startTag("ANGELXML");
152 0 $writer->startTag("MESSAGE");
153 0 $writer->startTag("PLAY");
154 0 $writer->startTag("PROMPT", type=>"text");
155 0 $writer->characters($self->prompt);
156 0 $writer->endTag("PROMPT");
157 0 $writer->endTag("PLAY");
158 0 $writer->emptyTag("GOTO", destination=>$self->page);
159 0 $writer->endTag("MESSAGE");
160 0 $writer->startTag("VARIABLES");
161 0 $writer->emptyTag("VAR", name=>"status_code", value=>$self->deny);
162 0 $writer->endTag("VARIABLES");
163 0 $writer->endTag("ANGELXML");
164 0 $writer->end();
165 0 return $document;
166 }
167  
168 =head2 header
169  
170 print $document->header;
171  
172 Example:
173  
174 Content-Type: application/vnd.angle-xml.xml+xml
175  
176 =cut
177  
178 0 ▶sub header {
Subroutine header: not called CC=1 SCAR=6.9
Pod documented
179 0 my $self=shift;
180 0 return sprintf("Content-Type: %s\n\n", $self->mimetype);
181 }
182  
183 =head2 mimetype
184  
185 Sets or returns mime type the default is application/vnd.angle-xml.xml+xml
186  
187 $ws->mimetype('text/xml'); #This works better when testing with MSIE
188 my $mt=$ws->mimetype;
189  
190 =cut
191  
192 29 ▶sub mimetype {
Subroutine mimetype: called CC=2 SCAR=6.9
Pod documented
193 29 my $self=shift;
194 29 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 13 16 29
195 13 $self->{'mimetype'}=shift;
196 }
197 29 return $self->{'mimetype'};
198 }
199  
200 =head2 cgi
201  
202 Sets or returns the cgi object which must be CGI from cpan. Default is to construct a new CGI object. If you already have a CGI object, you MUST pass it on construction.
203  
204 $cgi=CGI->new("id=9999;pin=0000;page=/1000");
205 $ws=WebService::AngelXML::Auth->new(cgi=>$cgi);
206  
207 DO NOT do this as we would have already created two CGI objects.
208  
209 $cgi=CGI->new("id=9999;pin=0000;page=/1000"); #a new CGI object is created
210 $ws=WebService::AngelXML::Auth->new(); #a new CGI object is created on initialization
211 $ws->cgi($cgi); #this CGI object may not be iniatialized correctly
212  
213 CGI object is fully functional
214  
215 print $ws->cgi->p("Hello World!"); #All CGI methods are available
216  
217 =cut
218  
219 91 ▶sub cgi {
Subroutine cgi: called CC=3 SCAR=11.0
Pod documented
220 91 my $self=shift;
221 91 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 11 80 91
222 11 my $obj=shift;
223 11 ▶ $self->{'cgi'}=$obj if ref($obj) eq 'CGI';
Branch: 1 branch
BranchTrueFalseTotal
if ref $obj eq "CGI" 11 0 11
224 }
225 91 return $self->{'cgi'};
226 }
227  
228 =head2 id
229  
230 Returns the user id which is passed from the CGI parameter. The default CGI parameter is "id" but can be overriden by the param_id method.
231  
232 print $ws->id;
233 $ws->id("0000"); #if you want to set it for testing.
234  
235 =cut
236  
237 4 ▶sub id {
Subroutine id: called CC=2 SCAR=6.9
Pod documented
238 4 my $self=shift;
239 4 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 3 4
240 1 $self->cgi->param(-name=>$self->param_id, -value=>shift);
241 }
242 4 my $return=$self->cgi->param(-name=>$self->param_id);
243 4 return $return;
244 }
245  
246 =head2 param_id
247  
248 The value of the CGI parameter holding the value of the user id.
249  
250 $ws->param_id("id"); #default
251  
252 =cut
253  
254 33 ▶sub param_id {
Subroutine param_id: called CC=2 SCAR=6.9
Pod documented
255 33 my $self=shift();
256 33 ▶ $self->{'param_id'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 14 19 33
257 33 return $self->{'param_id'};
258 }
259  
260 =head2 pin
261  
262 Returns the user pin which is passed from the CGI parameter. The default CGI parameter is "pin" but can be overriden by the param_pin method.
263  
264 print $ws->pin;
265 $ws->pin("0000"); #if you want to set it for testing.
266  
267 =cut
268  
269 4 ▶sub pin {
Subroutine pin: called CC=2 SCAR=6.9
Pod documented
270 4 my $self=shift;
271 4 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 3 4
272 1 $self->cgi->param(-name=>$self->param_pin, -value=>shift);
273 }
274 4 my $return=$self->cgi->param(-name=>$self->param_pin);
275 4 return $return;
276 }
277  
278 =head2 param_pin
279  
280 The value of the CGI parameter holding the value of the user pin.
281  
282 $ws->param_pin("pin"); #default
283  
284 =cut
285  
286 33 ▶sub param_pin {
Subroutine param_pin: called CC=2 SCAR=6.9
Pod documented
287 33 my $self=shift;
288 33 ▶ $self->{'param_pin'}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 14 19 33
289 33 return $self->{'param_pin'};
290 }
291  
292 =head2 page
293  
294 Returns the authentication next page which can be passed from the POST parameter. See param_page method.
295  
296 Three ways to set next page.
297  
298 $ws=WebService::AngelXML::Auth->new(page=>"/1000"); #during construction
299 $ws->page("/1000"); #after constructing
300 script.cgi?page=/1000 #as cgi parameter
301  
302 =cut
303  
304 33 ▶sub page {
Subroutine page: called CC=2 SCAR=6.9
Pod documented
305 33 my $self=shift;
306 33 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 19 33
307 14 my $value=shift;
308 14 $self->cgi->param(-name=>$self->param_page, -value=>$value);
309 }
310 33 return $self->cgi->param(-name=>$self->param_page);
311 }
312  
313 =head2 param_page
314  
315 The value of the CGI parameter holding the value of the next page.
316  
317 $ws->param_page("page"); #default
318  
319 =cut
320  
321 75 ▶sub param_page {
Subroutine param_page: called CC=2 SCAR=6.9
Pod documented
322 75 my $self=shift;
323 75 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 61 75
324 14 $self->{'param_page'}=shift;
325 }
326 75 return $self->{'param_page'};
327 }
328  
329 =head2 prompt
330  
331 Sets or returns the prompt text.
332  
333 print $ws->prompt;
334 $ws->prompt("."); #default
335  
336 =cut
337  
338 31 ▶sub prompt {
Subroutine prompt: called CC=2 SCAR=6.9
Pod documented
339 31 my $self=shift;
340 31 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 14 17 31
341 14 $self->{'prompt'}=shift;
342 }
343 31 return $self->{'prompt'};
344  
345 }
346  
347 =head1 BUGS
348  
349 =head1 SUPPORT
350  
351 Try Angel first then the author of this package who is not an Angel employee
352  
353 =head1 AUTHOR
354  
355 Michael R. Davis (mrdvt92)
356 CPAN ID: MRDVT
357  
358 =head1 COPYRIGHT
359  
360 Copyright 2008 - STOP, LLC
361 Copyright 2008 - Michael R. Davis (mrdvt92)
362  
363 This program is free software licensed under the...
364  
365 The BSD License
366  
367 The full text of the license can be found in the
368 LICENSE file included with this module.
369  
370 =head1 SEE ALSO
371  
372 L<XML::Writer> is used by this package to generate XML.
373  
374 L<CGI> is used by this package to handle HTTP POST/GET parameters.
375  
376 =cut
377  
378 3 1;
↑ Summary