| 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.007'); | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my ($orig, $class, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | my $args | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | = !@args ? {} | ||||||||||||||||||||||||||||||||||||||||||
| 21 | : @args == 1 ? $args[0] | ||||||||||||||||||||||||||||||||||||||||||
| 22 | : {@args}; | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | if ( blessed $args | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
builtin::blessed($args) and $args->isa("HTTP::Request") || $args->isa("HTTP::Response")
$args->isa("HTTP::Request") or $args->isa("HTTP::Response")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my @query = $uri->query_form; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | while ( my $key = shift @query ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _map_fields { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_map_fields: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$super ne __PACKAGE__ and UNIVERSAL::can($super, "_map_fields")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _get_headers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_headers: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | next if !$attr->style eq 'header'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $has = 'has_' . $name; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | next if !$self->$has; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $headers{$attr->real_name} = $self->$name; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return %headers; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $urlencode = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $url = shift; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $url =~ s/(\W)/sprintf('%%%x',ord($1))/eg; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return $url; | |||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | sub _get_query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_query: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | next if !$attr->style eq 'query'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | my $has = 'has_' . $name; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | next if !$self->$has; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||||||||||||||||