| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
2
|
|
|
2
|
|
194065
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
77
|
|
|
2
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
115
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package WebService::IMDBAPI; |
|
5
|
|
|
|
|
|
|
{ |
|
6
|
|
|
|
|
|
|
$WebService::IMDBAPI::VERSION = '1.130150'; |
|
7
|
|
|
|
|
|
|
} |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Interface to http://imdbapi.org/ |
|
10
|
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
1111
|
use WebService::IMDBAPI::Result; |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
18
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
2421
|
use LWP::UserAgent; |
|
|
2
|
|
|
|
|
357769
|
|
|
|
2
|
|
|
|
|
67
|
|
|
14
|
2
|
|
|
2
|
|
2565
|
use JSON; |
|
|
2
|
|
|
|
|
45594
|
|
|
|
2
|
|
|
|
|
14
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# default options |
|
17
|
2
|
|
|
2
|
|
315
|
use constant DEFAULT_USER_AGENT => 'Mozilla/5.0'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
76
|
|
|
18
|
2
|
|
|
2
|
|
8
|
use constant DEFAULT_LANG => 'en-US'; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
82
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
12
|
use constant BASE_URL => 'http://imdbapi.org/?type=json'; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
84
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
16
|
use Object::Tiny qw( |
|
23
|
|
|
|
|
|
|
user_agent |
|
24
|
|
|
|
|
|
|
language |
|
25
|
2
|
|
|
2
|
|
9
|
); |
|
|
2
|
|
|
|
|
3
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
|
28
|
2
|
|
|
2
|
1
|
642
|
my $class = shift; |
|
29
|
2
|
|
|
|
|
96
|
my $self = $class->SUPER::new(@_); |
|
30
|
|
|
|
|
|
|
|
|
31
|
2
|
50
|
|
|
|
233
|
unless ( $self->user_agent ) { |
|
32
|
2
|
|
|
|
|
29
|
$self->{user_agent} = DEFAULT_USER_AGENT; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
2
|
50
|
|
|
|
51
|
unless ( $self->language ) { |
|
35
|
2
|
|
|
|
|
15
|
$self->{language} = DEFAULT_LANG; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
8
|
return $self; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub search_by_title { |
|
42
|
2
|
|
|
2
|
1
|
956
|
my ( $self, $title, $options ) = @_; |
|
43
|
|
|
|
|
|
|
|
|
44
|
2
|
100
|
|
|
|
12
|
unless ($title) { |
|
45
|
1
|
|
|
|
|
15
|
die "title is required"; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
1
|
|
|
|
|
4
|
$options->{title} = $title; |
|
48
|
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
5
|
my $response = $self->_do_search($options); |
|
50
|
1
|
50
|
|
|
|
774625
|
if ( $response->is_success ) { |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
my $content = decode_json( $response->content ); |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
my @results; |
|
55
|
0
|
0
|
|
|
|
0
|
if ( ref($content) eq 'ARRAY' ) { |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
for ( @{ decode_json( $response->content ) } ) { |
|
|
0
|
|
|
|
|
0
|
|
|
58
|
0
|
|
|
|
|
0
|
my $result = WebService::IMDBAPI::Result->new( %{$_} ); |
|
|
0
|
|
|
|
|
0
|
|
|
59
|
0
|
|
|
|
|
0
|
push( @results, $result ); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
} |
|
62
|
0
|
|
|
|
|
0
|
return \@results; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
else { |
|
65
|
1
|
|
|
|
|
17
|
die $response->status_line; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub search_by_id { |
|
70
|
1
|
|
|
1
|
1
|
511
|
my ( $self, $id, $options ) = @_; |
|
71
|
|
|
|
|
|
|
|
|
72
|
1
|
50
|
|
|
|
5
|
unless ($id) { |
|
73
|
1
|
|
|
|
|
31
|
die "id is required"; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
0
|
|
|
|
|
0
|
$options->{id} = $id; |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
my $response = $self->_do_search($options); |
|
78
|
0
|
0
|
|
|
|
0
|
if ( $response->is_success ) { |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
my $content = decode_json( $response->content ); |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
0
|
if ( $content->{error} ) { |
|
83
|
0
|
|
|
|
|
0
|
return; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
0
|
|
|
|
|
0
|
my $result = WebService::IMDBAPI::Result->new( %{$content} ); |
|
|
0
|
|
|
|
|
0
|
|
|
86
|
0
|
|
|
|
|
0
|
return $result; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
else { |
|
89
|
0
|
|
|
|
|
0
|
die $response->status_line; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# carries out the search and returns the response |
|
94
|
|
|
|
|
|
|
sub _do_search { |
|
95
|
1
|
|
|
1
|
|
2
|
my ( $self, $options ) = @_; |
|
96
|
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
5
|
my $url = $self->_generate_url($options); |
|
98
|
1
|
|
|
|
|
12
|
my $ua = LWP::UserAgent->new(); |
|
99
|
1
|
|
|
|
|
3283
|
$ua->agent( $self->{user_agent} ); |
|
100
|
1
|
|
|
|
|
55
|
return $ua->get($url); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# generates a url from the options |
|
104
|
|
|
|
|
|
|
sub _generate_url { |
|
105
|
3
|
|
|
3
|
|
2022
|
my ( $self, $options ) = @_; |
|
106
|
|
|
|
|
|
|
|
|
107
|
3
|
|
|
|
|
20
|
my $url = sprintf( "%s&lang=%s", BASE_URL, $self->{language} ); |
|
108
|
|
|
|
|
|
|
|
|
109
|
3
|
|
|
|
|
19
|
while ( my ( $key, $value ) = each(%$options) ) { |
|
110
|
3
|
|
50
|
|
|
37
|
$url .= sprintf( "&%s=%s", $key, $value || 0 ); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
3
|
|
|
|
|
31
|
return $url; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=pod |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 NAME |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
WebService::IMDBAPI - Interface to http://imdbapi.org/ |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 VERSION |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
version 1.130150 |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my $imdb = WebService::IMDBAPI->new(); |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# an array of up to 1 result |
|
135
|
|
|
|
|
|
|
my $results = $imdbapi->search_by_title('In Brugges', { limit => 1 }); |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# an WebService::IMDBAPI::Result object |
|
138
|
|
|
|
|
|
|
my $result = $results->[0]; |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
say $result->title; |
|
141
|
|
|
|
|
|
|
say $result->plot_simple; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
WebService::IMDBAPI is an interface to L. |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 METHODS |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 new |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Creates a new WebService::IMDBAPI object. Takes the following optional parameters: |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=over 4 |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item user_agent |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
The user agent to use. Note that the default LWP user agent seems to be blocked. Defaults to C. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item language |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
The language for the results. Defaults to C. |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=back |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 search_by_title( $title, $options ) |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Searches based on a title. For the options and their defaults, see L. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Some of the most common options are: |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=over 4 |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item limit |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Limits the number of results. Defaults to 1. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item plot |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
The plot type you wish the API to return (none, simple or full). Defaults to simple. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item release |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
The release date type you wish the API to return (simple or full). Defaults to simple. |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=back |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
C<$title> is required. C<$options> are optional. |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Returns an array of L objects. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head2 search_by_id( $id, $options ) |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Searches based on an IMDB ID. For the options and their defaults, see L. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
C<$id> is required. C<$options> are optional. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Returns a single L object. |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 AUTHOR |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Andrew Jones |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Andrew Jones. |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
208
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
__END__ |