lib/Google/Ads/Common/MediaUtils.pm

filter: Statementstmt 76.4% 26 / 34 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 1 totaltotal 73.9% 34 / 46 CC 2 SCAR 6.9
CC
2
Cov
72%
get_base64_data_from_url
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« blib/lib/Google/Ads/AdWords/v201809/YouTubeAdVideoRegistrationError/Reason.pm ↑ Summary lib/Google/Ads/Common/Utilities/AdsUtilityRegistry.pm »
1 # Copyright 2013, 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::MediaUtils;
16  
17 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶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 5 ▶use Google::Ads::Common::Constants; our $VERSION = ${Google::Ads::Common::Constants::VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 5 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 5 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 5 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 5 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 0 ▶sub get_base64_data_from_url (%) {
Subroutine get_base64_data_from_url: not called CC=2 SCAR=17.9
Pod undocumented
31 0 my $url = shift;
32 0 my $request = HTTP::Request->new(GET => $url);
33 0 my $userAgent = LWP::UserAgent->new();
34 0 $userAgent->agent(sprintf("%s: %s", __PACKAGE__, $0));
35 0 my $response = $userAgent->request($request);
36 0 ▶ if ($response->is_success()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) 0 0 0
37 0 my $content = $response->content();
38 0 return encode_base64($content);
39 }
40 }
41  
42 5 return 1;
43  
44 =pod
45  
46 =head1 NAME
47  
48 Google::Ads::Common::ImageUtils
49  
50 =head1 SYNOPSIS
51  
52 use Google::Ads::Common::ImageUtils;
53  
54 my $image_data;
55 eval {
56 $image_data = Google::Ads::Common::ImageUtils::get_image_data_from_url({
57 url => 'https://sandbox.google.com/sandboximages/image.jpg'
58 });
59 };
60 if ($@) {
61 # $@ will contain a string explaining why the image data request failed.
62 } else {
63 # Make use of $image_data.
64 }
65  
66 =head1 DESCRIPTION
67  
68  
69 =head1 SUBROUTINES
70  
71 =head2 get_image_data_from_url
72  
73 Gets the image data (byte representation) from a given URL.
74  
75 =head3 Parameters
76  
77 The URL from which the data will be retrieved.
78  
79 =head3 Returns
80  
81 A byte array of the image data. Or no return if the image is not found.
82  
83 =head1 LICENSE AND COPYRIGHT
84  
85 Copyright 2013 Google Inc.
86  
87 Licensed under the Apache License, Version 2.0 (the "License");
88 you may not use this file except in compliance with the License.
89 You may obtain a copy of the License at
90  
91 http://www.apache.org/licenses/LICENSE-2.0
92  
93 Unless required by applicable law or agreed to in writing, software
94 distributed under the License is distributed on an "AS IS" BASIS,
95 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96 See the License for the specific language governing permissions and
97 limitations under the License.
98  
99 =head1 REPOSITORY INFORMATION
100  
101 $Rev: $
102 $LastChangedBy: $
103 $Id: $
104  
105 =cut
« blib/lib/Google/Ads/AdWords/v201809/YouTubeAdVideoRegistrationError/Reason.pm ↑ Summary lib/Google/Ads/Common/Utilities/AdsUtilityRegistry.pm »