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