line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flickr::API2::Photo; |
2
|
4
|
|
|
4
|
|
41
|
use 5.12.0; |
|
4
|
|
|
|
|
11
|
|
3
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
99
|
|
4
|
4
|
|
|
4
|
|
1579
|
use Encode::Base58; |
|
4
|
|
|
|
|
1564
|
|
|
4
|
|
|
|
|
191
|
|
5
|
4
|
|
|
4
|
|
20
|
use Moo; |
|
4
|
|
|
|
|
3
|
|
|
4
|
|
|
|
|
17
|
|
6
|
|
|
|
|
|
|
extends 'Flickr::API2::Base'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Flickr::API2::Photo |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Represents a Flickr photo, with helper methods. (Incomplete) |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
title |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
date_upload |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
date_taken |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
count_faves |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
views |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
owner_name |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
url_s url_m url_l |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
description |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
path_alias |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
license |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
tags |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
height_s |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
width_s |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
height_m |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
width_m |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
height_l |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
width_l |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
height_o |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
width_o |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
has 'id' => ( |
59
|
|
|
|
|
|
|
is => 'ro', |
60
|
|
|
|
|
|
|
required => 1, |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
has 'title' => ( is => 'rw' ); |
63
|
|
|
|
|
|
|
has 'date_upload' => ( is => 'rw' ); |
64
|
|
|
|
|
|
|
has 'date_taken' => ( is => 'rw' ); |
65
|
|
|
|
|
|
|
has 'count_faves' => ( is => 'rw' ); |
66
|
|
|
|
|
|
|
has 'views' => ( is => 'rw' ); |
67
|
|
|
|
|
|
|
has 'owner_id' => ( is => 'rw' ); |
68
|
|
|
|
|
|
|
has 'owner_name' => ( is => 'rw' ); |
69
|
|
|
|
|
|
|
has 'url_sq' => ( |
70
|
|
|
|
|
|
|
is => 'rw', |
71
|
|
|
|
|
|
|
lazy => 1, |
72
|
|
|
|
|
|
|
default => sub { $_[0]->populate_size_urls; $_[0]->url_sq; }, |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
has 'url_t' => ( |
75
|
|
|
|
|
|
|
is => 'rw', |
76
|
|
|
|
|
|
|
lazy => 1, |
77
|
|
|
|
|
|
|
default => sub { $_[0]->populate_size_urls; $_[0]->url_t; }, |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
has 'url_s' => ( |
80
|
|
|
|
|
|
|
is => 'rw', |
81
|
|
|
|
|
|
|
lazy => 1, |
82
|
|
|
|
|
|
|
default => sub { $_[0]->populate_size_urls; $_[0]->url_s; }, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
has 'url_m' => ( |
85
|
|
|
|
|
|
|
is => 'rw', |
86
|
|
|
|
|
|
|
lazy => 1, |
87
|
|
|
|
|
|
|
default => sub { $_[0]->populate_size_urls; $_[0]->url_m; }, |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
has 'url_l' => ( |
90
|
|
|
|
|
|
|
is => 'rw', |
91
|
|
|
|
|
|
|
lazy => 1, |
92
|
|
|
|
|
|
|
default => sub { $_[0]->populate_size_urls; $_[0]->url_l; }, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
has 'url_o' => ( |
95
|
|
|
|
|
|
|
is => 'rw', |
96
|
|
|
|
|
|
|
lazy => 1, |
97
|
|
|
|
|
|
|
default => sub { $_[0]->populate_size_urls; $_[0]->url_o; }, |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
has 'description' => ( is => 'rw' ); |
100
|
|
|
|
|
|
|
has 'path_alias' => ( is => 'rw' ); |
101
|
|
|
|
|
|
|
has 'license' => ( is => 'rw' ); |
102
|
|
|
|
|
|
|
has 'tags' => ( is => 'rw' ); |
103
|
|
|
|
|
|
|
has 'height_s' => ( is => 'rw' ); |
104
|
|
|
|
|
|
|
has 'width_s' => ( is => 'rw' ); |
105
|
|
|
|
|
|
|
has 'height_m' => ( is => 'rw' ); |
106
|
|
|
|
|
|
|
has 'width_m' => ( is => 'rw' ); |
107
|
|
|
|
|
|
|
has 'height_l' => ( is => 'rw' ); |
108
|
|
|
|
|
|
|
has 'width_l' => ( is => 'rw' ); |
109
|
|
|
|
|
|
|
has 'height_o' => ( is => 'rw' ); |
110
|
|
|
|
|
|
|
has 'width_o' => ( is => 'rw' ); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 METHODS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 info |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Returns getInfo results for this photo; contains lots of info that isn't |
117
|
|
|
|
|
|
|
currently available by simple accessors. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub info { |
122
|
1
|
|
|
1
|
1
|
2
|
my ($self) = shift; |
123
|
1
|
|
|
|
|
12
|
my $response = $self->api->execute_method( |
124
|
|
|
|
|
|
|
'flickr.photos.getInfo', |
125
|
|
|
|
|
|
|
{ |
126
|
|
|
|
|
|
|
photo_id => $self->id, |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
); |
129
|
1
|
|
|
|
|
7
|
return $response; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 sizes |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Returns getSizes results for this photo. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Note that you probably don't need to call this directly - instead, see the |
137
|
|
|
|
|
|
|
various url accessors. If they're blank, try calling populate_size_urls() |
138
|
|
|
|
|
|
|
first. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub sizes { |
143
|
1
|
|
|
1
|
1
|
13
|
my ($self) = shift; |
144
|
1
|
|
|
|
|
15
|
my $response = $self->api->execute_method( |
145
|
|
|
|
|
|
|
'flickr.photos.getSizes', |
146
|
|
|
|
|
|
|
{ |
147
|
|
|
|
|
|
|
photo_id => $self->id, |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
); |
150
|
1
|
|
|
|
|
7
|
return $response->{sizes}; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 populate_size_urls |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Populates all the various URLs to the differently-sized images by querying |
156
|
|
|
|
|
|
|
the API. This *should* have been done automatically for you, the first time |
157
|
|
|
|
|
|
|
you queried one of the url accessors. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
our %label_to_accessor = ( |
162
|
|
|
|
|
|
|
Square => 'url_sq', |
163
|
|
|
|
|
|
|
Thumbnail => 'url_t', |
164
|
|
|
|
|
|
|
Small => 'url_s', |
165
|
|
|
|
|
|
|
Medium => 'url_m', |
166
|
|
|
|
|
|
|
Large => 'url_l', |
167
|
|
|
|
|
|
|
Original => 'url_o', |
168
|
|
|
|
|
|
|
); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub populate_size_urls { |
171
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
172
|
1
|
|
|
|
|
5
|
my $sizes = $self->sizes->{size}; |
173
|
1
|
|
|
|
|
4
|
for my $s (@$sizes) { |
174
|
9
|
100
|
|
|
|
1296
|
if (my $acc = $label_to_accessor{$s->{label}}) { |
175
|
6
|
|
|
|
|
56
|
$self->$acc($s->{source}); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 page_url |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Returns the URL for this photo's page on Flickr. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# See http://www.flickr.com/services/api/misc.urls.html |
187
|
|
|
|
|
|
|
# for generation method |
188
|
|
|
|
|
|
|
sub page_url { |
189
|
3
|
|
|
3
|
1
|
4421
|
my $self = shift; |
190
|
3
|
|
33
|
|
|
81
|
return sprintf('http://flickr.com/photos/%s/%d', |
191
|
|
|
|
|
|
|
($self->path_alias || $self->owner_name || $self->owner_id), |
192
|
|
|
|
|
|
|
$self->id |
193
|
|
|
|
|
|
|
); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 short_url |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Returns the shortened URL for the photo page, ie. at http://flic.kr/ |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub short_url { |
203
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
204
|
1
|
|
|
|
|
7
|
sprintf('http://flic.kr/p/%s', encode_base58($self->id)); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
1; |