File Coverage

blib/lib/TMDB/Genre.pm
Criterion Covered Total %
statement 32 32 100.0
branch 5 10 50.0
condition 1 2 50.0
subroutine 9 9 100.0
pod 0 3 0.0
total 47 56 83.9


line stmt bran cond sub pod time code
1             package TMDB::Genre;
2              
3             #######################
4             # LOAD CORE MODULES
5             #######################
6 3     3   16 use strict;
  3         4  
  3         104  
7 3     3   13 use warnings FATAL => 'all';
  3         5  
  3         151  
8 3     3   13 use Carp qw(croak carp);
  3         8  
  3         172  
9              
10             #######################
11             # LOAD CPAN MODULES
12             #######################
13 3     3   14 use Object::Tiny qw(id session);
  3         6  
  3         15  
14 3     3   2062 use Params::Validate qw(validate_with :types);
  3         31955  
  3         654  
15              
16             #######################
17             # LOAD DIST MODULES
18             #######################
19 3     3   1494 use TMDB::Session;
  3         15  
  3         30  
20              
21             #######################
22             # VERSION
23             #######################
24             our $VERSION = '1.3.0';
25              
26             #######################
27             # PUBLIC METHODS
28             #######################
29              
30             ## ====================
31             ## Constructor
32             ## ====================
33             sub new {
34 1     1 0 9 my $class = shift;
35 1         48 my %opts = validate_with(
36             params => \@_,
37             spec => {
38             session => {
39             type => OBJECT,
40             isa => 'TMDB::Session',
41             },
42             id => {
43             type => SCALAR,
44             optional => 1,
45             },
46             },
47             );
48              
49 1         11 my $self = $class->SUPER::new(%opts);
50 1         8 return $self;
51             } ## end sub new
52              
53             ## ====================
54             ## LIST
55             ## ====================
56             sub list {
57 1     1 0 15 my ($self) = @_;
58 1 50       18 my $response = $self->session->talk(
59             {
60             method => 'genre/list',
61             params => {
62             language => $self->session->lang
63             ? $self->session->lang
64             : undef,
65             },
66             }
67             );
68 1 50       30 return unless $response;
69              
70 1         1 my $genres;
71 1   50     7 $genres = $response->{genres} || [];
72 1 50       3 return @$genres if wantarray;
73 1         5 return $genres;
74             } ## end sub list
75              
76             ## ====================
77             ## MOVIES
78             ## ====================
79             sub movies {
80 1     1 0 275 my ( $self, $max_pages ) = @_;
81 1 50       22 return unless $self->id();
82 1 50       16 return $self->session->paginate_results(
83             {
84             method => 'genre/' . $self->id() . '/movies',
85             max_pages => $max_pages,
86             params => {
87             language => $self->session->lang
88             ? $self->session->lang
89             : undef,
90             },
91             }
92             );
93             } ## end sub movies
94              
95             #######################
96             1;