| 1 | package Google::API::Method; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use URI::Escape qw/uri_escape/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | my (%param) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | for my $required (qw/ua json_parser base_url opt doc/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | die unless $param{$required}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | bless { %param }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | sub execute { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my $url = $self->{base_url} . $self->{doc}{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my $http_method = uc($self->{doc}{httpMethod}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my %required_param; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | for my $p (@{$self->{doc}{parameterOrder}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | $required_param{$p} = delete $self->{opt}{$p}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ($self->{opt}{body} && $self->{opt}{body}{$p}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"opt"}{"body"} and $self->{"opt"}{"body"}{$p}
MC/DC0%0/2
$self->{"opt"}{"body"} and $self->{"opt"}{"body"}{$p}
$self->{"opt"}{"body"}
$self->{"opt"}{"body"}{$p}
Truth table0%0/3
A and B
A= $self->{"opt"}{"body"}B= $self->{"opt"}{"body"}{$p}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | $required_param{$p} = delete $self->{opt}{body}{$p}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $url =~ s/{([^}]+)}/uri_escape(delete $required_param{$1})/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $uri = URI->new($url); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ($http_method eq 'POST' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/9
$http_method eq "POST" or $http_method eq "PUT" or $http_method eq "PATCH" or $http_method eq "DELETE"
$http_method eq "POST" or $http_method eq "PUT" or $http_method eq "PATCH"
$http_method eq "POST" or $http_method eq "PUT"
MC/DC0%0/4
$http_method eq "POST" or $http_method eq "PUT" or $http_method eq "PATCH" or $http_method eq "DELETE"
$http_method eq "POST"
$http_method eq "PUT"
$http_method eq "PATCH"
$http_method eq "DELETE"
Truth table0%0/5
A or B or C or D
A= $http_method eq "POST"B= $http_method eq "PUT"C= $http_method eq "PATCH"D= $http_method eq "DELETE"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | $http_method eq 'PUT' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | $http_method eq 'PATCH' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | $http_method eq 'DELETE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $uri->query_form(\%required_param); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $request = HTTP::Request->new($http_method => $uri); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ($self->{opt}{body}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $request->content_type('application/json'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $request->content($self->{json_parser}->encode($self->{opt}{body})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $request->content_length(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } elsif ($http_method eq 'GET') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my $body = $self->{opt}{body} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'opt'}{'body'} || {}
MC/DC0%0/1
$self->{'opt'}{'body'} || {}
$self->{'opt'}{'body'}
Truth table0%0/2
A
A= $self->{'opt'}{'body'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my %q = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | %required_param, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | %$body, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($arg->{key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $q{key} = $arg->{key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $uri->query_form(\%q); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $request = HTTP::Request->new($http_method => $uri); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($arg->{auth_driver}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | $request->header('Authorization', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | sprintf "%s %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | $arg->{auth_driver}->token_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $arg->{auth_driver}->access_token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $response = $self->{ua}->request($request); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ($response->code == 401 && $arg->{auth_driver}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response->code == 401 and $arg->{"auth_driver"}
MC/DC0%0/2
$response->code == 401 and $arg->{"auth_driver"}
$response->code == 401
$arg->{"auth_driver"}
Truth table0%0/3
A and B
A= $response->code == 401B= $arg->{"auth_driver"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $arg->{auth_driver}->refresh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | $request->header('Authorization', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | sprintf "%s %s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | $arg->{auth_driver}->token_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $arg->{auth_driver}->access_token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $response = $self->{ua}->request($request); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | unless ($response->is_success) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $self->_die_with_error($response); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($response->code == 204) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | return $response->header('content-type') =~ m!^application/json! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | ? $self->{json_parser}->decode(decode_utf8($response->content)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | : $response->content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | sub _die_with_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | my ($self, $response) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_die_with_error: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my $err_str = $response->status_line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ($response->content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$response->content and $response->header("content-type") =~ m[^application/json]
MC/DC0%0/2
$response->content and $response->header("content-type") =~ m[^application/json]
$response->content
$response->header("content-type") =~ m[^application/json]
Truth table0%0/3
A and B
A= $response->contentB= $response->header("content-type") =~ m[^application/json]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | && $response->header('content-type') =~ m!^application/json!) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $content = $self->{json_parser}->decode(decode_utf8($response->content)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $err_str = "$err_str: $content->{error}{message}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | die $err_str; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||