blib/lib/Google/Auth/Exceptions.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 2 totaltotal 88.4% 46 / 52 CC 3 SCAR 4.6
CC
3
Cov
92%
throw
3.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« blib/lib/Google/Auth/IDTokens.pm ↑ Summary blib/lib/Google/Auth/Stores/TokenStore.pm »
1 # Copyright 2022 Google LLC and contributors
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14  
15 package Google::Auth::Exceptions;
16  
17 18 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 =head1 NAME
22  
23 Google::Auth::Exceptions - Exception classes used by Google::Auth
24  
25 =head1 VERSION
26  
27 Version 0.15
28  
29 =head1 SYNOPSIS
30  
31 use Google::Auth::Exceptions;
32  
33 eval {
34 Google::Auth::DefaultCredentialsError->throw('No credentials found');
35 };
36 if (my $err = $@) {
37 if (ref($err) && $err->isa('Google::Auth::DefaultCredentialsError')) {
38 warn "ADC lookup failed: $err\n";
39 }
40 }
41  
42 =head1 DESCRIPTION
43  
44 C<Google::Auth::Exceptions> defines the structured exception hierarchy thrown
45 by L<Google::Auth> and its credential providers. All exception classes inherit
46 from C<Google::Auth::Error> and overload stringification (C<"">) to return
47 their C<message> attribute.
48  
49 =head1 EXCEPTION CLASSES
50  
51 =over 4
52  
53 =item C<Google::Auth::Error>
54  
55 Base exception class. Provides C<message> (read-only string), C<to_string()>,
56 and C<throw($message)>.
57  
58 =item C<Google::Auth::TransportError>
59  
60 Subclasses C<Google::Auth::Error>. Thrown when an underlying HTTP transport
61 request fails.
62  
63 =item C<Google::Auth::RefreshError>
64  
65 Subclasses C<Google::Auth::Error>. Thrown when refreshing an OAuth 2.0 access
66 token or ID token fails.
67  
68 =item C<Google::Auth::DefaultCredentialsError>
69  
70 Subclasses C<Google::Auth::Error>. Thrown by
71 L<Google::Auth::DefaultCredentials> when Application Default Credentials
72 cannot be located in the environment.
73  
74 =back
75  
76 =cut
77  
78 # Base class for all google.auth errors
79  
80 package Google::Auth::Error;
81 18 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 18 ▶use overload '""' => \&to_string, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 18 has message => (is => 'ro', required => 1);
85  
86 19 ▶sub to_string {
Subroutine to_string: called CC=1 SCAR=0.0
Pod undocumented
87 19 my ($self) = @_;
88 19 return $self->message;
89 }
90  
91 18 ▶sub throw {
Subroutine throw: called CC=3 SCAR=12.0
Pod undocumented
92 18 my ($class, $message) = @_;
93 18 ▶ if (ref $class) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 0 18 18
94 0 die $class;
95 }
96 18 ▶ my $self = $class->new({message => $message || 'Unknown error'});
Condition50%1/2
$message || 'Unknown error'
l!l
180
MC/DC0%0/1
$message || 'Unknown error'
$message
Truth table50%1/2
A
A= $message
Aresult
11
00
97 18 die $self;
98 }
99  
100 # Used to indicate an error occurred during an HTTP request
101 #[%- Perl::Critic::Policy::Modules::ProhibitMultiplePackages %]
102 package Google::Auth::TransportError;
103 18 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
104 18 extends 'Google::Auth::Error';
105  
106 # Used to indicate failure to refresh the credentials' access token
107 #[%- Perl::Critic::Policy::Modules::ProhibitMultiplePackages %]
108 package Google::Auth::RefreshError;
109 18 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
110 18 extends 'Google::Auth::Error';
111  
112 # Used to indicate failure to acquire default credentials
113 #[%- Perl::Critic::Policy::Modules::ProhibitMultiplePackages %]
114 package Google::Auth::DefaultCredentialsError;
115 18 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
116 18 extends 'Google::Auth::Error';
117  
118 =head1 AUTHOR
119  
120 C.J. Collier, C<< <cjac at google.com> >>
121  
122 =head1 BUGS AND SUPPORT
123  
124 Please report any bugs or feature requests to the GitHub issue tracker at
125 L<https://github.com/GoogleCloudPlatform/google-auth-library-perl/issues> or via RT at
126 L<https://rt.cpan.org/Dist/Display.html?Name=Google-Auth>.
127  
128 You can also look for information at:
129  
130 =over 4
131  
132 =item * GitHub Issue Tracker
133  
134 L<https://github.com/GoogleCloudPlatform/google-auth-library-perl/issues>
135  
136 =item * RT: CPAN's Request Tracker
137  
138 L<https://rt.cpan.org/Dist/Display.html?Name=Google-Auth>
139  
140 =item * MetaCPAN
141  
142 L<https://metacpan.org/release/Google-Auth>
143  
144 =back
145  
146  
147 =head1 ACKNOWLEDGEMENTS
148  
149  
150 =head1 LICENSE AND COPYRIGHT
151  
152 Copyright 2020 Google LLC and contributors
153  
154 This program is released under the following license: Apache 2.0
155  
156  
157 =cut
158  
159 18 1; # End of Google::Auth::Exceptions
« blib/lib/Google/Auth/IDTokens.pm ↑ Summary blib/lib/Google/Auth/Stores/TokenStore.pm »