TMDB/Search.pm

filter: Statementstmt 79.3% 69 / 87 Branchbran 38.6% 17 / 44 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 67.8% 19 / 28 Podpod 0.0% 0 / 17 totaltotal 54.4% 105 / 193 CC 27 SCAR 20.4
CC
27
Cov
60%
__ANON__
42.0
__ANON__
6.0
company
6.0
CRAP 7.7
« TMDB/Movie.pm ↑ Summary TMDB/Config.pm »
1 package TMDB::Search;
2  
3 #######################
4 # LOAD CORE MODULES
5 #######################
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Carp qw(croak carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #######################
11 # LOAD CPAN MODULES
12 #######################
13 3 ▶use Params::Validate qw(validate_with :types);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Object::Tiny qw(session include_adult max_pages);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #######################
17 # LOAD DIST MODULES
18 #######################
19 3 ▶use TMDB::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 #######################
22 # VERSION
23 #######################
24 3 our $VERSION = '1.3.0';
25  
26 #######################
27 # PUBLIC METHODS
28 #######################
29  
30 ## ====================
31 ## Constructor
32 ## ====================
33 1 ▶sub new {
Subroutine new: called CC=1 SCAR=1.2
Pod undocumented
34 1 my $class = shift;
35 my %opts = validate_with(
36 params => \@_,
37 spec => {
38 session => {
39 type => OBJECT,
40 isa => 'TMDB::Session',
41 },
42 include_adult => {
43 type => SCALAR,
44 optional => 1,
45 default => 'false',
46 callbacks => {
47 'valid flag' =>
48 0 ▶ sub { lc $_[0] eq 'true' or lc $_[0] eq 'false' }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
lc $_[0] eq "true" or lc $_[0] eq "false" 0 0 0
49 },
50 },
51 max_pages => {
52 type => SCALAR,
53 optional => 1,
54 default => 1,
55 callbacks => {
56 0 ▶ 'integer' => sub { $_[0] =~ m{\d+} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
57 },
58 },
59 },
60 1 );
61  
62 1 my $self = $class->SUPER::new(%opts);
63 1 return $self;
64 } ## end sub new
65  
66 ## ====================
67 ## Search Movies
68 ## ====================
69 1 ▶sub movie {
Subroutine movie: called CC=5 SCAR=17.6
Pod undocumented
70 1 my ( $self, $string ) = @_;
71  
72 # Get Year
73 1 my $year;
74 1 ▶ if ( $string =~ m{.+\((\d{4})\)$} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /.+\((\d{4})\)$/) 0 1 1
75 0 $year = $1;
76 0 $string =~ s{\($year\)$}{};
77 } ## end if ( $string =~ m{.+\((\d{4})\)$})
78  
79 # Trim
80 1 $string =~ s{(?:^\s+)|(?:\s+$)}{};
81  
82 # Search
83 1 my $params = {
84 query => $string,
85 include_adult => $self->include_adult,
86 };
87 1 ▶ $params->{language} = $self->session->lang if $self->session->lang;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->lang 1 0 1
88 1 ▶ $params->{year} = $year if $year;
Branch: 1 branch
BranchTrueFalseTotal
if $year 0 1 1
89  
90 1 ▶ warn "DEBUG: Searching for $string\n" if $self->session->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->debug 0 1 1
91 1 return $self->_search(
92 {
93 method => 'search/movie',
94 params => $params,
95 }
96 );
97 } ## end sub movie
98  
99 ## ====================
100 ## Search TV Shows
101 ## ====================
102 1 ▶sub tv {
Subroutine tv: called CC=5 SCAR=17.6
Pod undocumented
103 1 my ( $self, $string ) = @_;
104  
105 # Get Year
106 1 my $year;
107 1 ▶ if ( $string =~ m{.+\((\d{4})\)$} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /.+\((\d{4})\)$/) 0 1 1
108 0 $year = $1;
109 0 $string =~ s{\($year\)$}{};
110 } ## end if ( $string =~ m{.+\((\d{4})\)$})
111  
112 # Trim
113 1 $string =~ s{(?:^\s+)|(?:\s+$)}{};
114  
115 # Search
116 1 my $params = {
117 query => $string,
118 include_adult => $self->include_adult,
119 };
120 1 ▶ $params->{language} = $self->session->lang if $self->session->lang;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->lang 1 0 1
121 1 ▶ $params->{year} = $year if $year;
Branch: 1 branch
BranchTrueFalseTotal
if $year 0 1 1
122  
123 1 ▶ warn "DEBUG: Searching for $string\n" if $self->session->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->debug 0 1 1
124 1 return $self->_search(
125 {
126 method => 'search/tv',
127 params => $params,
128 }
129 );
130 } ## end sub tv
131  
132 ## ====================
133 ## Search Person
134 ## ====================
135 1 ▶sub person {
Subroutine person: called CC=2 SCAR=7.1
Pod undocumented
136 1 my ( $self, $string ) = @_;
137  
138 1 ▶ warn "DEBUG: Searching for $string\n" if $self->session->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->debug 0 1 1
139 1 return $self->_search(
140 {
141 method => 'search/person',
142 params => {
143 query => $string,
144 },
145 }
146 );
147 } ## end sub person
148  
149 ## ====================
150 ## Search Companies
151 ## ====================
152 0 ▶sub company {
Subroutine company: not called CC=2 SCAR=17.9
Pod undocumented
153 0 my ( $self, $string ) = @_;
154  
155 0 ▶ warn "DEBUG: Searching for $string\n" if $self->session->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->debug 0 0 0
156 0 return $self->_search(
157 {
158 method => 'search/company',
159 params => {
160 query => $string,
161 },
162 }
163 );
164 } ## end sub company
165  
166 ## ====================
167 ## Search Lists
168 ## ====================
169 1 ▶sub list {
Subroutine list: called CC=2 SCAR=7.1
Pod undocumented
170 1 my ( $self, $string ) = @_;
171  
172 1 ▶ warn "DEBUG: Searching for $string\n" if $self->session->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->debug 0 1 1
173 1 return $self->_search(
174 {
175 method => 'search/list',
176 params => {
177 query => $string,
178 },
179 }
180 );
181 } ## end sub list
182  
183 ## ====================
184 ## Search Keywords
185 ## ====================
186 0 ▶sub keyword {
Subroutine keyword: not called CC=2 SCAR=17.9
Pod undocumented
187 0 my ( $self, $string ) = @_;
188  
189 0 ▶ warn "DEBUG: Searching for $string\n" if $self->session->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->debug 0 0 0
190 0 return $self->_search(
191 {
192 method => 'search/keyword',
193 params => {
194 query => $string,
195 },
196 }
197 );
198 } ## end sub keyword
199  
200 ## ====================
201 ## Search Collection
202 ## ====================
203 1 ▶sub collection {
Subroutine collection: called CC=2 SCAR=7.1
Pod undocumented
204 1 my ( $self, $string ) = @_;
205  
206 1 ▶ warn "DEBUG: Searching for $string\n" if $self->session->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->debug 0 1 1
207 1 return $self->_search(
208 {
209 method => 'search/collection',
210 params => {
211 query => $string,
212 },
213 }
214 );
215 } ## end sub collection
216  
217 ## ====================
218 ## LISTS
219 ## ====================
220  
221 # Latest
222 0 ▶sub latest { return shift->session->talk( { method => 'movie/latest', } ); }
Subroutine latest: not called CC=1 SCAR=6.9
Pod undocumented
223  
224 # Upcoming
225 1 ▶sub upcoming {
Subroutine upcoming: called CC=2 SCAR=7.2
Pod undocumented
226 1 my ($self) = @_;
227 1 ▶ return $self->_search(
Branch: 1 branch
BranchTrueFalseTotal
$self->session->lang ? : 1 0 1
228 {
229 method => 'movie/upcoming',
230 params => {
231 language => $self->session->lang
232 ? $self->session->lang
233 : undef,
234 },
235 }
236 );
237 } ## end sub upcoming
238  
239 # Now Playing
240 1 ▶sub now_playing {
Subroutine now_playing: called CC=2 SCAR=7.2
Pod undocumented
241 1 my ($self) = @_;
242 1 ▶ return $self->_search(
Branch: 1 branch
BranchTrueFalseTotal
$self->session->lang ? : 1 0 1
243 {
244 method => 'movie/now_playing',
245 params => {
246 language => $self->session->lang
247 ? $self->session->lang
248 : undef,
249 },
250 }
251 );
252 } ## end sub now_playing
253  
254 # Popular
255 1 ▶sub popular {
Subroutine popular: called CC=2 SCAR=7.2
Pod undocumented
256 1 my ($self) = @_;
257 1 ▶ return $self->_search(
Branch: 1 branch
BranchTrueFalseTotal
$self->session->lang ? : 1 0 1
258 {
259 method => 'movie/popular',
260 params => {
261 language => $self->session->lang
262 ? $self->session->lang
263 : undef,
264 },
265 }
266 );
267 } ## end sub popular
268  
269 # Top rated
270 0 ▶sub top_rated {
Subroutine top_rated: not called CC=2 SCAR=17.9
Pod undocumented
271 0 my ($self) = @_;
272 0 ▶ return $self->_search(
Branch: 1 branch
BranchTrueFalseTotal
$self->session->lang ? : 0 0 0
273 {
274 method => 'movie/top-rated',
275 params => {
276 language => $self->session->lang
277 ? $self->session->lang
278 : undef,
279 },
280 }
281 );
282 } ## end sub top_rated
283  
284 # Popular People
285 1 ▶sub popular_people {
Subroutine popular_people: called CC=2 SCAR=7.2
Pod undocumented
286 1 my ($self) = @_;
287 1 ▶ return $self->_search(
Branch: 1 branch
BranchTrueFalseTotal
$self->session->lang ? : 1 0 1
288 {
289 method => 'person/popular',
290 params => {
291 language => $self->session->lang
292 ? $self->session->lang
293 : undef,
294 },
295 }
296 );
297 } ## end sub popular_people
298  
299 # Latest Person
300 0 ▶sub latest_person {
Subroutine latest_person: not called CC=1 SCAR=6.9
Pod undocumented
301 return shift->session->talk(
302 {
303 0 method => 'person/latest',
304 }
305 );
306 } ## end sub latest_person
307  
308 #######################
309 # DISCOVER
310 #######################
311 1 ▶sub discover {
Subroutine discover: called CC=2 SCAR=14.2
Pod undocumented
312 1 my ( $self, @args ) = @_;
313 my %options = validate_with(
314 params => [@args],
315 spec => {
316 sort_by => {
317 type => SCALAR,
318 optional => 1,
319 default => 'popularity.asc',
320 callbacks => {
321 0 ▶ 'valid flag' => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
322 0 ▶ ( lc $_[0] eq 'vote_average.desc' )
Branch: 1 branch
BranchTrueFalseTotal
lc $_[0] eq "vote_average.desc" or lc $_[0] eq "vote_average.asc" or lc $_[0] eq "release_date.desc" or lc $_[0] eq "release_date.asc" or lc $_[0] eq "popularity.desc" or lc $_[0] eq "popularity.asc" 0 0 0
Condition0%0/12
lc $_[0] eq "vote_average.desc" or lc $_[0] eq "vote_average.asc" or lc $_[0] eq "release_date.desc" or lc $_[0] eq "release_date.asc" or lc $_[0] eq "popularity.desc"
l!l&&r!l&&!r
000
lc $_[0] eq "vote_average.desc" or lc $_[0] eq "vote_average.asc" or lc $_[0] eq "release_date.desc" or lc $_[0] eq "release_date.asc"
l!l&&r!l&&!r
000
lc $_[0] eq "vote_average.desc" or lc $_[0] eq "vote_average.asc" or lc $_[0] eq "release_date.desc"
l!l&&r!l&&!r
000
lc $_[0] eq "vote_average.desc" or lc $_[0] eq "vote_average.asc"
l!l&&r!l&&!r
000
MC/DC0%0/5
lc $_[0] eq "vote_average.desc" or lc $_[0] eq "vote_average.asc" or lc $_[0] eq "release_date.desc" or lc $_[0] eq "release_date.asc" or lc $_[0] eq "popularity.desc"
lc $_[0] eq "vote_average.desc" lc $_[0] eq "vote_average.asc" lc $_[0] eq "release_date.desc" lc $_[0] eq "release_date.asc" lc $_[0] eq "popularity.desc"
Truth table0%0/6
A or B or C or D or E
A= lc $_[0] eq "vote_average.desc"B= lc $_[0] eq "vote_average.asc"C= lc $_[0] eq "release_date.desc"D= lc $_[0] eq "release_date.asc"E= lc $_[0] eq "popularity.desc"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
323 or ( lc $_[0] eq 'vote_average.asc' )
324 or ( lc $_[0] eq 'release_date.desc' )
325 or ( lc $_[0] eq 'release_date.asc' )
326 or ( lc $_[0] eq 'popularity.desc' )
327 or ( lc $_[0] eq 'popularity.asc' );
328 },
329 },
330 },
331 year => {
332 type => SCALAR,
333 optional => 1,
334 regex => qr/^\d{4}$/
335 },
336 primary_release_year => {
337 type => SCALAR,
338 optional => 1,
339 regex => qr/^\d{4}$/
340 },
341 'release_date.gte' => {
342 type => SCALAR,
343 optional => 1,
344 regex => qr/^\d{4}\-\d{2}\-\d{2}$/
345 },
346 'release_date.lte' => {
347 type => SCALAR,
348 optional => 1,
349 regex => qr/^\d{4}\-\d{2}\-\d{2}$/
350 },
351 'vote_count.gte' => {
352 type => SCALAR,
353 optional => 1,
354 regex => qr/^\d+$/
355 },
356 'vote_average.gte' => {
357 type => SCALAR,
358 optional => 1,
359 regex => qr/^\d{1,2}\.\d{1,}$/,
360 callbacks => {
361 0 ▶ average => sub { $_[0] <= 10 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
362 },
363 },
364 1 with_genres => {
365 type => SCALAR,
366 optional => 1,
367 },
368 with_companies => {
369 type => SCALAR,
370 optional => 1,
371 },
372 },
373 );
374  
375 1 ▶ return $self->_search(
Branch: 1 branch
BranchTrueFalseTotal
$self->session->lang ? : 1 0 1
376 {
377 method => 'discover/movie',
378 params => {
379 language => $self->session->lang
380 ? $self->session->lang
381 : undef,
382 include_adult => $self->include_adult,
383 %options,
384 },
385 }
386 );
387  
388 } ## end sub discover
389  
390 #######################
391 # FIND
392 #######################
393 1 ▶sub find {
Subroutine find: called CC=2 SCAR=7.1
Pod undocumented
394 1 my ( $self, @args ) = @_;
395 1 my %options = validate_with(
396 params => [@args],
397 spec => {
398 id => {
399 type => SCALAR,
400 },
401 source => {
402 type => SCALAR,
403 },
404 },
405 );
406  
407 return $self->session->talk(
408 {
409 method => 'find/' . $options{id},
410 params => {
411 external_source => $options{source},
412 1 ▶ language => $self->session->lang
Branch: 1 branch
BranchTrueFalseTotal
$self->session->lang ? : 1 0 1
413 ? $self->session->lang
414 : undef,
415 }
416 }
417 );
418 } ## end sub find
419  
420 #######################
421 # PRIVATE METHODS
422 #######################
423  
424 ## ====================
425 ## Search
426 ## ====================
427 10 ▶sub _search {
Subroutine _search: called CC=1 SCAR=0.0
428 10 my $self = shift;
429 10 my $args = shift;
430 10 $args->{max_pages} = $self->max_pages();
431 10 return $self->session->paginate_results($args);
432 } ## end sub _search
433  
434 #######################
435 3 1;
« TMDB/Movie.pm ↑ Summary TMDB/Config.pm »