line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flickr::Tools; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22732
|
use Flickr::API; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
use Flickr::Roles::Permissions; |
5
|
|
|
|
|
|
|
use Flickr::Types::Tools qw( FlickrAPI FlickrToken FlickrAPIargs HexNum); |
6
|
|
|
|
|
|
|
use Types::Standard qw( Maybe Str HashRef Int InstanceOf Bool); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Storable qw( retrieve_fd ); |
9
|
|
|
|
|
|
|
use Data::Dumper; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use 5.010; |
12
|
|
|
|
|
|
|
use Carp; |
13
|
|
|
|
|
|
|
use Moo; |
14
|
|
|
|
|
|
|
use strictures 2; |
15
|
|
|
|
|
|
|
use namespace::clean; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '1.21_02'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
with('Flickr::Roles::Permissions'); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has _api => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
isa => InstanceOf ['Flickr::API'], |
24
|
|
|
|
|
|
|
clearer => 1, |
25
|
|
|
|
|
|
|
predicate => 'has_api', |
26
|
|
|
|
|
|
|
lazy => 1, |
27
|
|
|
|
|
|
|
builder => '_build_api', |
28
|
|
|
|
|
|
|
required => 1, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has '_api_name' => ( |
32
|
|
|
|
|
|
|
is => 'ro', |
33
|
|
|
|
|
|
|
isa => sub { $_[0] =~ m/^Flickr::API$/ }, |
34
|
|
|
|
|
|
|
required => 1, |
35
|
|
|
|
|
|
|
default => 'Flickr::API', |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has access_token => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
clearer => 1, |
41
|
|
|
|
|
|
|
isa => Maybe [ InstanceOf ['Net::OAuth::AccessTokenResponse'] ], |
42
|
|
|
|
|
|
|
required => 0, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has auth_uri => ( |
46
|
|
|
|
|
|
|
is => 'ro', |
47
|
|
|
|
|
|
|
isa => Maybe [Str], |
48
|
|
|
|
|
|
|
clearer => 1, |
49
|
|
|
|
|
|
|
required => 0, |
50
|
|
|
|
|
|
|
default => 'https://api.flickr.com/services/oauth/authorize', |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has callback => ( |
54
|
|
|
|
|
|
|
is => 'ro', |
55
|
|
|
|
|
|
|
isa => Maybe [Str], |
56
|
|
|
|
|
|
|
clearer => 1, |
57
|
|
|
|
|
|
|
required => 0, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
has config_file => ( |
61
|
|
|
|
|
|
|
is => 'ro', |
62
|
|
|
|
|
|
|
isa => Maybe [Str], |
63
|
|
|
|
|
|
|
clearer => 1, |
64
|
|
|
|
|
|
|
required => 0, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
has consumer_key => ( |
68
|
|
|
|
|
|
|
is => 'ro', |
69
|
|
|
|
|
|
|
isa => HexNum, |
70
|
|
|
|
|
|
|
required => 1, |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
has consumer_secret => ( |
74
|
|
|
|
|
|
|
is => 'ro', |
75
|
|
|
|
|
|
|
isa => HexNum, |
76
|
|
|
|
|
|
|
required => 1, |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
has local => ( |
80
|
|
|
|
|
|
|
is => 'rw', |
81
|
|
|
|
|
|
|
isa => Maybe [HashRef], |
82
|
|
|
|
|
|
|
clearer => 1, |
83
|
|
|
|
|
|
|
required => 0, |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
has request_method => ( |
87
|
|
|
|
|
|
|
is => 'ro', |
88
|
|
|
|
|
|
|
clearer => 1, |
89
|
|
|
|
|
|
|
isa => Maybe [Str], |
90
|
|
|
|
|
|
|
required => 0, |
91
|
|
|
|
|
|
|
default => 'GET', |
92
|
|
|
|
|
|
|
); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
has request_token => ( |
95
|
|
|
|
|
|
|
is => 'ro', |
96
|
|
|
|
|
|
|
isa => Maybe [ InstanceOf ['Net::OAuth::V1_0A::RequestTokenResponse'] ], |
97
|
|
|
|
|
|
|
clearer => 1, |
98
|
|
|
|
|
|
|
required => 0, |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
has request_url => ( |
102
|
|
|
|
|
|
|
is => 'ro', |
103
|
|
|
|
|
|
|
isa => Maybe [Str], |
104
|
|
|
|
|
|
|
clearer => 1, |
105
|
|
|
|
|
|
|
required => 0, |
106
|
|
|
|
|
|
|
default => 'https://api.flickr.com/services/rest/', |
107
|
|
|
|
|
|
|
); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
has rest_uri => ( |
110
|
|
|
|
|
|
|
is => 'ro', |
111
|
|
|
|
|
|
|
isa => Maybe [Str], |
112
|
|
|
|
|
|
|
clearer => 1, |
113
|
|
|
|
|
|
|
required => 0, |
114
|
|
|
|
|
|
|
default => 'https://api.flickr.com/services/rest/', |
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
has signature_method => ( |
118
|
|
|
|
|
|
|
is => 'ro', |
119
|
|
|
|
|
|
|
isa => Maybe [Str], |
120
|
|
|
|
|
|
|
clearer => 1, |
121
|
|
|
|
|
|
|
required => 0, |
122
|
|
|
|
|
|
|
default => 'HMAC-SHA1', |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
has token => ( |
126
|
|
|
|
|
|
|
is => 'ro', |
127
|
|
|
|
|
|
|
isa => Maybe [FlickrToken], |
128
|
|
|
|
|
|
|
predicate => 1, |
129
|
|
|
|
|
|
|
clearer => 1, |
130
|
|
|
|
|
|
|
required => 0, |
131
|
|
|
|
|
|
|
); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
has token_secret => ( |
134
|
|
|
|
|
|
|
is => 'ro', |
135
|
|
|
|
|
|
|
isa => Maybe [HexNum], |
136
|
|
|
|
|
|
|
predicate => 1, |
137
|
|
|
|
|
|
|
clearer => 1, |
138
|
|
|
|
|
|
|
required => 0, |
139
|
|
|
|
|
|
|
); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
has unicode => ( |
142
|
|
|
|
|
|
|
is => 'ro', |
143
|
|
|
|
|
|
|
isa => sub { $_[0] != 0 ? 1 : 0; }, |
144
|
|
|
|
|
|
|
clearer => 1, |
145
|
|
|
|
|
|
|
required => 0, |
146
|
|
|
|
|
|
|
default => 0, |
147
|
|
|
|
|
|
|
); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
has _user => ( |
150
|
|
|
|
|
|
|
is => 'rw', |
151
|
|
|
|
|
|
|
isa => Maybe [HashRef], |
152
|
|
|
|
|
|
|
predicate => 1, |
153
|
|
|
|
|
|
|
clearer => 1, |
154
|
|
|
|
|
|
|
required => 0, |
155
|
|
|
|
|
|
|
); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
has version => ( |
158
|
|
|
|
|
|
|
is => 'ro', |
159
|
|
|
|
|
|
|
isa => Maybe [Str], |
160
|
|
|
|
|
|
|
clearer => 1, |
161
|
|
|
|
|
|
|
required => 0, |
162
|
|
|
|
|
|
|
default => '1.0', |
163
|
|
|
|
|
|
|
); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub _dump { |
166
|
|
|
|
|
|
|
my $self = shift; |
167
|
|
|
|
|
|
|
say 'Examine the tool'; |
168
|
|
|
|
|
|
|
print Dumper($self); |
169
|
|
|
|
|
|
|
return; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub BUILDARGS { |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my $class = shift; |
175
|
|
|
|
|
|
|
my $args = shift; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $import; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# args should be either a hashref, or a string containing the path to a config file |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
unless ( ref $args ) { |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
my $config_filename = $args; |
184
|
|
|
|
|
|
|
undef $args; |
185
|
|
|
|
|
|
|
$args->{config_file} = $config_filename; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
confess |
190
|
|
|
|
|
|
|
"\n\nFlickr::Tools->new() expects a hashref,\n or at least the name of a config file\n\n" |
191
|
|
|
|
|
|
|
unless ref($args) eq 'HASH'; |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
if ( $args->{config_file} ) { |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
if ( -r $args->{config_file} ) { |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
my $info = Storable::file_magic( $args->{config_file} ); |
198
|
|
|
|
|
|
|
if ( $info->{version} ) { |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
open my $IMPORT, '<', $args->{config_file} |
201
|
|
|
|
|
|
|
or carp "\nCannot open $args->{config_file} for read: $!\n"; |
202
|
|
|
|
|
|
|
$import = retrieve_fd($IMPORT); |
203
|
|
|
|
|
|
|
close $IMPORT; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
else { |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
carp $args->{config_file}, |
209
|
|
|
|
|
|
|
" is not in storable format, removing from arguments\n"; |
210
|
|
|
|
|
|
|
delete $args->{config_file}; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
else { |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
carp $args->{config_file}, |
216
|
|
|
|
|
|
|
" is not a readable file, removing from arguments\n"; |
217
|
|
|
|
|
|
|
delete $args->{config_file}; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
my $fullargs = _merge_configs( $args, $import ); |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
unless (exists( $fullargs->{consumer_key} ) |
225
|
|
|
|
|
|
|
and exists( $fullargs->{consumer_secret} ) ) |
226
|
|
|
|
|
|
|
{ |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
carp |
229
|
|
|
|
|
|
|
"\nMust provide, at least, a consumer_key and consumer_secret. They can be\npassed directly or in a config_file\n"; |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
return $fullargs; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub api { |
237
|
|
|
|
|
|
|
my $self = shift; |
238
|
|
|
|
|
|
|
return $self->_api if $self->has_api; |
239
|
|
|
|
|
|
|
$self->_build_api; |
240
|
|
|
|
|
|
|
return $self->_api; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub clear_api { |
244
|
|
|
|
|
|
|
my $self = shift; |
245
|
|
|
|
|
|
|
$self->_clear_api; |
246
|
|
|
|
|
|
|
$self->_clear_api_connects; |
247
|
|
|
|
|
|
|
return; |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
sub user { |
251
|
|
|
|
|
|
|
my $self = shift; |
252
|
|
|
|
|
|
|
return $self->_user if $self->_has_user; |
253
|
|
|
|
|
|
|
carp 'No user found'; |
254
|
|
|
|
|
|
|
return; |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
sub prepare_method { } |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
sub validate_method { } |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
sub call_method { } |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub make_arglist { } |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
sub auth_method { } |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
sub set_method { |
268
|
|
|
|
|
|
|
my $self = shift; |
269
|
|
|
|
|
|
|
my $args = shift; |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
if ( $args->{method} =~ m/flickr\.people\./x ) { |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
else { |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
} |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
return; |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
# then specific tools::person or such operate on the family of methods |
282
|
|
|
|
|
|
|
# and they can override some of the above. |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
sub _build_api { |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
my $self = shift; |
287
|
|
|
|
|
|
|
my $args = shift; |
288
|
|
|
|
|
|
|
my $call = {}; |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
# required args |
291
|
|
|
|
|
|
|
$call->{consumer_key} = $self->consumer_key; |
292
|
|
|
|
|
|
|
$call->{consumer_secret} = $self->consumer_secret; |
293
|
|
|
|
|
|
|
$call->{api_type} = 'oauth'; |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
$call->{unicode} = $self->unicode; |
296
|
|
|
|
|
|
|
$call->{request_method} = $self->request_method; |
297
|
|
|
|
|
|
|
$call->{request_url} = $self->request_url; |
298
|
|
|
|
|
|
|
$call->{rest_uri} = $self->rest_uri; |
299
|
|
|
|
|
|
|
$call->{auth_uri} = $self->auth_uri; |
300
|
|
|
|
|
|
|
$call->{signature_method} = $self->signature_method; |
301
|
|
|
|
|
|
|
$call->{version} = $self->version; |
302
|
|
|
|
|
|
|
$call->{callback} = $self->callback; |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
if ( $self->has_token && $self->has_token_secret ) { |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
$call->{token} = $self->token; |
307
|
|
|
|
|
|
|
$call->{token_secret} = $self->token_secret; |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
$self->{_api} = $self->{_api_name}->new($call); |
312
|
|
|
|
|
|
|
return; |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
# |
316
|
|
|
|
|
|
|
# make a template configuration and overwrite template values |
317
|
|
|
|
|
|
|
# with ones passed into new(). Any extra keys get weeded out |
318
|
|
|
|
|
|
|
# and added to args->{local}->{unused_keys} |
319
|
|
|
|
|
|
|
# |
320
|
|
|
|
|
|
|
sub _merge_configs { |
321
|
|
|
|
|
|
|
my @hashes = (@_); |
322
|
|
|
|
|
|
|
my $template = _make_config_template(); |
323
|
|
|
|
|
|
|
my $extrakeys = {}; |
324
|
|
|
|
|
|
|
my $key; |
325
|
|
|
|
|
|
|
my $value; |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
foreach my $hashref (@hashes) { |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
while ( ( $key, $value ) = each %{$hashref} ) { |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
if ( exists( $template->{$key} ) ) { |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
$template->{$key} = $value; |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
else { |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
$extrakeys->{$key} = $value; |
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
} |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
$template->{local}->{unused_args} = $extrakeys; |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
return $template; |
346
|
|
|
|
|
|
|
} |
347
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
# |
349
|
|
|
|
|
|
|
# make a shell of a configuration to deal with any random stuff |
350
|
|
|
|
|
|
|
# that might be sent into new(). |
351
|
|
|
|
|
|
|
# |
352
|
|
|
|
|
|
|
sub _make_config_template { |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
my %empty = ( |
355
|
|
|
|
|
|
|
access_token => undef, |
356
|
|
|
|
|
|
|
auth_uri => 'https://api.flickr.com/services/oauth/authorize', |
357
|
|
|
|
|
|
|
callback => undef, |
358
|
|
|
|
|
|
|
config_file => undef, |
359
|
|
|
|
|
|
|
consumer_key => undef, |
360
|
|
|
|
|
|
|
consumer_secret => undef, |
361
|
|
|
|
|
|
|
local => undef, |
362
|
|
|
|
|
|
|
nonce => undef, |
363
|
|
|
|
|
|
|
request_method => 'GET', |
364
|
|
|
|
|
|
|
request_token => undef, |
365
|
|
|
|
|
|
|
request_url => 'https://api.flickr.com/services/rest/', |
366
|
|
|
|
|
|
|
rest_uri => 'https://api.flickr.com/services/rest/', |
367
|
|
|
|
|
|
|
signature_method => 'HMAC-SHA1', |
368
|
|
|
|
|
|
|
timestamp => undef, |
369
|
|
|
|
|
|
|
token => undef, |
370
|
|
|
|
|
|
|
token_secret => undef, |
371
|
|
|
|
|
|
|
unicode => 0, |
372
|
|
|
|
|
|
|
user => undef, |
373
|
|
|
|
|
|
|
version => '1.0', |
374
|
|
|
|
|
|
|
); |
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
return \%empty; |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
} |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
1; |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
__END__ |