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
|
|
|
|
|
|
|
# This module provides utility methods to other services. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use strict; |
19
|
10
|
|
|
10
|
|
57
|
use warnings; |
|
10
|
|
|
|
|
24
|
|
|
10
|
|
|
|
|
235
|
|
20
|
10
|
|
|
10
|
|
44
|
use version; |
|
10
|
|
|
|
|
32
|
|
|
10
|
|
|
|
|
219
|
|
21
|
10
|
|
|
10
|
|
347
|
|
|
10
|
|
|
|
|
1369
|
|
|
10
|
|
|
|
|
50
|
|
22
|
|
|
|
|
|
|
# The following needs to be on one line because CPAN uses a particularly hacky |
23
|
|
|
|
|
|
|
# eval() to determine module versions. |
24
|
|
|
|
|
|
|
use Google::Ads::GoogleAds::Constants; our $VERSION = ${Google::Ads::GoogleAds::Constants::VERSION}; |
25
|
10
|
|
|
10
|
|
905
|
|
|
10
|
|
|
|
|
86
|
|
|
10
|
|
|
|
|
374
|
|
26
|
|
|
|
|
|
|
use Exporter::Auto; |
27
|
10
|
|
|
10
|
|
4354
|
use Storable qw(dclone); |
|
10
|
|
|
|
|
84153
|
|
|
10
|
|
|
|
|
80
|
|
28
|
10
|
|
|
10
|
|
1629
|
|
|
10
|
|
|
|
|
5490
|
|
|
10
|
|
|
|
|
5447
|
|
29
|
|
|
|
|
|
|
# Deletes the unassigned fields in the hash reference. |
30
|
|
|
|
|
|
|
my ($hash_ref, $args) = @_; |
31
|
|
|
|
|
|
|
delete @{$hash_ref}{grep { not exists $args->{$_} } keys %$hash_ref}; |
32
|
36
|
|
|
36
|
1
|
2228
|
} |
33
|
36
|
|
|
|
|
171
|
|
|
36
|
|
|
|
|
144
|
|
|
1117
|
|
|
|
|
1263
|
|
34
|
|
|
|
|
|
|
# Checks whether the scripts parameters are not the "INSERT_..._HERE" values. |
35
|
|
|
|
|
|
|
my (@params) = @_; |
36
|
|
|
|
|
|
|
foreach my $param (@params) { |
37
|
|
|
|
|
|
|
if (ref $param eq "ARRAY") { |
38
|
9
|
|
|
9
|
1
|
627
|
return 0 if !(@$param && check_params(@$param)); |
39
|
9
|
|
|
|
|
14
|
} elsif (!defined $param || $param =~ /INSERT_.*_HERE/) { |
40
|
14
|
100
|
100
|
|
|
84
|
return 0; |
|
|
100
|
|
|
|
|
|
41
|
3
|
100
|
100
|
|
|
15
|
} |
42
|
|
|
|
|
|
|
} |
43
|
4
|
|
|
|
|
30
|
return 1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
10
|
# Removes the leading and trailing spaces and line breaks from a string. |
47
|
|
|
|
|
|
|
my $str = shift; |
48
|
|
|
|
|
|
|
return $str if !defined $str; |
49
|
|
|
|
|
|
|
$str =~ s/^\s*(.*?)\s*$/$1/; |
50
|
|
|
|
|
|
|
return $str; |
51
|
2
|
|
|
2
|
1
|
4
|
} |
52
|
2
|
100
|
|
|
|
7
|
|
53
|
1
|
|
|
|
|
9
|
# Expands a path template by replacing the parameters in braces with the given |
54
|
1
|
|
|
|
|
4
|
# arguments. |
55
|
|
|
|
|
|
|
my ($path_template, $args) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# To support the {+customers} format template. |
58
|
|
|
|
|
|
|
$path_template =~ s/\{\+/\{/g; |
59
|
|
|
|
|
|
|
|
60
|
38
|
|
|
38
|
1
|
66
|
if (not ref $args) { |
61
|
|
|
|
|
|
|
$path_template =~ s/\{\w+}/$args/ if defined $args; |
62
|
|
|
|
|
|
|
} elsif (ref $args eq "ARRAY") { |
63
|
38
|
|
|
|
|
87
|
$path_template =~ s/\{\w+}/shift @$args if @$args/eg; |
64
|
|
|
|
|
|
|
} else { |
65
|
38
|
100
|
|
|
|
107
|
$path_template =~ s/\{(\w+)}/delete $args->{$1} if exists $args->{$1}/eg; |
|
|
100
|
|
|
|
|
|
66
|
3
|
100
|
|
|
|
11
|
} |
67
|
|
|
|
|
|
|
|
68
|
32
|
100
|
|
|
|
155
|
return $path_template; |
|
72
|
|
|
|
|
311
|
|
69
|
|
|
|
|
|
|
} |
70
|
3
|
50
|
|
|
|
18
|
|
|
3
|
|
|
|
|
26
|
|
71
|
|
|
|
|
|
|
# Copies a hash reference to a new object. |
72
|
|
|
|
|
|
|
my ($original) = shift; |
73
|
38
|
|
|
|
|
167
|
return undef if !$original; |
74
|
|
|
|
|
|
|
return dclone($original); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Converts a string to lower underscore case. |
78
|
2
|
|
|
2
|
1
|
2803
|
my $str = shift; |
79
|
2
|
100
|
|
|
|
28
|
return $str if !defined $str; |
80
|
1
|
|
|
|
|
71
|
$str =~ |
81
|
|
|
|
|
|
|
s/(?:\b|(?<=([a-z])))([A-Z][a-z]+)/(defined($1) ? "_" : "") . lc($2)/eg; |
82
|
|
|
|
|
|
|
return $str; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
72
|
|
|
72
|
1
|
90
|
# Converts a scalar to boolean string. |
86
|
72
|
100
|
|
|
|
141
|
shift ? "true" : "false"; |
87
|
71
|
|
|
|
|
316
|
} |
88
|
53
|
100
|
|
|
|
186
|
|
89
|
71
|
|
|
|
|
161
|
# Dies with a specified exit code. |
90
|
|
|
|
|
|
|
my $exit_code = shift; |
91
|
|
|
|
|
|
|
$! = $exit_code; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
die @_; |
94
|
5
|
100
|
|
5
|
1
|
25
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=pod |
99
|
1
|
|
|
1
|
1
|
2
|
|
100
|
1
|
|
|
|
|
2
|
=head1 NAME |
101
|
|
|
|
|
|
|
|
102
|
1
|
|
|
|
|
11
|
Google::Ads::GoogleAds::Utils::GoogleAdsHelper |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 DESCRIPTION |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This module provides utility methods to other services. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 METHODS |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 remove_unassigned_fields |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Removes the fields not presenting in the constructor arguments from a newly created |
113
|
|
|
|
|
|
|
Google Ads API entity. These fields will be excluded when encoding the JSON HTTP |
114
|
|
|
|
|
|
|
request payload. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head3 Parameters |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=over |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
I<hash_ref>: a hash reference to the newly created Google Ads API entity. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
I<args>: the arguments for the constructor of a Google Ads API entity. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=back |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 check_params |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Checks whether the parameters in the code sample are correctly specified. The |
133
|
|
|
|
|
|
|
values can either be set in the source code or passed in from the command line. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head3 Parameters |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=over |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
I<params>: an array of parameters in the code sample to verify. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=back |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head3 Returns |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
True, if all the parameters are correctly specified. False, otherwise. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 trim |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Removes the leading and trailing spaces and line breaks from a string. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head3 Parameters |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=over |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
The original input string. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head3 Returns |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
The trimmed string without leading and trailing white spaces. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head2 expand_path_template |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Expands a path template by replacing the parameters in braces with the given |
170
|
|
|
|
|
|
|
arguments. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head3 Parameters |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=over |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
I<path_template>: the path template to expand. The format could be: |
179
|
|
|
|
|
|
|
'customers/{customer_id}/adGroups/{ad_group_id}' or |
180
|
|
|
|
|
|
|
'v11/customers/{+customerId}/adGroups:mutate'. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
I<args>: the args in scalar or array/hash reference used to expand the template. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=back |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head3 Returns |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
The expanded path template. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head2 copy_from |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Copies a hash reference deeply to a new object. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head3 Parameters |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=over |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item * |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
I<original>: the original hash reference to copy from. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=back |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head3 Returns |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
A deeply copied object based on the C<original> hash reference. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=head2 to_lower_underscore |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Converts a string to lower underscore case. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head3 Parameters |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=over |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item * |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
The original input string. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=back |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head3 Returns |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
The result string in lower underscore case. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head2 to_boolean |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Converts a scalar to boolean string. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head3 Parameters |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=over |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=item * |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
The original input scalar value. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=back |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head3 Returns |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
"true" if the input value is valid. "false", otherwise. |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head2 die_with_code |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Dies with a specified exit code. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head3 Parameters |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=over |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item * |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
I<exit_code>: the exit code. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=item * |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
I<list>: list of one or more items, which will be stringified and concatenated |
261
|
|
|
|
|
|
|
to make the exception. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=back |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Copyright 2019 Google LLC |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); |
270
|
|
|
|
|
|
|
you may not use this file except in compliance with the License. |
271
|
|
|
|
|
|
|
You may obtain a copy of the License at |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0 |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software |
276
|
|
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, |
277
|
|
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
278
|
|
|
|
|
|
|
See the License for the specific language governing permissions and |
279
|
|
|
|
|
|
|
limitations under the License. |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head1 REPOSITORY INFORMATION |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
$Rev: $ |
284
|
|
|
|
|
|
|
$LastChangedBy: $ |
285
|
|
|
|
|
|
|
$Id: $ |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=cut |