| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my $doc; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | if (XML::Atom->LIBXML) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$c->request->is_soap and my $body = $res->body
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | return $c->NEXT::finalize_error(@_); | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if (defined(my $err = $c->error->[0])) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$c->request->is_soap or not $status or $status == 200
$c->request->is_soap or not $status
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ($c->request->is_soap) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||