WADL.pm

filter: Statementstmt 30.8% 25 / 81 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 70.0% 7 / 10 Podpod n/a totaltotal 20.5% 32 / 156 CC 27 SCAR 56.4
CC
27
Cov
19%
_request
462.0
_get_method
56.0
_get_uri
2.0
CRAP 280.6
↑ Summary WADL/Element.pm »
1 package W3C::SOAP::WADL;
2  
3 # Created on: 2013-04-20 13:30:57
4 # Create by: Ivan Wills
5 # $Id$
6 # $Revision$, $HeadURL$, $Date$
7 # $Revision$, $Source$, $Date$
8  
9 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Data::Dumper qw/Dumper/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use TryCatch;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use JSON qw/decode_json/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 extends 'W3C::SOAP::Client';
18  
19 3 our $VERSION = version->new('0.007');
20  
21 3 has _response => (
22 is => 'rw',
23 isa => 'Any',
24 );
25  
26 0 ▶sub _request {
Subroutine _request: not called CC=21 SCAR=61.4
27 0 my ( $self, $method_name, @params ) = @_;
28 0 my $method = $self->_get_method($method_name);
29  
30 0 my $uri = $self->_get_uri($method);
31 0 my $http_request = HTTP::Request->new( $method->method, $uri );
32 0 ▶ my $request = $method->has_request ? $method->request : '';
Branch: 1 branch
BranchTrueFalseTotal
$method->has_request ? : 0 0 0
33 0 ▶ if ( $request ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request) 0 0 0
34  
35 # build the request object
36 0 my $object = $request->new(@params);
37  
38 # split the object into its components
39 # Headers
40 0 my %headers = $object->_get_headers;
41 0 for my $header ( keys %headers ) {
42 0 $http_request->header( $header, $headers{$header} );
43 }
44  
45 # GET or body parameters
46 0 ▶ if ( $method->method eq 'GET' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method->method eq 'GET') { } 0 0 0
47 0 $http_request->uri( $uri . '?' . $object->_get_query );
48 }
49 else {
50 0 $http_request->content( scalar $object->_get_query );
51 }
52 }
53  
54 0 my $ua = $self->ua;
55 0 my $response = $method->response;
56  
57 0 $self->clear_response;
58 0 my $http_response = $ua->request( $http_request );
59 0 $self->response($http_response);
60  
61 0 ▶ if ( !$response->{ $http_response->code } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$response{$http_response->code}) 0 0 0
62 0 my $msg = "Unknown response code '" . $http_response->code . "'!\n";
63 0 ▶ $self->log->error($msg) if $self->has_log;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_log 0 0 0
64 0 confess $msg;
65 }
66  
67 0 ▶ if ( !$response->{ $http_response->code } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$response{$http_response->code}) 0 0 0
68 # unhandled codes
69 0 ▶ $self->log->error( "Unknown response code '" . $http_response->code . "'!\n" ) if $self->has_log;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_log 0 0 0
70 0 confess "Unknown response code '" . $http_response->code . "'!\n";
71 }
72  
73 0 my $res_class = $response->{ $http_response->code };
74 0 my $object = $res_class->new( $http_response );
75 0 $self->_response($object);
76  
77 0 my $content = $http_response->content;
78 0 ▶ if ( $object->has_representations ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->has_representations) 0 0 0
79 0 my $type = lc $http_response->headers->content_type;
80 0 my $rep = $object->_representations->{$type};
81  
82 0 ▶ if ( $rep ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rep) 0 0 0
83  
84 # Do any parsing of content
85 0 ▶ if ( $rep->{parser} && ref $rep->{parser} eq 'CODE' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($rep->{'parser'} and ref $rep->{'parser'} eq 'CODE') { } 0 0 0
elsif ($type eq 'application/json') { } 0 0 0
elsif ($type eq 'text/xml' or $type eq 'application/xml') { } 0 0 0
elsif ($type eq 'x-application-urlencoded' or $type eq 'application/x-www-form-urlencoded' or $type eq 'multipart/form-data') { } 0 0 0
Condition0%0/3
$rep->{"parser"} and ref $rep->{"parser"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
$rep->{"parser"} and ref $rep->{"parser"} eq "CODE"
$rep->{"parser"} ref $rep->{"parser"} eq "CODE"
Truth table0%0/3
A and B
A= $rep->{"parser"}B= ref $rep->{"parser"} eq "CODE"
ABresult
0X0
100
111
86 # custom user defined parser
87 0 $content = $rep->{parser}->( $content );
88 }
89 elsif ( $type eq 'application/json' ) {
90 # process JSON
91 0 $content = decode_json($content);
92 }
93 ▶ elsif ( $type eq 'text/xml' || $type eq 'application/xml' ) {
Condition0%0/3
$type eq "text/xml" or $type eq "application/xml"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "text/xml" or $type eq "application/xml"
$type eq "text/xml" $type eq "application/xml"
Truth table0%0/3
A or B
A= $type eq "text/xml"B= $type eq "application/xml"
ABresult
1X1
011
000
94 # get xml element object
95 0 $content = XML::LibXML->load_xml( string => $content );
96 }
97 ▶ elsif (
Condition0%0/6
$type eq "x-application-urlencoded" or $type eq "application/x-www-form-urlencoded" or $type eq "multipart/form-data"
l!l&&r!l&&!r
000
$type eq "x-application-urlencoded" or $type eq "application/x-www-form-urlencoded"
l!l&&r!l&&!r
000
MC/DC0%0/3
$type eq "x-application-urlencoded" or $type eq "application/x-www-form-urlencoded" or $type eq "multipart/form-data"
$type eq "x-application-urlencoded" $type eq "application/x-www-form-urlencoded" $type eq "multipart/form-data"
Truth table0%0/4
A or B or C
A= $type eq "x-application-urlencoded"B= $type eq "application/x-www-form-urlencoded"C= $type eq "multipart/form-data"
ABCresult
1XX1
01X1
0011
0000
98 $type eq 'x-application-urlencoded'
99 || $type eq 'application/x-www-form-urlencoded'
100 || $type eq 'multipart/form-data'
101 ) {
102 # get a form element object
103 0 $content = { map { (split /=/, $_) } split /&/, $content };
104 }
105  
106 # if the content should be inflated to a particular class, do so
107 0 ▶ if ( $rep->{class} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rep->{"class"}) 0 0 0
108 0 my $class = $rep->{class};
109 0 $content = $class->new($content);
110 }
111 }
112 }
113  
114 0 ▶ return wantarray ? ( $content, $object ) : $content;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
115 }
116  
117 0 ▶sub _get_uri {
Subroutine _get_uri: not called CC=1 SCAR=6.9
118 0 my ($self, $method) = @_;
119  
120 0 my $uri = $self->location;
121 0 $uri =~ s{/$}{};
122 0 $uri .= '/' . $method->path;
123  
124 0 return $uri;
125 }
126  
127 0 ▶sub _get_method {
Subroutine _get_method: not called CC=7 SCAR=40.3
128 0 my ($self, $name) = @_;
129  
130 0 my $method = $self->meta->get_method($name);
131 0 ▶ return $method if $method && $method->meta->name eq 'W3C::SOAP::WADL::Meta::Method';
Branch: 1 branch
BranchTrueFalseTotal
if $method and $method->meta->name eq "W3C::SOAP::WADL::Meta::Method" 0 0 0
Condition0%0/3
$method and $method->meta->name eq "W3C::SOAP::WADL::Meta::Method"
!ll&&!rl&&r
000
MC/DC0%0/2
$method and $method->meta->name eq "W3C::SOAP::WADL::Meta::Method"
$method $method->meta->name eq "W3C::SOAP::WADL::Meta::Method"
Truth table0%0/3
A and B
A= $methodB= $method->meta->name eq "W3C::SOAP::WADL::Meta::Method"
ABresult
0X0
100
111
132  
133 0 for my $super ( $self->meta->superclasses ) {
134 0 ▶ next unless $super->can('_get_method');
Branch: 1 branch
BranchTrueFalseTotal
unless $super->can("_get_method") 0 0 0
135 0 $method = $super->_get_method($name);
136 0 ▶ return $method if $method && $method->meta->name eq 'W3C::SOAP::WADL::Meta::Method';
Branch: 1 branch
BranchTrueFalseTotal
if $method and $method->meta->name eq "W3C::SOAP::WADL::Meta::Method" 0 0 0
Condition0%0/3
$method and $method->meta->name eq "W3C::SOAP::WADL::Meta::Method"
!ll&&!rl&&r
000
MC/DC0%0/2
$method and $method->meta->name eq "W3C::SOAP::WADL::Meta::Method"
$method $method->meta->name eq "W3C::SOAP::WADL::Meta::Method"
Truth table0%0/3
A and B
A= $methodB= $method->meta->name eq "W3C::SOAP::WADL::Meta::Method"
ABresult
0X0
100
111
137 }
138  
139 0 confess "Could not find any methods called $name in $self!";
140 }
141  
142 3 1;
143  
144 __END__
↑ Summary WADL/Element.pm »