blib/lib/W3C/SOAP/WADL/Element.pm

filter: Statementstmt 25.6% 19 / 74 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 50.0% 5 / 10 Podpod n/a totaltotal 18.4% 24 / 130 CC 24 SCAR 42.7
CC
24
Cov
17%
__ANON__
156.0
_get_query
42.0
_get_headers
30.0
CRAP 71.5
« blib/lib/W3C/SOAP/WADL.pm ↑ Summary blib/lib/W3C/SOAP/WADL/Parser.pm »
1 package W3C::SOAP::WADL::Element;
2  
3 # Created on: 2013-04-27 21:58:42
4 # Create by: Ivan Wills
5 # $Id$
6 # $Revision$, $HeadURL$, $Date$
7 # $Revision$, $Source$, $Date$
8  
9 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Carp qw/carp croak cluck confess longmess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Data::Dumper qw/Dumper/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 our $VERSION = version->new('0.006');
16  
17 around BUILDARGS => sub {
18 0 ▶ my ($orig, $class, @args) = @_;
Subroutine __ANON__: not called CC=12 SCAR=50.5
19 0 ▶ my $args
Branch: 2 branches
BranchTrueFalseTotal
!@args ? : 0 0 0
@args == 1 ? : 0 0 0
20 = !@args ? {}
21 : @args == 1 ? $args[0]
22 : {@args};
23  
24 0 ▶ if ( blessed $args
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($args) and $args->isa("HTTP::Request") || $args->isa("HTTP::Response")) 0 0 0
Condition0%0/6
builtin::blessed($args) and $args->isa("HTTP::Request") || $args->isa("HTTP::Response")
!ll&&!rl&&r
000
$args->isa("HTTP::Request") or $args->isa("HTTP::Response")
l!l&&r!l&&!r
000
MC/DC0%0/3
builtin::blessed($args) and $args->isa("HTTP::Request") || $args->isa("HTTP::Response")
builtin::blessed($args) $args->isa("HTTP::Request") $args->isa("HTTP::Response")
Truth table0%0/4
A and B or C
A= builtin::blessed($args)B= $args->isa("HTTP::Request")C= $args->isa("HTTP::Response")
ABCresult
0XX0
1000
11X1
1011
25 && ( $args->isa('HTTP::Request') || $args->isa('HTTP::Response') )
26 ) {
27 0 my $http = $args;
28 0 ▶ my $uri = $http->can('uri') ? $http->uri : undef;
Branch: 1 branch
BranchTrueFalseTotal
$http->can('uri') ? : 0 0 0
29 0 $args = {};
30  
31 0 my %map = $class->_map_fields;
32  
33 # process headers
34 0 for my $header ( $http->header_field_names ) {
35 0 ▶ if ( $map{$header} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($map{$header}) { } 0 0 0
elsif ($map{lc $header}) { } 0 0 0
36 0 $args->{ $map{$header} } = $http->header($header);
37 }
38 elsif ( $map{lc $header} ) {
39 0 $args->{ $map{lc $header} } = $http->header($header);
40 }
41 else {
42 0 $args->{$header} = $http->header($header);
43 }
44 }
45  
46 # process URI params
47 0 ▶ if ( $uri ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri) 0 0 0
48 0 my @query = $uri->query_form;
49 0 ▶ while ( my $key = shift @query ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $key = shift @query) 0 0 0
50 0 my $value = shift @query;
51 # TODO make work with multiple values
52 0 $args->{ $map{$key} } = $value;
53 }
54 }
55 }
56  
57 0 return $class->$orig($args);
58 1 };
59  
60 sub _map_fields {
61 0 ▶ my ($self) = @_;
Subroutine _map_fields: not called CC=4 SCAR=30.0
62 0 my $meta = $self->meta;
63  
64 0 my @parent_nodes;
65 0 my @supers = $meta->superclasses;
66 0 for my $super (@supers) {
67 0 ▶ push @parent_nodes, $super->_map_fields
Branch: 1 branch
BranchTrueFalseTotal
if $super ne __PACKAGE__ and UNIVERSAL::can($super, "_map_fields") 0 0 0
Condition0%0/3
$super ne __PACKAGE__ and UNIVERSAL::can($super, "_map_fields")
!ll&&!rl&&r
000
MC/DC0%0/2
$super ne __PACKAGE__ and UNIVERSAL::can($super, "_map_fields")
$super ne __PACKAGE__ UNIVERSAL::can($super, "_map_fields")
Truth table0%0/3
A and B
A= $super ne __PACKAGE__B= UNIVERSAL::can($super, "_map_fields")
ABresult
0X0
100
111
68 if $super ne __PACKAGE__ && UNIVERSAL::can($super, '_map_fields');
69 }
70  
71 return @parent_nodes, map {
72 0 $meta->get_attribute($_)->real_name => $_,
73 lc $meta->get_attribute($_)->real_name => $_
74 }
75 grep {
76 0 $meta->get_attribute($_)->does('W3C::SOAP::WADL::Traits')
77 }
78 $meta->get_attribute_list;
79 }
80  
81 sub _get_headers {
82 0 ▶ my ($self) = @_;
Subroutine _get_headers: not called CC=5 SCAR=34.0
83 0 my $meta = $self->meta;
84 0 my %headers;
85  
86 0 for my $name ( $meta->get_attribute_list ) {
87 0 my $attr = $meta->get_attribute($name);
88 0 ▶ next if !$attr->does('W3C::SOAP::WADL');
Branch: 1 branch
BranchTrueFalseTotal
unless $attr->does("W3C::SOAP::WADL") 0 0 0
89 0 ▶ next if !$attr->style eq 'header';
Branch: 1 branch
BranchTrueFalseTotal
if !$attr->style eq "header" 0 0 0
90  
91 0 my $has = 'has_' . $name;
92 0 ▶ next if !$self->$has;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->$has 0 0 0
93  
94 0 $headers{$attr->real_name} = $self->$name;
95 }
96  
97 0 return %headers;
98 }
99  
100 my $urlencode = sub {
101 0 ▶ my $url = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
102 0 $url =~ s/(\W)/sprintf('%%%x',ord($1))/eg;
103 0 return $url;
104 1 };
105 sub _get_query {
106 0 ▶ my ($self) = @_;
Subroutine _get_query: not called CC=6 SCAR=37.4
107 0 my $meta = $self->meta;
108 0 my %query;
109  
110 0 for my $name ( $meta->get_attribute_list ) {
111 0 my $attr = $meta->get_attribute($name);
112 0 ▶ next if !$attr->does('W3C::SOAP::WADL');
Branch: 1 branch
BranchTrueFalseTotal
unless $attr->does("W3C::SOAP::WADL") 0 0 0
113 0 ▶ next if !$attr->style eq 'query';
Branch: 1 branch
BranchTrueFalseTotal
if !$attr->style eq "query" 0 0 0
114  
115 0 my $has = 'has_' . $name;
116 0 ▶ next if !$self->$has;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->$has 0 0 0
117  
118 0 $query{ $urlencode->( $attr->real_name )} = $urlencode->( $self->$name );
119 0 $query{$attr->real_name} = $self->$name;
120 }
121  
122 0 ▶ return wantarray ? %query : join '&', map { "$_=$query{$_}"} keys %query;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
123 }
124  
125 1 1;
126  
127 __END__
128  
129 =head1 NAME
130  
131 W3C::SOAP::WADL::Element - Provides ability to map inputted request object to response object.
132  
133 =head1 VERSION
134  
135 This documentation refers to W3C::SOAP::WADL::Element version 0.006.
136  
137 =head1 SYNOPSIS
138  
139 use W3C::SOAP::WADL::Element;
140  
141 # Brief but working code example(s) here showing the most common usage(s)
142 # This section will be as far as many users bother reading, so make it as
143 # educational and exemplary as possible.
144  
145  
146 =head1 DESCRIPTION
147  
148 Has a builder the will convert a HTTP request object to the WADL object.
149  
150 =head1 SUBROUTINES/METHODS
151  
152 =head1 DIAGNOSTICS
153  
154 =head1 CONFIGURATION AND ENVIRONMENT
155  
156 =head1 DEPENDENCIES
157  
158 =head1 INCOMPATIBILITIES
159  
160 =head1 BUGS AND LIMITATIONS
161  
162 There are no known bugs in this module.
163  
164 Please report problems to Ivan Wills (ivan.wills@gmail.com).
165  
166 Patches are welcome.
167  
168 =head1 AUTHOR
169  
170 Ivan Wills - (ivan.wills@gmail.com)
171  
172 =head1 LICENSE AND COPYRIGHT
173  
174 Copyright (c) 2013 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077).
175 All rights reserved.
176  
177 This module is free software; you can redistribute it and/or modify it under
178 the same terms as Perl itself. See L<perlartistic>. This program is
179 distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
180 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
181 PARTICULAR PURPOSE.
182  
183 =cut
« blib/lib/W3C/SOAP/WADL.pm ↑ Summary blib/lib/W3C/SOAP/WADL/Parser.pm »