lib/Google/Ads/Common/Utilities/AdsUtilityRegistry.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 4 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 12 / 12 Podpod 100% 2 / 2 totaltotal 96.8% 62 / 64 CC 5 SCAR 5.6
CC
5
Cov
98%
get_and_reset_ads_utility_registry_string
3.0
add_ads_utilities
3.0
BEGIN
1.0
CRAP 1.8
« lib/Google/Ads/Common/MediaUtils.pm ↑ Summary lib/Google/Ads/AdWords/v201809/TypeMaps/AccountLabelService.pm »
1 # Copyright 2016, 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 # Description: This is a global object that maintains a registry of the
16 # utilities that have recently been used. This registry of utilities is
17 # primarily collected to be put in the userAgent of the header when a
18 # request is sent. The registry is cleared every time the string representation
19 # of the registry is retrieved.
20  
21 package Google::Ads::Common::Utilities::AdsUtilityRegistry;
22  
23 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 # The following needs to be on one line because CPAN uses a particularly hacky
29 # eval() to determine module versions.
30 3 ▶use Google::Ads::AdWords::Constants; our $VERSION = ${Google::Ads::AdWords::Constants::VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
31 3 ▶use Google::Ads::AdWords::Logging;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 3 ▶use Class::Std::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 3 ▶use Log::Log4perl qw(:levels);
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 # The Mapping of utility class names to a generic name used by all the client
37 # libraries. This string will be passed into the user agent.
38 2 our %ADS_UTILITIES = (
39 BatchJobHandler => "BatchJobHelper",
40 LoggingEnabled => "Logging/Enabled",
41 LoggingDisabled => "Logging/Disabled",
42 PageProcessor => "PageProcessor",
43 ReportDownloaderFile => "ReportDownloader/file",
44 ReportDownloaderStream => "ReportDownloader/stream",
45 ReportDownloaderString => "ReportDownloader/string",
46 ReportQueryBuilder => "ReportQueryBuilder",
47 ServiceQueryBuilder => "ServiceQueryBuilder"
48 );
49  
50 {
51 # This is a globally static variable.
52 2 my %ads_utility_registry = ();
53  
54 # Add one or more utilities to the utility registry.
55 # Example:
56 # Google::Ads::Common::Utilities::AdsUtilityRegistry->add_ads_utilities(
57 # "ReportDownloaderStream");
58 15 ▶ sub add_ads_utilities {
Subroutine add_ads_utilities: called CC=3 SCAR=11.0
Pod documented
59 16 my ($class, @params) = @_;
60 # Verify that the value passed is a key in %ADS_UTILITIES. Don't continue
61 # if the value passed in is incorrect. Avoid duplicates with a hash.
62 16 foreach my $param (@params) {
63 17 ▶ if (exists $ADS_UTILITIES{$param}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Google::Ads::Common::Utilities::AdsUtilityRegistry::ADS_UTILITIES{$param}) { } 15 1 16
64 16 $ads_utility_registry{$ADS_UTILITIES{$param}} = $ADS_UTILITIES{$param};
65 } else {
66 2 die sprintf("Parameter incorrect: %s\nChoose from values(s): %s",
67 $param, join(", ", (keys %ADS_UTILITIES)));
68 }
69 }
70 }
71  
72 # Get the list of non-repeated utilities sorted in alphabetical order.
73 8 ▶ sub __get_ads_utilities {
Subroutine __get_ads_utilities: called CC=1 SCAR=0.0
74 8 return sort (keys %ads_utility_registry);
75 }
76  
77 # Reset the registry of ads utilities.
78 8 ▶ sub __reset_ads_utilities {
Subroutine __reset_ads_utilities: called CC=1 SCAR=0.0
79 8 %ads_utility_registry = ();
80 }
81  
82 # This method returns an alphabetical, comma-separated string of non-repeated
83 # ads utilities currently registered.
84 # This method also clears the utility registry.
85 8 ▶ sub get_and_reset_ads_utility_registry_string {
Subroutine get_and_reset_ads_utility_registry_string: called CC=3 SCAR=11.0
Pod documented
86 # Update the logging status.
87 8 ▶ my $log_utility =
Branch: 1 branch
BranchTrueFalseTotal
!Google::Ads::AdWords::Logging::get_awapi_logger()->level || Google::Ads::AdWords::Logging::get_awapi_logger()->level == $Google::Ads::Common::Utilities::AdsUtilityRegistry::OFF ? : 7 1 8
Condition66%2/3
not Google::Ads::AdWords::Logging::get_awapi_logger()->level or Google::Ads::AdWords::Logging::get_awapi_logger()->level == $Google::Ads::Common::Utilities::AdsUtilityRegistry::OFF
l!l&&r!l&&!r
071
MC/DC50%1/2
not Google::Ads::AdWords::Logging::get_awapi_logger()->level or Google::Ads::AdWords::Logging::get_awapi_logger()->level == $Google::Ads::Common::Utilities::AdsUtilityRegistry::OFF
not Google::Ads::AdWords::Logging::get_awapi_logger()->level Google::Ads::AdWords::Logging::get_awapi_logger()->level == $Google::Ads::Common::Utilities::AdsUtilityRegistry::OFF
Truth table66%2/3
not(A) or B
A= not Google::Ads::AdWords::Logging::get_awapi_logger()->levelB= Google::Ads::AdWords::Logging::get_awapi_logger()->level == $Google::Ads::Common::Utilities::AdsUtilityRegistry::OFF
ABresult
1X1
011
000
88 ( !Google::Ads::AdWords::Logging::get_awapi_logger()->level()
89 || Google::Ads::AdWords::Logging::get_awapi_logger()->level() == $OFF)
90 ? "LoggingDisabled"
91 : "LoggingEnabled";
92 8 Google::Ads::Common::Utilities::AdsUtilityRegistry->add_ads_utilities(
93 $log_utility);
94  
95 # Retrieve the list and reset the utilities registry.
96 8 my @utilities = __get_ads_utilities();
97 8 __reset_ads_utilities();
98 8 return join(", ", @utilities);
99 }
100 }
101  
102 2 1;
103  
104 =pod
105  
106 =head1 NAME
107  
108 Google::Ads::Common::Utilities::AdsUtilityRegsitry
109  
110 =head1 DESCRIPTION
111  
112 This is a global object that maintains a registry of the utilities that have
113 recently been used. This registry of utilities is primarily collected to be put
114 in the userAgent of the header when a request is sent. The registry is cleared
115 every time the string representation of the registry is retrieved.
116  
117 =head2 PROPERTIES
118  
119 The following properties may be accessed using get_PROPERTY methods:
120  
121 =head1 METHODS
122  
123 =head2 add_ads_utilities
124  
125 Add one or more utilities to the utility registry. The possible values passed
126 in are in the keys of
127 Google::Ads::Common::Utilities::AdsUtilityRegistry::ADS_UTILITIES. The method
128 will error if one of the values passed in is incorrect.
129 Example:
130 Google::Ads::Common::Utilities::AdsUtilityRegistry->add_ads_utilities(
131 "ReportDownloaderStream");
132  
133 =head3 Parameters
134  
135 =over
136  
137 =item *
138  
139 One or more strings representing ad utilities. These strings can be found in
140 the keys of Google::Ads::Common::Utilities::AdsUtilityRegistry::ADS_UTILITIES.
141  
142 =back
143  
144 =head2 __get_ads_utilities
145  
146 (Private) This method returns the list of non-repeated ads utilities in
147 alphabetical order. Possible values can be found in the values of
148 Google::Ads::Common::Utilities::AdsUtilityRegistry::ADS_UTILITIES.
149  
150 =head3 Returns
151  
152 An array of non-repeated utilities that have been added via add_ads_utilities in
153 alphabetic order. Possible values can be found in the values of
154 Google::Ads::Common::Utilities::AdsUtilityRegistry::ADS_UTILITIES.
155  
156 =head2 __reset_ads_utilities
157  
158 (Private) This method clears the registry of ads utilities.
159  
160 =head2 get_and_reset_ads_utility_registry_string
161  
162 This method returns an alphabetical, comma-separated string of non-repeated ads
163 utilities currently registered.
164 This method also clears the registry of ads utilities.
165  
166 =head3 Returns
167  
168 Returns an alphabetical, comma-separated string of non-repeated ads utilities
169 currently registered.
170  
171 =cut
« lib/Google/Ads/Common/MediaUtils.pm ↑ Summary lib/Google/Ads/AdWords/v201809/TypeMaps/AccountLabelService.pm »