Plugin/AtomServer.pm

filter: Statementstmt 20.6% 12 / 58 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 50.0% 4 / 8 Podpod 0.0% 0 / 1 totaltotal 15.8% 16 / 101 CC 15 SCAR 35.0
CC
15
Cov
14%
finalize_error
72.0
finalize
20.0
body_parsed
12.0
CRAP 33.3
↑ Summary Plugin/Authentication/Credential/Atom.pm »
1 # $Id: AtomServer.pm 1257 2006-06-27 17:07:05Z btrott $
2  
3 package Catalyst::Plugin::AtomServer;
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 our $VERSION = '0.04';
7  
8 ## todo:
9 ## dispatching based on request method?
10  
11 2 ▶use Catalyst::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use NEXT;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use XML::Atom;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 {
16 package Catalyst::Request;
17 __PACKAGE__->mk_accessors(qw( url_parameters is_atom is_soap
18 _body_parsed ));
19  
20 0 ▶ sub body_parsed {
Subroutine body_parsed: not called CC=3 SCAR=24.8
Pod undocumented
21 0 my $req = shift;
22 0 ▶ unless ($req->_body_parsed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($req->_body_parsed) 0 0 0
23 0 my $doc;
24 0 ▶ if (XML::Atom->LIBXML) {
Branch: 1 branch
BranchTrueFalseTotal
if ('XML::Atom'->LIBXML) { } 0 0 0
25 0 my $parser = XML::LibXML->new;
26 0 $doc = $parser->parse_file($req->body);
27 } else {
28 0 $doc = XML::XPath->new(filename => $req->body);
29 }
30 0 $req->_body_parsed($doc);
31 }
32 0 $req->_body_parsed;
33 }
34 }
35  
36 0 ▶sub prepare {
Subroutine prepare: not called CC=3 SCAR=24.8
37 0 my $class = shift;
38 0 my $c = $class->NEXT::prepare(@_);
39 0 my $req = $c->request;
40  
41 ## Extract parameters from URI path info.
42 0 my $param = {};
43 0 for my $pair (@{ $req->arguments }) {
44 0 my($k, $v) = split /=/, $pair, 2;
45 0 $param->{$k} = $v;
46 }
47 0 $req->url_parameters($param);
48  
49 ## If the request has a SOAP wrapper, unwrap it.
50 0 ▶ if (my $action = $req->header('SOAPAction')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $action = $req->header("SOAPAction")) 0 0 0
51 0 $req->is_soap(1);
52 0 $action =~ s/"//g;
53 0 my($method) = $action =~ /\/([^\/]+)$/;
54 0 $req->method($method);
55 }
56  
57 0 $c;
58 }
59  
60 0 ▶sub finalize {
Subroutine finalize: not called CC=4 SCAR=30.0
61 0 my $c = shift;
62 0 ▶ unless ($c->request->is_atom) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->request->is_atom) 0 0 0
63 0 return $c->NEXT::finalize(@_);
64 }
65 0 my $res = $c->response;
66 0 ▶ if ($c->request->is_soap && (my $body = $res->body)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->request->is_soap and my $body = $res->body) 0 0 0
Condition0%0/3
$c->request->is_soap and my $body = $res->body
!ll&&!rl&&r
000
MC/DC0%0/2
$c->request->is_soap and my $body = $res->body
$c->request->is_soap my $body = $res->body
Truth table0%0/3
A and B
A= $c->request->is_soapB= my $body = $res->body
ABresult
0X0
100
111
67 0 $body =~ s/^(<\?xml.*?\?>)//;
68 0 $body = <<SOAP;
69 $1
70 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
71 <soap:Body>$body</soap:Body>
72 </soap:Envelope>
73 SOAP
74 0 $res->body($body);
75 }
76 0 $c->NEXT::finalize(@_);
77 }
78  
79 0 ▶sub finalize_error {
Subroutine finalize_error: not called CC=8 SCAR=42.8
80 0 my $c = shift;
81 0 ▶ unless ($c->request->is_atom) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c->request->is_atom) 0 0 0
82 0 return $c->NEXT::finalize_error(@_);
83 }
84 0 ▶ if (defined(my $err = $c->error->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $err = $c->error->[0])) 0 0 0
85 0 my $res = $c->response;
86 0 my $status = $res->status;
87 0 ▶ if ($c->request->is_soap || !$status || $status == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->request->is_soap or not $status or $status == 200) 0 0 0
Condition0%0/6
$c->request->is_soap or not $status or $status == 200
l!l&&r!l&&!r
000
$c->request->is_soap or not $status
l!l&&r!l&&!r
000
MC/DC0%0/3
$c->request->is_soap or not $status or $status == 200
$c->request->is_soap not $status $status == 200
Truth table0%0/4
A or not(B) or C
A= $c->request->is_soapB= not $statusC= $status == 200
ABCresult
1XX1
01X1
0011
0000
88 0 $res->status(500);
89 0 $status = $res->status;
90 }
91 0 ▶ my $body = UNIVERSAL::can($err, 'message') ? $err->message : $err;
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::can($err, 'message') ? : 0 0 0
92 0 ▶ if ($c->request->is_soap) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->request->is_soap) { } 0 0 0
93 0 $res->body(<<FAULT);
94 <?xml version="1.0" encoding="utf-8"?>
95 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
96 <soap:Body>
97 <soap:Fault>
98 <faultcode>$status</faultcode>
99 <faultstring>$body</faultstring>
100 </soap:Fault>
101 </soap:Body>
102 </soap:Envelope>
103 FAULT
104 } else {
105 0 $res->body(<<XML);
106 <?xml version="1.0" encoding="utf-8"?>
107 <error>$body</error>
108 XML
109 }
110 }
111 }
112  
113 1;
114 __END__
↑ Summary Plugin/Authentication/Credential/Atom.pm »