File Coverage

lib/Google/Ads/AdWords/RequestStats.pm
Criterion Covered Total %
statement 18 33 54.5
branch 0 2 0.0
condition 0 16 0.0
subroutine 6 7 85.7
pod 0 1 0.0
total 24 59 40.6


line stmt bran cond sub pod time code
1             # Copyright 2012, Google Inc. All Rights Reserved.
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::Ads::AdWords::RequestStats;
16              
17 2     2   1398 use strict;
  2         6  
  2         66  
18 2     2   18 use warnings;
  2         6  
  2         59  
19 2     2   8 use version;
  2         3  
  2         14  
20 2     2   493 use Encode qw( encode_utf8 decode_utf8 );
  2         8008  
  2         138  
21              
22 2     2   15 use Class::Std::Fast;
  2         3  
  2         19  
23              
24             my %client_id_of : ATTR(:name :default<>);
25             my %service_name_of : ATTR(:name :default<>);
26             my %method_name_of : ATTR(:name :default<>);
27             my %response_time_of : ATTR(:name :default<0>);
28             my %request_id_of : ATTR(:name :default<>);
29             my %operations_of : ATTR(:name :default<0>);
30             my %is_fault_of : ATTR(:name :default<0>);
31             my %server_of : ATTR(:name :default<>);
32             my %fault_message_of : ATTR(:name :default<>);
33              
34             sub as_str : STRINGIFY {
35 0     0 0   my $self = shift;
36 0   0       my $client_id = $self->get_client_id() || "";
37 0   0       my $server = $self->get_server() || "";
38 0   0       my $service = $self->get_service_name() || "";
39 0   0       my $method = $self->get_method_name() || "";
40 0   0       my $response_time = $self->get_response_time() || "";
41 0   0       my $request_id = $self->get_request_id() || "";
42 0   0       my $operations = $self->get_operations() || "";
43 0 0         my $is_fault = $self->get_is_fault() ? "yes" : "no";
44 0   0       my $fault_message = $self->get_fault_message() || "";
45              
46             # Convert the fault message to one less than 16K characters.
47 0           $fault_message =~ s/\r?\n/ /g;
48 0           my $utf8 = encode_utf8($fault_message);
49 0           my @utf8_chunks = $utf8 =~ /\G(.{1,16000})(?![\x80-\xBF])/sg;
50 0           $fault_message = decode_utf8($_) for @utf8_chunks;
51              
52 0           return " clientCustomerId=${client_id}" . " server=${server}" .
53             " service=${service}" . " method=${method}" .
54             " responseTime=${response_time}" . " requestId=${request_id}" .
55             " operations=${operations}" . " isFault=${is_fault}" .
56             " faultMessage=${fault_message}";
57 2     2   931 }
  2         5  
  2         14  
58              
59             return 1;
60              
61             =pod
62              
63             =head1 NAME
64              
65             Google::Ads::AdWords::RequestStats
66              
67             =head1 SYNOPSIS
68              
69             Class that wraps API request statistics such as number of operations,
70             request id and others.
71              
72             =head1 DESCRIPTION
73              
74             This class holds the data coming from API response headers and others related
75             to a given request.
76              
77             =head1 ATTRIBUTES
78              
79             =head2 client_id
80              
81             The client id against which the call was made if available.
82              
83             =head2 server
84              
85             The server endpoint.
86              
87             =head2 service_name
88              
89             The name of the service that was called.
90              
91             =head2 method_name
92              
93             The method name of the service that was called.
94              
95             =head2 response_time
96              
97             Server side time of the duration of the call.
98              
99             =head2 request_id
100              
101             Request id of the call.
102              
103             =head2 operations
104              
105             Number of operations in the request.
106              
107             =head2 is_fault
108              
109             Whether the request returned as a fault or not.
110              
111             =head2 fault_message
112              
113             The stack trace of up to 16K characters if a fault occurs.
114              
115             =head1 LICENSE AND COPYRIGHT
116              
117             Copyright 2012 Google Inc.
118              
119             Licensed under the Apache License, Version 2.0 (the "License");
120             you may not use this file except in compliance with the License.
121             You may obtain a copy of the License at
122              
123             http://www.apache.org/licenses/LICENSE-2.0
124              
125             Unless required by applicable law or agreed to in writing, software
126             distributed under the License is distributed on an "AS IS" BASIS,
127             WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128             See the License for the specific language governing permissions and
129             limitations under the License.
130              
131             =head1 REPOSITORY INFORMATION
132              
133             $Rev: $
134             $LastChangedBy: $
135             $Id: $
136              
137             =cut