| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package MooseX::Role::REST::Consumer; | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use MooseX::Role::Parameterized; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use MooseX::Role::REST::Consumer::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use REST::Consumer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Module::Load; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = '0.003'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | my @HTTP_METHODS = qw(get put post delete); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | parameter service_host => ( | |||||||||||||||||||||||||||
| 19 | lazy => 1, | ||||||||||||||||||||||||||||
| 20 | default => '', | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | parameter service_port => (); | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | parameter resource_path => ( | ||||||||||||||||||||||||||||
| 26 | lazy => 1, | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | default => sub { undef }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 28 | 1 | ); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 1 | parameter content_type => ( | |||||||||||||||||||||||||||
| 31 | isa => 'Str', | ||||||||||||||||||||||||||||
| 32 | required => 1, | ||||||||||||||||||||||||||||
| 33 | default => 'application/json', | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | parameter header_exclude => ( | ||||||||||||||||||||||||||||
| 37 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 38 | 8 | ▶ | default => sub {{}}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 1 | ); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | parameter retry => ( | |||||||||||||||||||||||||||
| 42 | required => 1, | ||||||||||||||||||||||||||||
| 43 | default => 0, | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | parameter timeout => ( | |||||||||||||||||||||||||||
| 47 | default => 1, | ||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | parameter query_params_mapping => ( | ||||||||||||||||||||||||||||
| 51 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 52 | 7 | ▶ | default => sub {{}}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 1 | ); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | parameter useragent_class => ( | |||||||||||||||||||||||||||
| 56 | isa => 'Str', | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 8 | ▶ | role { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 60 | 8 | my $p = shift; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 8 | my $service_host = $p->service_host; | |||||||||||||||||||||||||||
| 63 | 8 | my $service_port = $p->service_port; | |||||||||||||||||||||||||||
| 64 | 8 | my $resource_path = $p->resource_path; | |||||||||||||||||||||||||||
| 65 | 8 | my $content_type = $p->content_type; | |||||||||||||||||||||||||||
| 66 | 8 | my $retry = $p->retry; | |||||||||||||||||||||||||||
| 67 | 8 | my $timeout = $p->timeout; | |||||||||||||||||||||||||||
| 68 | 8 | my $query_params_mapping = $p->query_params_mapping; | |||||||||||||||||||||||||||
| 69 | 8 | my $useragent_class = $p->useragent_class; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | #Note: since this is a parametrized role then only one class will be closing | ||||||||||||||||||||||||||||
| 72 | #over this variable and this instance only depends on role parameters | ||||||||||||||||||||||||||||
| 73 | 8 | my $consumer_instance; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | #Note: $class varible in methods of this role can be an instance and a class name | ||||||||||||||||||||||||||||
| 76 | #For GET requests this is usually a class name, for POST requests | ||||||||||||||||||||||||||||
| 77 | #this would usually be an instance. | ||||||||||||||||||||||||||||
| 78 | #Be carefull! | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 13 | ▶ | method 'consumer' => sub { | ||||||||||||||||||||||||||
|
Subroutine
consumer: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||
| 81 | 13 | my ($class) = @_; | |||||||||||||||||||||||||||
| 82 | 13 | ▶ | return $consumer_instance if($consumer_instance); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 7 | my $user_agent; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 7 | ▶ | if($useragent_class) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 1 | Module::Load::load($useragent_class); | |||||||||||||||||||||||||||
| 88 | 0 | $user_agent = $useragent_class->new; | |||||||||||||||||||||||||||
| 89 | }; | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 6 | ▶ | my $client = REST::Consumer->new( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 92 | host => $service_host, | ||||||||||||||||||||||||||||
| 93 | timeout => $timeout, | ||||||||||||||||||||||||||||
| 94 | ($user_agent ? (ua => $user_agent) : ()), | ||||||||||||||||||||||||||||
| 95 | ($service_port ? (port => $service_port) : ()) | ||||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 6 | $client->user_agent->use_eval(0); | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 6 | $consumer_instance = $client; | |||||||||||||||||||||||||||
| 101 | 6 | return $client; | |||||||||||||||||||||||||||
| 102 | 8 | }; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 11 | ▶ | method 'call' => sub { | ||||||||||||||||||||||||||
|
Subroutine
call: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 105 | 11 | my ($class, $method, %params) = @_; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | my %request_headers = $class->request_headers( | ||||||||||||||||||||||||||||
| 108 | header_exclude => $p->header_exclude, | ||||||||||||||||||||||||||||
| 109 | headers => $params{headers}, | ||||||||||||||||||||||||||||
| 110 | 11 | content_type => $p->content_type, | |||||||||||||||||||||||||||
| 111 | method => $method, | ||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 11 | $content_type = delete $request_headers{'Content-Type'}; | |||||||||||||||||||||||||||
| 115 | 11 | ▶ | if ($params{access_token}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 1 | $request_headers{Authorization} = 'Bearer ' . $params{access_token}; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | my %query_params = $class->query_params( | ||||||||||||||||||||||||||||
| 120 | params => $params{params}, | ||||||||||||||||||||||||||||
| 121 | 11 | query_params_mapping => $query_params_mapping, | |||||||||||||||||||||||||||
| 122 | ); | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | my $path = $class->request_path( | ||||||||||||||||||||||||||||
| 125 | resource_path => $resource_path, | ||||||||||||||||||||||||||||
| 126 | route_params => delete $params{route_params}, | ||||||||||||||||||||||||||||
| 127 | path => delete $params{path}, | ||||||||||||||||||||||||||||
| 128 | 11 | ); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 11 | my ($data, $error, $timeout_error) = (undef, '', 0); | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | my %request = ( | ||||||||||||||||||||||||||||
| 133 | params => \%query_params, | ||||||||||||||||||||||||||||
| 134 | content => $params{content}, | ||||||||||||||||||||||||||||
| 135 | 11 | ▶ | path => $path, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | content_type => $content_type, | ||||||||||||||||||||||||||||
| 137 | headers => ( %request_headers ? [ %request_headers ] : undef ), | ||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | #my $logger = $class->get_logger | ||||||||||||||||||||||||||||
| 141 | #$logger->start_request( | ||||||||||||||||||||||||||||
| 142 | # type => $method, | ||||||||||||||||||||||||||||
| 143 | # path => $path, | ||||||||||||||||||||||||||||
| 144 | # response => $data, | ||||||||||||||||||||||||||||
| 145 | # request => \%request | ||||||||||||||||||||||||||||
| 146 | #); | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 11 | my $consumer = $class->consumer; #we want same instance throughout the whole process | |||||||||||||||||||||||||||
| 149 | 10 | ▶ | $consumer->host(delete $params{host}) if $params{host}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 10 | ▶ | if (my $timeout_override = delete $params{timeout} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 1 | $consumer->timeout($timeout_override); | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 10 | my $try = 0; | |||||||||||||||||||||||||||
| 156 | 10 | ▶ | while ($try <= $retry) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 12 | my $is_success; | |||||||||||||||||||||||||||
| 158 | 12 | ▶ | try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 159 | 12 | $try++; | |||||||||||||||||||||||||||
| 160 | 12 | $data = $consumer->$method(%request); | |||||||||||||||||||||||||||
| 161 | 8 | $is_success = 1; | |||||||||||||||||||||||||||
| 162 | 4 | ▶ | } catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 163 | 4 | $error = $_; | |||||||||||||||||||||||||||
| 164 | 4 | ▶ | $timeout_error++ if $error =~ /read timeout/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 12 | }; | |||||||||||||||||||||||||||
| 166 | 12 | ▶ | last if $is_success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 10 | $consumer->timeout($timeout); | |||||||||||||||||||||||||||
| 170 | 10 | $consumer->host($service_host); | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | #$logger->finish($log_entry, { | ||||||||||||||||||||||||||||
| 173 | # type => $method, | ||||||||||||||||||||||||||||
| 174 | # path => $path, | ||||||||||||||||||||||||||||
| 175 | # response => $data, | ||||||||||||||||||||||||||||
| 176 | # request => \%request | ||||||||||||||||||||||||||||
| 177 | #}); | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | # TODO: It's confusing as to how we handle errors. | ||||||||||||||||||||||||||||
| 180 | # ie: message should be called "error_message" and | ||||||||||||||||||||||||||||
| 181 | # we should inspect the response content for possible error messages | ||||||||||||||||||||||||||||
| 182 | 10 | return MooseX::Role::REST::Consumer::Response->new( | |||||||||||||||||||||||||||
| 183 | data => $data, | ||||||||||||||||||||||||||||
| 184 | is_success => !$error, | ||||||||||||||||||||||||||||
| 185 | error_message => "$error", | ||||||||||||||||||||||||||||
| 186 | request => $consumer->last_request, | ||||||||||||||||||||||||||||
| 187 | content_type => $content_type, | ||||||||||||||||||||||||||||
| 188 | response => $consumer->last_response, | ||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||
| 190 | 8 | }; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | # Note: REST::Consumer doesn't support OPTIONS/PATCH | ||||||||||||||||||||||||||||
| 193 | 8 | for my $method ( @HTTP_METHODS ) { | |||||||||||||||||||||||||||
| 194 | 11 | ▶ | method $method => sub { | ||||||||||||||||||||||||||
|
Subroutine
post: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 195 | 11 | my $class = shift; | |||||||||||||||||||||||||||
| 196 | 11 | $class->call($method, @_); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | 32 | } | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 11 | ▶ | method 'request_headers' => sub { | ||||||||||||||||||||||||||
|
Subroutine
request_headers: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||
| 201 | 11 | my ($class, %params) = @_; | |||||||||||||||||||||||||||
| 202 | 11 | ▶ | my %request_headers = ($params{headers} ? %{delete $params{headers}} : ()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | # Strange mutation going on here: | ||||||||||||||||||||||||||||
| 204 | # 1. First we set the content_type in the headers if we have one set in parameter definition | ||||||||||||||||||||||||||||
| 205 | # 2. However, we won't override anything that is passed explicitly into a method call Class->post | ||||||||||||||||||||||||||||
| 206 | # 3. Next we delete anything that needs to be removed from the header | ||||||||||||||||||||||||||||
| 207 | # 4. Finally we explicltly pull out content-type from the request_headers | ||||||||||||||||||||||||||||
| 208 | # to make REST::Consumer happy | ||||||||||||||||||||||||||||
| 209 | 11 | ▶ | $request_headers{'Content-Type'} = $params{content_type} unless $request_headers{'Content-Type'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | 0 | ▶ | delete @request_headers{@{$params{header_exclude}->{$params{method}}}} if $params{header_exclude}->{$params{method}}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | 11 | return %request_headers; | |||||||||||||||||||||||||||
| 212 | 8 | }; | |||||||||||||||||||||||||||
| 213 | 22 | ▶ | method 'request_path' => sub { | ||||||||||||||||||||||||||
|
Subroutine
request_path: called CC=12 SCAR=25.3
| |||||||||||||||||||||||||||||
| 214 | 22 | my ($class, %params) = @_; | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 22 | my $resource_path = $params{resource_path}; | |||||||||||||||||||||||||||
| 217 | 22 | my $route_params = $params{route_params}; | |||||||||||||||||||||||||||
| 218 | 22 | my $params_path = $params{path}; | |||||||||||||||||||||||||||
| 219 | 22 | ▶ | my @path = (defined $resource_path ? $resource_path : ()); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 22 | ▶ | if($params_path) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 222 | 9 | ▶ | if(ref($params_path) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 0 | push(@path, @$params_path); | |||||||||||||||||||||||||||
| 224 | } else { | ||||||||||||||||||||||||||||
| 225 | 9 | push(@path, $params_path); | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | 22 | ▶ | my $path = File::Spec->catfile(@path) . ( $resource_path && $resource_path =~ m{[^/]+/$} ? '/' : ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$resource_path and $resource_path =~ m[[^/]+/$]
MC/DC50%1/2
$resource_path and $resource_path =~ m[[^/]+/$]
$resource_path
$resource_path =~ m[[^/]+/$]
Truth table66%2/3
A and B
A= $resource_pathB= $resource_path =~ m[[^/]+/$]
| |||||||||||||||||||||||||||||
| 229 | #We support two ways of substituting params here: | ||||||||||||||||||||||||||||
| 230 | # /:param/ - name has to have '/' or end of string after it | ||||||||||||||||||||||||||||
| 231 | # /has_:{param}_value - surround param name with '{}' | ||||||||||||||||||||||||||||
| 232 | #Note: we go through complete incremental parsing/fetching url params to avoid | ||||||||||||||||||||||||||||
| 233 | #params substituted values being mached against other params names | ||||||||||||||||||||||||||||
| 234 | #We also verify that all parameters have been substituted | ||||||||||||||||||||||||||||
| 235 | 22 | my $result = ''; | |||||||||||||||||||||||||||
| 236 | 22 | ▶ | while($path =~ /\G(.*?)(:(?:\{([^}]+?)\}|(\w+)(?=\W|$)))/gc) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | 19 | $result .= $1; | |||||||||||||||||||||||||||
| 238 | 19 | ▶ | if($2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | 19 | ▶ | my $name = $3 || $4; # only one of them could match | ||||||||||||||||||||||||||
|
Condition66%2/3
$3 || $4
MC/DC0%0/2
$3 || $4
$3
$4
Truth table66%2/3
A || B
A= $3B= $4
| |||||||||||||||||||||||||||||
| 240 | 19 | ▶ | if(exists $route_params->{$name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | 18 | ▶ | $result .= URI::Escape::uri_escape_utf8($route_params->{$name} // ''); | ||||||||||||||||||||||||||
|
Condition50%1/2
$route_params->{$name} // ""
MC/DC0%0/1
$route_params->{$name} // ""
$route_params->{$name}
Truth table50%1/2
A
A= $route_params->{$name}
| |||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | else { | ||||||||||||||||||||||||||||
| 244 | 1 | die "Found parameter $name in path but it wasn't set in parameters hash"; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||
| 248 | 21 | ▶ | if($path =~ /\G(.+)$/g) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | 17 | $result .= $1; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | 21 | return $result; | |||||||||||||||||||||||||||
| 252 | 8 | }; | |||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 11 | ▶ | method 'query_params' => sub { | ||||||||||||||||||||||||||
|
Subroutine
query_params: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||
| 255 | 11 | my ($class, %params) = @_; | |||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 11 | my %query_params; | |||||||||||||||||||||||||||
| 258 | 11 | ▶ | if($params{params}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | # TODO: I don't think having this strict mapping in place | ||||||||||||||||||||||||||||
| 260 | # makes a lot of sense. Ideally we should be able to pass in | ||||||||||||||||||||||||||||
| 261 | # any query params that we want | ||||||||||||||||||||||||||||
| 262 | 1 | ▶ | if ( $params{query_params_mapping} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 1 | ▶ | while(my ($name, $url_name) = each(%{$params{query_params_mapping}})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | # Check for method canness here probably | ||||||||||||||||||||||||||||
| 265 | 1 | $query_params{$url_name} = delete($params{params}->{$name}); | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | } else { | ||||||||||||||||||||||||||||
| 268 | 0 | %query_params = %{$params{params}}; | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | 11 | return %query_params; | |||||||||||||||||||||||||||
| 272 | 8 | }; | |||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 0 | ▶ | method 'parameters' => sub { $p }; | ||||||||||||||||||||||||||
|
Subroutine
parameters: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 1 | }; | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | __END__ | ||||||||||||||||||||||||||||