PicasaWeb/Media.pm untested

filter: Statementstmt 0.0% 0 / 58 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 84 CC 8 SCAR 30.0
CC
8
Cov
0%
from_feed
42.0
_fetch
12.0
fetch
2.0
CRAP 20.0
1 package Net::Google::PicasaWeb::Media;
2 {
3 $Net::Google::PicasaWeb::Media::VERSION = '0.12';
4 }
5 use Moose;
6  
7 # ABSTRACT: hold information about a photo or video
8  
9 extends 'Net::Google::PicasaWeb::Base';
10  
11 use Carp;
12  
13  
14 has title => (
15 is => 'rw',
16 isa => 'Str',
17 );
18  
19  
20 has description => (
21 is => 'rw',
22 isa => 'Str',
23 );
24  
25  
26 has content => (
27 is => 'rw',
28 isa => 'Net::Google::PicasaWeb::Media::Content',
29 );
30  
31  
32 has thumbnails => (
33 is => 'rw',
34 isa => 'ArrayRef[Net::Google::PicasaWeb::Media::Thumbnail]',
35 auto_deref => 1,
36 );
37  
38  
39 sub from_feed {
40 my ($class, $service, $media_group) = @_;
41  
42 my $content = $media_group->first_child('media:content');
43  
44 my %params = (
45 service => $service,
46 twig => $media_group,
47 title => $media_group->field('media:title'),
48 description => $media_group->field('media:description'),
49 );
50
51 my $self = $class->new(\%params);
52  
53 $self->content(
54 Net::Google::PicasaWeb::Media::Content->new(
55 media => $self,
56 url => $content->att('url'),
57 mime_type => $content->att('type'),
58 medium => $content->att('medium'),
59  
60 ($content->att('height') ? (height => $content->att('height')) : ()),
61 ($content->att('width') ? (width => $content->att('width')) : ()),
62 ($content->att('fileSize') ? (size => $content->att('fileSize')) : ()),
63 )
64 );
65 $self->thumbnails(
66 [
67 map {
68 Net::Google::PicasaWeb::Media::Thumbnail->new(
69 media => $self,
70 url => $_->att('url'),
71  
72 ($_->att('height') ? (height => $_->att('height')) : ()),
73 ($_->att('width') ? (width => $_->att('width')) : ()),
74 )
75 } $media_group->children('media:thumbnail')
76 ]
77 );
78  
79 return $self;
80 }
81  
82 sub _fetch {
83 my ($self, $content, %params) = @_;
84 my $url = $content->url;
85  
86 my %header;
87 $header{':content_file'} = $params{file} if $params{file};
88  
89 my $response = $self->service->user_agent->get($url, %header);
90  
91 if ($response->is_success) {
92 return $response->content;
93 }
94 else {
95 croak $response->status_line;
96 }
97 }
98  
99 package Net::Google::PicasaWeb::Media::Content;
100 {
101 $Net::Google::PicasaWeb::Media::Content::VERSION = '0.12';
102 }
103 use Moose;
104  
105  
106 has media => (
107 is => 'rw',
108 isa => 'Net::Google::PicasaWeb::Media',
109 required => 1,
110 weak_ref => 1,
111 );
112  
113  
114 has url => (
115 is => 'rw',
116 isa => 'Str',
117 );
118  
119  
120 has mime_type => (
121 is => 'rw',
122 isa => 'Str',
123 );
124  
125  
126 has medium => (
127 is => 'rw',
128 isa => 'Str',
129 );
130  
131  
132 has width => (
133 is => 'rw',
134 isa => 'Int',
135 );
136  
137  
138 has height => (
139 is => 'rw',
140 isa => 'Int',
141 );
142  
143  
144 has size => (
145 is => 'rw',
146 isa => 'Int',
147 );
148  
149  
150 sub fetch {
151 my $self = shift;
152 return $self->media->_fetch($self, @_);
153 }
154  
155 package Net::Google::PicasaWeb::Media::Thumbnail;
156 {
157 $Net::Google::PicasaWeb::Media::Thumbnail::VERSION = '0.12';
158 }
159 use Moose;
160  
161  
162 has media => (
163 is => 'rw',
164 isa => 'Net::Google::PicasaWeb::Media',
165 required => 1,
166 weak_ref => 1,
167 );
168  
169  
170 has url => (
171 is => 'rw',
172 isa => 'Str',
173 );
174  
175  
176 has width => (
177 is => 'rw',
178 isa => 'Int',
179 );
180  
181  
182 has height => (
183 is => 'rw',
184 isa => 'Int',
185 );
186  
187  
188 sub fetch {
189 my $self = shift;
190 return $self->media->_fetch($self, @_);
191 }
192  
193 __PACKAGE__->meta->make_immutable;
194  
195 1;
196  
197 __END__