Client/AuthStorage/ServiceAccount.pm

filter: Statementstmt 48.7% 20 / 41 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 36.3% 4 / 11 Podpod 100% 2 / 2 totaltotal 41.9% 26 / 62 CC 5 SCAR 15.4
CC
5
Cov
41%
refresh_access_token
12.0
__ANON__
6.0
__ANON__
6.0
CRAP 4.7
« Client/Discovery.pm ↑ Summary Client/AuthStorage/GapiJSON.pm »
1 2 ▶use strictures;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package WebService::GoogleAPI::Client::AuthStorage::ServiceAccount;
4  
5 2 our $VERSION = '0.27'; # VERSION
6  
7 # ABSTRACT: Manage access tokens from a service account file
8  
9  
10 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Mojo::JWT::Google;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15 has scopes => is => 'rw',
16 0 ▶ coerce => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
17 0 my $arg = shift;
18 0 ▶ return [ split / /, $arg ] unless ref $arg eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $arg eq "ARRAY" 0 0 0
19 0 return $arg;
20 },
21 0 ▶ default => sub { [] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
22  
23  
24 has user => is => 'rw',
25 0 ▶ coerce => sub { $_[0] || '' },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0] or "" 0 0 0
26 2 default => '';
27  
28 2 with 'WebService::GoogleAPI::Client::AuthStorage';
29  
30  
31 2 has path => is => 'rw',
32 required => 1,
33 trigger => 1;
34  
35 0 ▶sub _trigger_path {
Subroutine _trigger_path: not called CC=1 SCAR=6.9
36 0 my ($self) = @_;
37 0 $self->jwt(Mojo::JWT::Google->new(from_json => $self->path));
38 }
39  
40  
41  
42 2 has jwt => is => 'rw';
43  
44  
45 has tokens => is => 'ro',
46 0 ▶ default => sub { {} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
47  
48  
49 sub get_access_token {
50 my ($self) = @_;
51 my $token = $self->tokens->{ $self->scopes_string }{ $self->user };
52 return $self->refresh_access_token unless $token;
53 return $token;
54 }
55  
56  
57 0 ▶sub refresh_access_token {
Subroutine refresh_access_token: not called CC=3 SCAR=24.8
Pod documented
58 0 my ($self) = @_;
59 0 ▶ croak "Can't get a token without a set of scopes" unless @{ $self->scopes };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->scopes;} 0 0 0
60  
61 0 $self->jwt->scopes($self->scopes);
62 0 ▶ if ($self->user) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->user) { } 0 0 0
63 0 $self->jwt->user_as($self->user);
64 } else {
65 0 $self->jwt->user_as(undef);
66 }
67  
68 0 my $new_token = $self->refresh_service_account_token($self->jwt);
69  
70 0 $self->tokens->{ $self->scopes_string }{ $self->user } = $new_token;
71 0 return $new_token;
72 }
73  
74  
75 0 ▶sub scopes_string {
Subroutine scopes_string: not called CC=1 SCAR=6.9
Pod documented
76 0 my ($self) = @_;
77 0 return join ' ', @{ $self->scopes };
78 }
79  
80  
81 2 9001
82  
83 __END__
« Client/Discovery.pm ↑ Summary Client/AuthStorage/GapiJSON.pm »