lib/Google/Ads/Common/MapUtils.pm

filter: Statementstmt 60.0% 18 / 30 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 64.1% 25 / 39 CC 3 SCAR 11.7
CC
3
Cov
60%
get_map
6.0
build_api_map
6.0
BEGIN
1.0
CRAP 3.2
« lib/Google/Ads/AdWords/Logging.pm ↑ Summary lib/Google/Ads/AdWords/OAuth2ApplicationsHandler.pm »
1 # Copyright 2011, 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::Common::MapUtils;
16  
17 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # The following needs to be on one line because CPAN uses a particularly hacky
22 # eval() to determine module versions.
23 1 ▶use Google::Ads::Common::Constants; our $VERSION = ${Google::Ads::Common::Constants::VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 our @EXPORT_OK = qw(get_map build_api_map);
28  
29 # Gets a map (associative array) from an array of map entries. A map entry is
30 # any object that has a key and value field.
31 0 ▶sub get_map($) {
Subroutine get_map: not called CC=2 SCAR=17.9
Pod documented
32 0 my $map_entries = $_[0];
33 0 my %result = ();
34 0 foreach my $map_entry (@{$map_entries}) {
35 0 $result{$map_entry->get_key()} = $map_entry->get_value();
36 }
37 0 return \%result;
38 }
39  
40 0 ▶sub build_api_map {
Subroutine build_api_map: not called CC=2 SCAR=17.9
Pod documented
41 0 my $map = shift;
42  
43 0 my @result = ();
44 0 foreach my $key (keys %{$map}) {
45 0 push @result, {key => $key, value => $map->{$key}};
46 }
47  
48 0 return \@result;
49 }
50  
51 1 return 1;
52  
53 =pod
54  
55 =head1 NAME
56  
57 Google::Ads::Common::MapUtils
58  
59 =head1 SYNOPSIS
60  
61 use Google::Ads::Common::MapUtils;
62  
63 my $map_entries = Google::Ads::Common::MapUtils::get_map($map_xml);
64 # Make use of $map_entries.
65  
66 =head1 DESCRIPTION
67  
68 A collection of utility methods for working with maps (associative arrays).
69  
70 =head1 SUBROUTINES
71  
72 =head2 get_map
73  
74 Gets a map (associative array) from an array of map entries. A map entry is any
75 object that has a key and value field.
76  
77 =head3 Parameters
78  
79 An array of map entries.
80  
81 =head3 Returns
82  
83 A map built from the keys and values of the map entries.
84  
85 =head2 build_api_map
86  
87 Builds an API map as defined in the WSDLs, which is really a list of key-value
88 maps from a given native Perl map.
89  
90 =head3 Parameters
91  
92 A native Perl map to be translated to "map" as expected by the API.
93  
94 =head3 Returns
95  
96 A list of maps in which each map represents an entry of a key and value from the
97 given map.
98  
99 =head1 LICENSE AND COPYRIGHT
100  
101 Copyright 2011 Google Inc.
102  
103 Licensed under the Apache License, Version 2.0 (the "License");
104 you may not use this file except in compliance with the License.
105 You may obtain a copy of the License at
106  
107 http://www.apache.org/licenses/LICENSE-2.0
108  
109 Unless required by applicable law or agreed to in writing, software
110 distributed under the License is distributed on an "AS IS" BASIS,
111 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
112 See the License for the specific language governing permissions and
113 limitations under the License.
114  
115 =head1 REPOSITORY INFORMATION
116  
117 $Rev: $
118 $LastChangedBy: $
119 $Id: $
120  
121 =cut
« lib/Google/Ads/AdWords/Logging.pm ↑ Summary lib/Google/Ads/AdWords/OAuth2ApplicationsHandler.pm »