line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flickr::License; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
33318
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
97
|
|
4
|
1
|
|
|
1
|
|
604
|
use Flickr::License::Helper; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
698
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Flickr::License - Represents the license of a photo from Flickr |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.02 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $license=Flickr::License->new({api_key=>$APIKEY, id=>$license_number}); |
22
|
|
|
|
|
|
|
if ($license->valid) { |
23
|
|
|
|
|
|
|
my $license_name = $license->name; |
24
|
|
|
|
|
|
|
my $license_url = $license->url; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This class retrieves data about the currently available Flickr photo licenses and returns the details that Flickr does based on the license number passed in. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
The license number can be obtained easily from the Flickr::Photo object using the ->license() call. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
If the license number isn't recognised in the data structure that Flickr returns then the "valid" property of the class is set to 0 and the name is set to "Invalid License" |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Behind the scenes it uses a singleton that holds the necessary license date, only refreshing itself if it thinks it needs to. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 new |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Sets up the license object. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $license=Flickr::License->new({api_key => $APIKEY, |
44
|
|
|
|
|
|
|
id => $license_id}); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
id is optional and can be set using the ->id() setter/getter -> details of the license are only filled in once id is set. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new { |
51
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
52
|
0
|
|
|
|
|
|
my $params = shift; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
if (!exists $params->{api_key}) { |
55
|
0
|
|
|
|
|
|
croak("Can't create a license without an Flick API key") |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $me = { api_key => $params->{api_key} }; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $self = bless $me, $class; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# init the license helper |
63
|
0
|
|
|
|
|
|
my $factory=Flickr::License::Helper->instance($self->{api_key}); |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if (exists $params->{id}) { |
66
|
0
|
|
|
|
|
|
$self->{id}=$params->{id}; |
67
|
0
|
|
|
|
|
|
$self->_init; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return $self; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#_init |
74
|
|
|
|
|
|
|
#Function to grab the license information from the Flickr::License::Helper object for this object. |
75
|
|
|
|
|
|
|
#Will croak if the license id is not set. That shouldn't happen as it is only called when the id is set. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _init { |
78
|
0
|
|
|
0
|
|
|
my $self=shift; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
if (!exists $self->{id}) { |
81
|
0
|
|
|
|
|
|
croak "Cannot get license information without a license id"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $number=$self->{id}; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $factory=Flickr::License::Helper->instance(); |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $licenses=$factory->licenses; |
89
|
0
|
0
|
|
|
|
|
if (exists $licenses->{$number}) { |
90
|
0
|
|
|
|
|
|
$self->{name}=$licenses->{$number}->{name}; |
91
|
0
|
|
|
|
|
|
$self->{url}=$licenses->{$number}->{url}; |
92
|
0
|
|
|
|
|
|
$self->{valid}=1; |
93
|
|
|
|
|
|
|
} else { |
94
|
0
|
|
|
|
|
|
$self->{name}="Invalid license"; |
95
|
0
|
|
|
|
|
|
$self->{url}=""; |
96
|
0
|
|
|
|
|
|
$self->{valid}=0; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 id |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $id = $license->id; |
104
|
|
|
|
|
|
|
my $different_id = $license->id($a_different_id); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Returns the id. Also sets the id if an argument is passed in - it will always return the new id. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Will also populate the object with license information. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub id { |
113
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
114
|
0
|
|
|
|
|
|
my $num=shift; |
115
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
|
if (defined $num) { |
117
|
0
|
|
|
|
|
|
$self->{id}=$num; |
118
|
0
|
|
|
|
|
|
$self->_init; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return $self->{id}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 name |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Returns the license name |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub name { |
131
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
132
|
0
|
|
|
|
|
|
return $self->{name}; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 url |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Returns the license url |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub url { |
142
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
143
|
0
|
|
|
|
|
|
return $self->{url}; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 valid |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Returns whether the license id was valid. 0=false, 1=true. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub valid { |
153
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
154
|
0
|
|
|
|
|
|
return $self->{valid}; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 AUTHOR |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Billy Abbott, C<< >> |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Copyright 2007 Billy Abbott, All Rights Reserved. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
166
|
|
|
|
|
|
|
under the same terms as Perl itself. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 SEE ALSO |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
, Flickr::API, Flickr::Photo |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |