line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flickr::License::Helper; |
2
|
1
|
|
|
1
|
|
1089
|
use Class::Singleton; |
|
1
|
|
|
|
|
396
|
|
|
1
|
|
|
|
|
26
|
|
3
|
1
|
|
|
1
|
|
909
|
use Flickr::API; |
|
1
|
|
|
|
|
138068
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
1182
|
use Flickr::API::Utils; |
|
1
|
|
|
|
|
1403
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
8
|
use Carp; |
|
1
|
|
|
|
|
71
|
|
|
1
|
|
|
|
|
83
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use vars qw(@ISA); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
598
|
|
9
|
|
|
|
|
|
|
@ISA = qw(Class::Singleton); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Flickr::License::Helper - Helper class to grab details of the currently supported licenses on Flickr |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.02 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $helper = Flickr::License::Helper->get_instance($APIKEY); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $license_name = $helper->licenses->{$license_id}{name}; |
28
|
|
|
|
|
|
|
my $license_url = $helper->licenses->{}$license_id}{url}; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
The class is a singleton that caches the data returned by the flickr.photo.getLicenses api call in a simple hash. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
It only grabs the data when the API key is set or changed, or if the refresh function is explicitly called. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 METHODS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#_new_instance |
41
|
|
|
|
|
|
|
#Returns a new instance of the Helper. |
42
|
|
|
|
|
|
|
#It is called by the Class::Singleton method ->instance() if the class is not initialised. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _new_instance { |
45
|
0
|
|
|
0
|
|
|
my $class = shift; |
46
|
0
|
|
|
|
|
|
my $api_key = shift; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $me = { utils => Flickr::API::Utils->new() }; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $self = bless $me, $class; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if (defined $api_key) { |
53
|
0
|
|
|
|
|
|
$self->api_key($api_key); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 api_key |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Returns the current api_key. If an argument is passed in that is set to be the current api_key. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
If the key has changed then the license data is refreshed from flickr |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub api_key { |
68
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
69
|
0
|
|
|
|
|
|
my $key=shift; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
0
|
|
|
|
if (defined $key && |
|
|
|
0
|
|
|
|
|
73
|
|
|
|
|
|
|
(!exists $self->{api_key} || !defined $self->{api_key} || $self->{api_key} ne $key)) |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
|
|
|
$self->{api_key}=$key; |
76
|
0
|
|
|
|
|
|
$self->refresh(); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return $self->{api_key}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 refresh |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Refreshes the internal cache from flickr |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub refresh { |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# no license key means no hash |
93
|
0
|
0
|
|
|
|
|
if ($self->{api_key} eq '') { |
94
|
0
|
|
|
|
|
|
croak "No flickr API key defined, can't get license info"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $api=new Flickr::API({key => $self->{api_key}}); |
98
|
0
|
|
|
|
|
|
my $response=$api->execute_method('flickr.photos.licenses.getInfo'); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# License info as of 20070711 |
101
|
|
|
|
|
|
|
# my $xml=<
|
102
|
|
|
|
|
|
|
# |
103
|
|
|
|
|
|
|
#
|
104
|
|
|
|
|
|
|
# url="http://creativecommons.org/licenses/by/2.0/" /> |
105
|
|
|
|
|
|
|
#
|
106
|
|
|
|
|
|
|
# url="http://creativecommons.org/licenses/by-nd/2.0/" /> |
107
|
|
|
|
|
|
|
#
|
108
|
|
|
|
|
|
|
# url="http://creativecommons.org/licenses/by-nc-nd/2.0/" /> |
109
|
|
|
|
|
|
|
#
|
110
|
|
|
|
|
|
|
# url="http://creativecommons.org/licenses/by-nc/2.0/" /> |
111
|
|
|
|
|
|
|
#
|
112
|
|
|
|
|
|
|
# url="http://creativecommons.org/licenses/by-nc-sa/2.0/" /> |
113
|
|
|
|
|
|
|
#
|
114
|
|
|
|
|
|
|
# url="http://creativecommons.org/licenses/by-sa/2.0/" /> |
115
|
|
|
|
|
|
|
# |
116
|
|
|
|
|
|
|
#END |
117
|
|
|
|
|
|
|
# ; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
my $result={}; |
120
|
0
|
|
|
|
|
|
$self->{utils}->test_return($response,$result); |
121
|
0
|
0
|
|
|
|
|
if ($result->{success}) { |
122
|
0
|
|
|
|
|
|
my $xml=$response;#->{_content}; |
123
|
0
|
|
|
|
|
|
$self->{licenses} = $self->_parse_licenses($xml); |
124
|
|
|
|
|
|
|
} else { |
125
|
0
|
|
|
|
|
|
croak "Failed to get license data: $result->{error_message} ($result->{error_code})"; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# _parse_licenses |
130
|
|
|
|
|
|
|
# parses the license data returned by flickr into the internal cache |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub _parse_licenses { |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
0
|
|
|
my $self=shift; |
135
|
0
|
|
|
|
|
|
my $xml=shift; |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
my $ret = {}; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
foreach my $node (@{$xml->{tree}{children}}) { |
|
0
|
|
|
|
|
|
|
140
|
0
|
0
|
0
|
|
|
|
if ($node->{type} eq 'tag' and $node->{name} eq 'licenses') { |
141
|
0
|
|
|
|
|
|
foreach my $license (@{$node->{children}}) { |
|
0
|
|
|
|
|
|
|
142
|
0
|
0
|
0
|
|
|
|
if ($license->{type} eq 'tag' and $license->{name} eq 'license') { |
143
|
0
|
|
|
|
|
|
$ret->{$license->{attributes}{id}}{name}=$license->{attributes}{name}; |
144
|
0
|
|
|
|
|
|
$ret->{$license->{attributes}{id}}{url}=$license->{attributes}{url}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
return $ret; |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 licenses |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Returns a handle to the internal cache of licenses. The structure should look something like this: |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
{ |
159
|
|
|
|
|
|
|
'6' => { |
160
|
|
|
|
|
|
|
'url' => 'http://creativecommons.org/licenses/by-nd/2.0/', |
161
|
|
|
|
|
|
|
'name' => 'Attribution-NoDerivs License' |
162
|
|
|
|
|
|
|
}, |
163
|
|
|
|
|
|
|
'1' => { |
164
|
|
|
|
|
|
|
'url' => 'http://creativecommons.org/licenses/by-nc-sa/2.0/', |
165
|
|
|
|
|
|
|
'name' => 'Attribution-NonCommercial-ShareAlike License' |
166
|
|
|
|
|
|
|
}, |
167
|
|
|
|
|
|
|
'4' => { |
168
|
|
|
|
|
|
|
'url' => 'http://creativecommons.org/licenses/by/2.0/', |
169
|
|
|
|
|
|
|
'name' => 'Attribution License' |
170
|
|
|
|
|
|
|
}, |
171
|
|
|
|
|
|
|
'3' => { |
172
|
|
|
|
|
|
|
'url' => 'http://creativecommons.org/licenses/by-nc-nd/2.0/', |
173
|
|
|
|
|
|
|
'name' => 'Attribution-NonCommercial-NoDerivs License' |
174
|
|
|
|
|
|
|
}, |
175
|
|
|
|
|
|
|
'0' => { |
176
|
|
|
|
|
|
|
'url' => '', |
177
|
|
|
|
|
|
|
'name' => 'All Rights Reserved' |
178
|
|
|
|
|
|
|
}, |
179
|
|
|
|
|
|
|
'2' => { |
180
|
|
|
|
|
|
|
'url' => 'http://creativecommons.org/licenses/by-nc/2.0/', |
181
|
|
|
|
|
|
|
'name' => 'Attribution-NonCommercial License' |
182
|
|
|
|
|
|
|
}, |
183
|
|
|
|
|
|
|
'5' => { |
184
|
|
|
|
|
|
|
'url' => 'http://creativecommons.org/licenses/by-sa/2.0/', |
185
|
|
|
|
|
|
|
'name' => 'Attribution-ShareAlike License' |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub licenses { |
192
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
193
|
0
|
|
|
|
|
|
return $self->{licenses}; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 AUTHOR |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Billy Abbott, C<< >> |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Copyright 2007 Billy Abbott, All Rights Reserved. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
205
|
|
|
|
|
|
|
under the same terms as Perl itself. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 SEE ALSO |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
, Flickr::API, Flickr::Photo |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=cut |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
1; |