File Coverage

blib/lib/Google/Ads/GoogleAds/Logging/SummaryStats.pm
Criterion Covered Total %
statement 33 33 100.0
branch 2 2 100.0
condition 6 10 60.0
subroutine 8 8 100.0
pod 0 1 0.0
total 49 54 90.7


line stmt bran cond sub pod time code
1             # Copyright 2019, Google LLC
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              
16             use strict;
17 11     11   73 use warnings;
  11         20  
  11         281  
18 11     11   51 use version;
  11         19  
  11         238  
19 11     11   47  
  11         27  
  11         50  
20             # The following needs to be on one line because CPAN uses a particularly hacky
21             # eval() to determine module versions.
22             use Google::Ads::GoogleAds::Constants; our $VERSION = ${Google::Ads::GoogleAds::Constants::VERSION};
23 11     11   751  
  11         19  
  11         487  
24             use Class::Std::Fast;
25 11     11   82 use Encode qw( encode_utf8 decode_utf8 );
  11         17  
  11         82  
26 11     11   7027  
  11         136767  
  11         3356  
27             my %host_of : ATTR(:name<host> :default<>);
28             my %customer_id_of : ATTR(:name<customer_id> :default<>);
29             my %method_of : ATTR(:name<method> :default<>);
30             my %request_id_of : ATTR(:name<request_id> :default<>);
31             my %is_fault_of : ATTR(:name<is_fault> :default<0>);
32             my %fault_message_of : ATTR(:name<fault_message> :default<>);
33              
34             my $self = shift;
35             my $host = $self->get_host() || "";
36 3     3 0 240 my $customer_id = $self->get_customer_id() || "";
37 3   50     7 my $method = $self->get_method() || "";
38 3   50     21 my $request_id = $self->get_request_id() || "";
39 3   50     15 my $is_fault = $self->get_is_fault() ? "True" : "False";
40 3   50     15 my $fault_message = $self->get_fault_message() || "";
41 3 100       15  
42 3   100     15 # Convert the fault message to one less than 16K characters.
43             $fault_message =~ s/\r?\n/ /g;
44             my $utf8 = encode_utf8($fault_message);
45 3         17 my @utf8_chunks = $utf8 =~ /\G(.{1,16000})(?![\x80-\xBF])/sg;
46 3         42 $fault_message = decode_utf8($_) for @utf8_chunks;
47 3         9  
48 3         13 return " Host=${host}" . " ClientCustomerId=${customer_id}" .
49             " Method=${method}" . " RequestId=${request_id}" .
50 3         27 " IsFault=${is_fault}" . " FaultMessage=${fault_message}";
51             }
52              
53 11     11   81 return 1;
  11         18  
  11         60  
54              
55             =pod
56              
57             =head1 NAME
58              
59             Google::Ads::GoogleAds::Logging::SummaryStats
60              
61             =head1 DESCRIPTION
62              
63             Class that wraps API request statistics such as client customer ID, request id,
64             API method and others.
65              
66             =head1 ATTRIBUTES
67              
68             =head2 host
69              
70             The Google Ads API server endpoint.
71              
72             =head2 customer_id
73              
74             The client customer id against which the API call was made.
75              
76             =head2 method
77              
78             The name of the service method that was called.
79              
80             =head2 request_id
81              
82             Request id of the call.
83              
84             =head2 is_fault
85              
86             Whether the request returned as a fault or not.
87              
88             =head2 fault_message
89              
90             The stack trace of up to 16K characters if a fault occurs.
91              
92             =head1 LICENSE AND COPYRIGHT
93              
94             Copyright 2019 Google LLC
95              
96             Licensed under the Apache License, Version 2.0 (the "License");
97             you may not use this file except in compliance with the License.
98             You may obtain a copy of the License at
99              
100             http://www.apache.org/licenses/LICENSE-2.0
101              
102             Unless required by applicable law or agreed to in writing, software
103             distributed under the License is distributed on an "AS IS" BASIS,
104             WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
105             See the License for the specific language governing permissions and
106             limitations under the License.
107              
108             =head1 REPOSITORY INFORMATION
109              
110             $Rev: $
111             $LastChangedBy: $
112             $Id: $
113              
114             =cut