blib/lib/TMDB/TV.pm

filter: Statementstmt 21.3% 23 / 108 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 30.4% 7 / 23 Podpod 0.0% 0 / 15 totaltotal 14.2% 30 / 210 SCAR 64.0
CC
30
Cov
14%
alternative_titles
42.0
changes
42.0
keywords
20.0
CRAP 602.0
« blib/lib/TMDB/Movie.pm ↑ Summary blib/lib/TMDB/Search.pm »
1 package TMDB::TV;
2  
3 #######################
4 # LOAD CORE MODULES
5 #######################
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp qw(croak carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #######################
11 # LOAD CPAN MODULES
12 #######################
13 1 ▶use Object::Tiny qw(id session);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Params::Validate qw(validate_with :types);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Locale::Codes::Country qw(all_country_codes);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 #######################
18 # LOAD DIST MODULES
19 #######################
20 1 ▶use TMDB::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 #######################
23 # VERSION
24 #######################
25 1 our $VERSION = '1.2.1';
26  
27 #######################
28 # PUBLIC METHODS
29 #######################
30  
31 ## ====================
32 ## Constructor
33 ## ====================
34 sub new {
35 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
36 0 my %opts = validate_with(
37 params => \@_,
38 spec => {
39 session => {
40 type => OBJECT,
41 isa => 'TMDB::Session',
42 },
43 id => {
44 type => SCALAR,
45 },
46 },
47 );
48  
49 0 my $self = $class->SUPER::new(%opts);
50 0 return $self;
51 } ## end sub new
52  
53 ## ====================
54 ## INFO
55 ## ====================
56 sub info {
57 0 ▶ my $self = shift;
Subroutine info: not called CC=3 SCAR=24.8
Pod undocumented
58 0 my $params = {};
59 0 ▶ $params->{language} = $self->session->lang if $self->session->lang;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->lang 0 0 0
60 0 my $info = $self->session->talk(
61 {
62 method => 'tv/' . $self->id,
63 params => $params
64 }
65 );
66 0 ▶ return unless $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 0 0
67 0 $self->{id} = $info->{id}; # Reset TMDB ID
68 0 return $info;
69 } ## end sub info
70  
71 ## ====================
72 ## ALTERNATIVE TITLES
73 ## ====================
74 sub alternative_titles {
75 0 ▶ my $self = shift;
Subroutine alternative_titles: not called CC=6 SCAR=37.4
Pod undocumented
76 0 my $country = shift;
77  
78 # Valid Country codes
79 0 ▶ if ($country) {
Branch: 1 branch
BranchTrueFalseTotal
if ($country) 0 0 0
80 my %valid_country_codes
81 0 = map { $_ => 1 } all_country_codes('alpha-2');
82 0 $country = uc $country;
83 0 ▶ return unless $valid_country_codes{$country};
Branch: 1 branch
BranchTrueFalseTotal
unless $valid_country_codes{$country} 0 0 0
84 } ## end if ($country)
85  
86 0 my $args = {
87 method => 'tv/' . $self->id() . '/alternative_titles',
88 params => {},
89 };
90 0 ▶ $args->{params}->{country} = $country if $country;
Branch: 1 branch
BranchTrueFalseTotal
if $country 0 0 0
91  
92 0 my $response = $self->session->talk($args);
93 0 ▶ my $titles = $response->{results} || [];
Condition0%0/2
$response->{'results'} || []
l!l
00
MC/DC0%0/1
$response->{'results'} || []
$response->{'results'}
Truth table0%0/2
A
A= $response->{'results'}
Aresult
11
00
94  
95 0 ▶ return @$titles if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
96 0 return $titles;
97 } ## end sub alternative_titles
98  
99 ## ====================
100 ## CAST
101 ## ====================
102 sub cast {
103 0 ▶ my $self = shift;
Subroutine cast: not called CC=3 SCAR=24.8
Pod undocumented
104 0 my $response = $self->_credits();
105 0 ▶ my $cast = $response->{cast} || [];
Condition0%0/2
$response->{'cast'} || []
l!l
00
MC/DC0%0/1
$response->{'cast'} || []
$response->{'cast'}
Truth table0%0/2
A
A= $response->{'cast'}
Aresult
11
00
106 0 ▶ return @$cast if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
107 0 return $cast;
108 } ## end sub cast
109  
110 ## ====================
111 ## CREW
112 ## ====================
113 sub crew {
114 0 ▶ my $self = shift;
Subroutine crew: not called CC=3 SCAR=24.8
Pod undocumented
115 0 my $response = $self->_credits();
116 0 ▶ my $crew = $response->{crew} || [];
Condition0%0/2
$response->{'crew'} || []
l!l
00
MC/DC0%0/1
$response->{'crew'} || []
$response->{'crew'}
Truth table0%0/2
A
A= $response->{'crew'}
Aresult
11
00
117 0 ▶ return @$crew if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
118 0 return $crew;
119 } ## end sub crew
120  
121 ## ====================
122 ## IMAGES
123 ## ====================
124 sub images {
125 0 ▶ my $self = shift;
Subroutine images: not called CC=2 SCAR=17.9
Pod undocumented
126 0 my $params = {};
127 0 ▶ $params->{lang} = $self->session->lang if $self->session->lang;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->lang 0 0 0
128 0 return $self->session->talk(
129 {
130 method => 'tv/' . $self->id() . '/images',
131 params => $params
132 }
133 );
134 } ## end sub images
135  
136 ## ====================
137 ## VIDEOS
138 ## ====================
139 sub videos {
140 0 ▶ my $self = shift;
Subroutine videos: not called CC=3 SCAR=24.8
Pod undocumented
141 0 my $response
142 = $self->session->talk( { method => 'tv/' . $self->id() . '/videos' } );
143 0 ▶ my $videos = $response->{results} || [];
Condition0%0/2
$response->{'results'} || []
l!l
00
MC/DC0%0/1
$response->{'results'} || []
$response->{'results'}
Truth table0%0/2
A
A= $response->{'results'}
Aresult
11
00
144  
145 0 ▶ return @$videos if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
146 0 return $videos;
147  
148 } ## end sub videos
149  
150 ## ====================
151 ## KEYWORDS
152 ## ====================
153 sub keywords {
154 0 ▶ my $self = shift;
Subroutine keywords: not called CC=4 SCAR=30.0
Pod undocumented
155 0 my $response = $self->session->talk(
156 { method => 'tv/' . $self->id() . '/keywords' } );
157 0 ▶ my $keywords_dump = $response->{results} || [];
Condition0%0/2
$response->{'results'} || []
l!l
00
MC/DC0%0/1
$response->{'results'} || []
$response->{'results'}
Truth table0%0/2
A
A= $response->{'results'}
Aresult
11
00
158 0 my @keywords;
159 0 foreach (@$keywords_dump) { push @keywords, $_->{name}; }
160 0 ▶ return @keywords if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
161 0 return \@keywords;
162 } ## end sub keywords
163  
164 ## ====================
165 ## TRANSLATIONS
166 ## ====================
167 sub translations {
168 0 ▶ my $self = shift;
Subroutine translations: not called CC=3 SCAR=24.8
Pod undocumented
169 0 my $response = $self->session->talk(
170 { method => 'tv/' . $self->id() . '/translations' } );
171 0 ▶ my $translations = $response->{translations} || [];
Condition0%0/2
$response->{'translations'} || []
l!l
00
MC/DC0%0/1
$response->{'translations'} || []
$response->{'translations'}
Truth table0%0/2
A
A= $response->{'translations'}
Aresult
11
00
172 0 ▶ return @$translations if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
173 0 return $translations;
174 } ## end sub translations
175  
176 ## ====================
177 ## SIMILAR TV SHOWS
178 ## ====================
179 sub similar {
180 0 ▶ my ( $self, $max_pages ) = @_;
Subroutine similar: not called CC=2 SCAR=17.9
Pod undocumented
181 0 ▶ return $self->session->paginate_results(
Branch: 1 branch
BranchTrueFalseTotal
$self->session->lang ? : 0 0 0
182 {
183 method => 'tv/' . $self->id() . '/similar',
184 max_pages => $max_pages,
185 params => {
186 language => $self->session->lang
187 ? $self->session->lang
188 : undef,
189 },
190 }
191 );
192 } ## end sub similar
193  
194 ## ====================
195 ## CONTENT RATING
196 ## ====================
197 sub content_ratings {
198 0 ▶ my $self = shift;
Subroutine content_ratings: not called CC=3 SCAR=24.8
Pod undocumented
199 0 my $response = $self->session->talk(
200 { method => 'tv/' . $self->id() . '/content_ratings' } );
201 0 ▶ my $content_ratings = $response->{results} || [];
Condition0%0/2
$response->{'results'} || []
l!l
00
MC/DC0%0/1
$response->{'results'} || []
$response->{'results'}
Truth table0%0/2
A
A= $response->{'results'}
Aresult
11
00
202 0 ▶ return @$content_ratings if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
203 0 return $content_ratings;
204 } ## end sub content_ratings
205  
206 ## ====================
207 ## SEASON
208 ## ====================
209 sub season {
210 0 ▶ my $self = shift;
Subroutine season: not called CC=1 SCAR=6.9
Pod undocumented
211 0 my $season = shift;
212 0 return $self->session->talk(
213 { method => 'tv/' . $self->id() . '/season/' . $season } );
214 } ## end sub season
215  
216 ## ====================
217 ## EPISODE
218 ## ====================
219 sub episode {
220 0 ▶ my $self = shift;
Subroutine episode: not called CC=1 SCAR=6.9
Pod undocumented
221 0 my $season = shift;
222 0 my $episode = shift;
223 0 return $self->session->talk(
224 {
225 method => 'tv/'
226 . $self->id()
227 . '/season/'
228 . $season
229 . '/episode/'
230 . $episode
231 }
232 );
233 } ## end sub episode
234  
235 ## ====================
236 ## CHANGES
237 ## ====================
238 sub changes {
239 0 ▶ my ( $self, @args ) = @_;
Subroutine changes: not called CC=6 SCAR=37.4
Pod undocumented
240 0 my %options = validate_with(
241 params => [@args],
242 spec => {
243 start_date => {
244 type => SCALAR,
245 optional => 1,
246 regex => qr/^\d{4}\-\d{2}\-\d{2}$/
247 },
248 end_date => {
249 type => SCALAR,
250 optional => 1,
251 regex => qr/^\d{4}\-\d{2}\-\d{2}$/
252 },
253 },
254 );
255  
256 my $changes = $self->session->talk(
257 {
258 method => 'tv/' . $self->id() . '/changes',
259 params => {
260 (
261 $options{start_date}
262 ? ( start_date => $options{start_date} )
263 : ()
264 ), (
265 $options{end_date} ? ( end_date => $options{end_date} )
266 0 ▶ : ()
Branch: 2 branches
BranchTrueFalseTotal
$options{'start_date'} ? : 0 0 0
$options{'end_date'} ? : 0 0 0
267 ),
268 },
269 }
270 );
271  
272 0 ▶ return unless defined $changes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $changes 0 0 0
273 0 ▶ return unless exists $changes->{changes};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $changes->{"changes"} 0 0 0
274 0 ▶ return @{ $changes->{changes} } if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
275 0 return $changes->{changes};
276 } ## end sub changes
277  
278 ## ====================
279 ## VERSION
280 ## ====================
281 sub version {
282 0 ▶ my ($self) = @_;
Subroutine version: not called CC=3 SCAR=24.8
Pod undocumented
283 0 ▶ my $response = $self->session->talk(
Branch: 1 branch
BranchTrueFalseTotal
my $response = $self->session->talk({"method", 'tv/' . $self->id, "want_headers", 1}) or return 0 0 0
284 {
285 method => 'tv/' . $self->id(),
286 want_headers => 1,
287 }
288 ) or return;
289 0 ▶ my $version = $response->{etag} || q();
Condition0%0/2
$response->{'etag'} || ''
l!l
00
MC/DC0%0/1
$response->{'etag'} || ''
$response->{'etag'}
Truth table0%0/2
A
A= $response->{'etag'}
Aresult
11
00
290 0 $version =~ s{"}{}gx;
291 0 return $version;
292 } ## end sub version
293  
294 #######################
295 # PRIVATE METHODS
296 #######################
297  
298 ## ====================
299 ## CREDITS
300 ## ====================
301 sub _credits {
302 0 ▶ my $self = shift;
Subroutine _credits: not called CC=1 SCAR=6.9
303 0 return $self->session->talk(
304 {
305 method => 'tv/' . $self->id() . '/credits',
306 }
307 );
308 } ## end sub _credits
309  
310 #######################
311 1 1;
« blib/lib/TMDB/Movie.pm ↑ Summary blib/lib/TMDB/Search.pm »