TMDB/TV.pm

filter: Statementstmt 63.8% 69 / 108 Branchbran 20.0% 8 / 40 Conditioncond 25.0% 4 / 16 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 78.2% 18 / 23 Podpod 0.0% 0 / 15 totaltotal 47.1% 99 / 210 CC 30 SCAR 26.3
CC
30
Cov
49%
alternative_titles
42.0
changes
42.0
keywords
20.0
CRAP 13.9
« TMDB/Session.pm ↑ Summary TMDB/Movie.pm »
1 package TMDB::TV;
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 Object::Tiny qw(id session);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Params::Validate qw(validate_with :types);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Locale::Codes::Country qw(all_country_codes);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 #######################
18 # LOAD DIST MODULES
19 #######################
20 3 ▶use TMDB::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 #######################
23 # VERSION
24 #######################
25 3 our $VERSION = '1.3.0';
26  
27 #######################
28 # PUBLIC METHODS
29 #######################
30  
31 ## ====================
32 ## Constructor
33 ## ====================
34 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
35 1 my $class = shift;
36 1 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 1 my $self = $class->SUPER::new(%opts);
50 1 return $self;
51 } ## end sub new
52  
53 ## ====================
54 ## INFO
55 ## ====================
56 1 ▶sub info {
Subroutine info: called CC=3 SCAR=11.2
Pod undocumented
57 1 my $self = shift;
58 1 my $params = {};
59 1 ▶ $params->{language} = $self->session->lang if $self->session->lang;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->lang 1 0 1
60 1 my $info = $self->session->talk(
61 {
62 method => 'tv/' . $self->id,
63 params => $params
64 }
65 );
66 1 ▶ return unless $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 1 1
67 1 $self->{id} = $info->{id}; # Reset TMDB ID
68 1 return $info;
69 } ## end sub info
70  
71 ## ====================
72 ## ALTERNATIVE TITLES
73 ## ====================
74 0 ▶sub alternative_titles {
Subroutine alternative_titles: not called CC=6 SCAR=37.4
Pod undocumented
75 0 my $self = shift;
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 1 ▶sub cast {
Subroutine cast: called CC=3 SCAR=11.3
Pod undocumented
103 1 my $self = shift;
104 1 my $response = $self->_credits();
105 1 ▶ my $cast = $response->{cast} || [];
Condition50%1/2
$response->{'cast'} || []
l!l
01
MC/DC0%0/1
$response->{'cast'} || []
$response->{'cast'}
Truth table50%1/2
A
A= $response->{'cast'}
Aresult
11
00
106 1 ▶ return @$cast if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 1 1
107 1 return $cast;
108 } ## end sub cast
109  
110 ## ====================
111 ## CREW
112 ## ====================
113 1 ▶sub crew {
Subroutine crew: called CC=3 SCAR=11.3
Pod undocumented
114 1 my $self = shift;
115 1 my $response = $self->_credits();
116 1 ▶ my $crew = $response->{crew} || [];
Condition50%1/2
$response->{'crew'} || []
l!l
01
MC/DC0%0/1
$response->{'crew'} || []
$response->{'crew'}
Truth table50%1/2
A
A= $response->{'crew'}
Aresult
11
00
117 1 ▶ return @$crew if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 1 1
118 1 return $crew;
119 } ## end sub crew
120  
121 ## ====================
122 ## IMAGES
123 ## ====================
124 1 ▶sub images {
Subroutine images: called CC=2 SCAR=7.0
Pod undocumented
125 1 my $self = shift;
126 1 my $params = {};
127 1 ▶ $params->{lang} = $self->session->lang if $self->session->lang;
Branch: 1 branch
BranchTrueFalseTotal
if $self->session->lang 1 0 1
128 1 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 1 ▶sub videos {
Subroutine videos: called CC=3 SCAR=11.3
Pod undocumented
140 1 my $self = shift;
141 1 my $response
142 = $self->session->talk( { method => 'tv/' . $self->id() . '/videos' } );
143 1 ▶ my $videos = $response->{results} || [];
Condition50%1/2
$response->{'results'} || []
l!l
10
MC/DC0%0/1
$response->{'results'} || []
$response->{'results'}
Truth table50%1/2
A
A= $response->{'results'}
Aresult
11
00
144  
145 1 ▶ return @$videos if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 1 1
146 1 return $videos;
147  
148 } ## end sub videos
149  
150 ## ====================
151 ## KEYWORDS
152 ## ====================
153 0 ▶sub keywords {
Subroutine keywords: not called CC=4 SCAR=30.0
Pod undocumented
154 0 my $self = shift;
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 0 ▶sub translations {
Subroutine translations: not called CC=3 SCAR=24.8
Pod undocumented
168 0 my $self = shift;
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 1 ▶sub similar {
Subroutine similar: called CC=2 SCAR=7.2
Pod undocumented
180 1 my ( $self, $max_pages ) = @_;
181 1 ▶ return $self->session->paginate_results(
Branch: 1 branch
BranchTrueFalseTotal
$self->session->lang ? : 1 0 1
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 0 ▶sub content_ratings {
Subroutine content_ratings: not called CC=3 SCAR=24.8
Pod undocumented
198 0 my $self = shift;
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 1 ▶sub season {
Subroutine season: called CC=1 SCAR=0.0
Pod undocumented
210 1 my $self = shift;
211 1 my $season = shift;
212 1 return $self->session->talk(
213 { method => 'tv/' . $self->id() . '/season/' . $season } );
214 } ## end sub season
215  
216 ## ====================
217 ## EPISODE
218 ## ====================
219 1 ▶sub episode {
Subroutine episode: called CC=1 SCAR=0.0
Pod undocumented
220 1 my $self = shift;
221 1 my $season = shift;
222 1 my $episode = shift;
223 1 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 0 ▶sub changes {
Subroutine changes: not called CC=6 SCAR=37.4
Pod undocumented
239 0 my ( $self, @args ) = @_;
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 1 ▶sub version {
Subroutine version: called CC=3 SCAR=11.3
Pod undocumented
282 1 my ($self) = @_;
283 1 ▶ my $response = $self->session->talk(
Branch: 1 branch
BranchTrueFalseTotal
my $response = $self->session->talk({"method", 'tv/' . $self->id, "want_headers", 1}) or return 1 0 1
284 {
285 method => 'tv/' . $self->id(),
286 want_headers => 1,
287 }
288 ) or return;
289 1 ▶ my $version = $response->{etag} || q();
Condition50%1/2
$response->{'etag'} || ''
l!l
01
MC/DC0%0/1
$response->{'etag'} || ''
$response->{'etag'}
Truth table50%1/2
A
A= $response->{'etag'}
Aresult
11
00
290 1 $version =~ s{"}{}gx;
291 1 return $version;
292 } ## end sub version
293  
294 #######################
295 # PRIVATE METHODS
296 #######################
297  
298 ## ====================
299 ## CREDITS
300 ## ====================
301 3 ▶sub _credits {
Subroutine _credits: called CC=1 SCAR=0.0
302 3 my $self = shift;
303 3 return $self->session->talk(
304 {
305 method => 'tv/' . $self->id() . '/credits',
306 }
307 );
308 } ## end sub _credits
309  
310 #######################
311 3 1;
« TMDB/Session.pm ↑ Summary TMDB/Movie.pm »