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   54 use warnings;
  11         14  
  11         220  
18 11     11   40 use version;
  11         17  
  11         420  
19 11     11   38  
  11         19  
  11         40  
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   487  
  11         27  
  11         330  
24             use Class::Std::Fast;
25 11     11   46 use Encode qw( encode_utf8 decode_utf8 );
  11         112  
  11         74  
26 11     11   5546  
  11         126731  
  11         3309  
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 268 my $customer_id = $self->get_customer_id() || "";
37 3   50     13 my $method = $self->get_method() || "";
38 3   50     24 my $request_id = $self->get_request_id() || "";
39 3   50     40 my $is_fault = $self->get_is_fault() ? "True" : "False";
40 3   50     16 my $fault_message = $self->get_fault_message() || "";
41 3 100       17  
42 3   100     17 # 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         19 my @utf8_chunks = $utf8 =~ /\G(.{1,16000})(?![\x80-\xBF])/sg;
46 3         48 $fault_message = decode_utf8($_) for @utf8_chunks;
47 3         9  
48 3         16 return " Host=${host}" . " ClientCustomerId=${customer_id}" .
49             " Method=${method}" . " RequestId=${request_id}" .
50 3         31 " IsFault=${is_fault}" . " FaultMessage=${fault_message}";
51             }
52              
53 11     11   79 return 1;
  11         18  
  11         69  
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