line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Actor.pm 7375 2012-04-10 11:49:08Z chris $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
WebService::Flixster::Actor |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package WebService::Flixster::Actor; |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
74
|
|
12
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
98
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
10
|
use base qw(WebService::Flixster::Base); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1148
|
|
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
18
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
165
|
|
19
|
|
|
|
|
|
|
our @CARP_NOT = qw(WebService::Flixster WebService::Flixster::Base WebService::Flixster::Movie); |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
2
|
|
13
|
use HTTP::Request::Common; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
139
|
|
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
12
|
use URI; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
51
|
|
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
2
|
|
1324
|
use WebService::Flixster::Movie::Stub; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw( |
28
|
|
|
|
|
|
|
__dob |
29
|
|
|
|
|
|
|
__movies |
30
|
|
|
|
|
|
|
)); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use constant { |
34
|
|
|
|
|
|
|
PAGE_MAIN => 1, |
35
|
|
|
|
|
|
|
PAGE_PHOTOS => 2, |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
PAGE_LAST => 2, |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 METHODS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 id |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 dob |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 movies |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 name |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 pob |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
################################ |
56
|
|
|
|
|
|
|
# |
57
|
|
|
|
|
|
|
# Primary properties |
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
################################ |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _url { |
62
|
|
|
|
|
|
|
my $self = shift; |
63
|
|
|
|
|
|
|
my $page = shift; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $uri = URI->new(); |
66
|
|
|
|
|
|
|
$uri->scheme("http"); |
67
|
|
|
|
|
|
|
$uri->host($self->_domain()); |
68
|
|
|
|
|
|
|
if ($page == PAGE_MAIN) { |
69
|
|
|
|
|
|
|
$uri->path(sprintf("/iphone/api/v1/actors/%d.json", $self->_id())); |
70
|
|
|
|
|
|
|
} elsif ($page == PAGE_PHOTOS) { |
71
|
|
|
|
|
|
|
$uri->path("/iphone/api/v1/photos.json"); |
72
|
|
|
|
|
|
|
$uri->query_form('actor' => $self->_id(), 'limit' => 100, 'offset' => 0); # TODO: Suitable limit (and use offset?) |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return $uri->as_string(); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub id { |
80
|
|
|
|
|
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
return $self->_content(PAGE_MAIN)->{'id'}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub dob { |
85
|
|
|
|
|
|
|
my $self = shift; |
86
|
|
|
|
|
|
|
return $self->_dob(); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub movies { |
90
|
|
|
|
|
|
|
my $self = shift; |
91
|
|
|
|
|
|
|
return $self->_movies(); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub name { |
95
|
|
|
|
|
|
|
my $self = shift; |
96
|
|
|
|
|
|
|
return $self->_content(PAGE_MAIN)->{'name'}; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub pob { |
100
|
|
|
|
|
|
|
my $self = shift; |
101
|
|
|
|
|
|
|
return $self->_content(PAGE_MAIN)->{'pob'}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
################################ |
106
|
|
|
|
|
|
|
# |
107
|
|
|
|
|
|
|
# Caching accessors |
108
|
|
|
|
|
|
|
# |
109
|
|
|
|
|
|
|
################################ |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub _flush { |
112
|
|
|
|
|
|
|
my $self = shift; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
$self->SUPER::_flush(); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$self->__dob(undef); |
117
|
|
|
|
|
|
|
$self->__movies(undef); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _dob { |
121
|
|
|
|
|
|
|
my $self = shift; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
if (!defined $self->__dob()) { |
124
|
|
|
|
|
|
|
$self->__dob($self->_get_dob()); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
return $self->__dob(); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub _movies { |
130
|
|
|
|
|
|
|
my $self = shift; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
if (!defined $self->__movies()) { |
133
|
|
|
|
|
|
|
$self->__movies($self->_get_movies()); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
return $self->__movies(); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
################################ |
140
|
|
|
|
|
|
|
# |
141
|
|
|
|
|
|
|
# Parsing methods |
142
|
|
|
|
|
|
|
# |
143
|
|
|
|
|
|
|
################################ |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub _get_id { |
146
|
|
|
|
|
|
|
my $self = shift; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# See comment in WebService::Flixster::Movie::_get_id() |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
if (exists $self->_q()->{'id'}) { |
151
|
|
|
|
|
|
|
my $id = $self->_q()->{'id'}; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
my $uri = URI->new(); |
154
|
|
|
|
|
|
|
$uri->scheme("http"); |
155
|
|
|
|
|
|
|
$uri->host($self->_domain()); |
156
|
|
|
|
|
|
|
$uri->path(sprintf("/iphone/api/v1/actors/%d.json", $id)); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
my $content = $self->_ws()->_response_decoded_content(GET $uri->as_string()); |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
if ($content =~ m/^\s*$/) { |
161
|
|
|
|
|
|
|
croak "Resource not found"; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
my $json = $self->_ws()->_response_decoded_json(GET $uri->as_string()); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
if ($json->{'id'} ne $id) { |
167
|
|
|
|
|
|
|
die "id failed round trip" |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
return $id; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
} elsif (exists $self->_q()->{'imdbid'}) { |
173
|
|
|
|
|
|
|
my $imdbid = $self->_q()->{'imdbid'}; |
174
|
|
|
|
|
|
|
my ($id) = $imdbid =~ m/^(?:nm)?(\d+)$/ or die "Failed to parse '$imdbid'"; |
175
|
|
|
|
|
|
|
die "TODO: " . sprintf("nm%07d", $id); |
176
|
|
|
|
|
|
|
} else { |
177
|
|
|
|
|
|
|
croak "No valid search criteria"; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub _get_dob { |
183
|
|
|
|
|
|
|
my $self = shift; |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
return WebService::Flixster::Date->_new($self->_ws(), $self->_content(PAGE_MAIN)->{'dob'}); |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub _get_movies { |
190
|
|
|
|
|
|
|
my $self = shift; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
return [ map { WebService::Flixster::Movie::Stub->_new($self->_ws(), $_) } @{$self->_content(PAGE_MAIN)->{'movies'}} ]; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
################################ |
198
|
|
|
|
|
|
|
# |
199
|
|
|
|
|
|
|
# Debug / dev code |
200
|
|
|
|
|
|
|
# |
201
|
|
|
|
|
|
|
################################ |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub _unparsed { |
204
|
|
|
|
|
|
|
my $self = shift; |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
use Storable qw(dclone); |
207
|
|
|
|
|
|
|
my $d = { map {$_ => dclone($self->_content($_))} (1..PAGE_LAST) }; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
delete $d->{PAGE_MAIN()}->{'dob'}; |
210
|
|
|
|
|
|
|
delete $d->{PAGE_MAIN()}->{'movies'}; |
211
|
|
|
|
|
|
|
delete $d->{PAGE_MAIN()}->{'name'}; |
212
|
|
|
|
|
|
|
delete $d->{PAGE_MAIN()}->{'pob'}; |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
return $d; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
1; |