blib/lib/TMDB/Person.pm

filter: Statementstmt 27.4% 20 / 73 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 28.5% 6 / 21 Podpod 0.0% 0 / 14 totaltotal 17.3% 26 / 150 CC 20 SCAR 25.0
CC
20
Cov
19%
_crew_names
30.0
aka
20.0
starred_in
20.0
CRAP 12.2
« blib/lib/TMDB/Genre.pm ↑ Summary blib/lib/TMDB/Collection.pm »
1 package TMDB::Person;
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  
16 #######################
17 # LOAD DIST MODULES
18 #######################
19 1 ▶use TMDB::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 #######################
22 # VERSION
23 #######################
24 1 our $VERSION = '1.2.0';
25  
26 #######################
27 # PUBLIC METHODS
28 #######################
29  
30 ## ====================
31 ## Constructor
32 ## ====================
33 sub new {
34 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my %opts = validate_with(
36 params => \@_,
37 spec => {
38 session => {
39 type => OBJECT,
40 isa => 'TMDB::Session',
41 },
42 id => {
43 type => SCALAR,
44 },
45 },
46 );
47  
48 0 my $self = $class->SUPER::new(%opts);
49 0 return $self;
50 } ## end sub new
51  
52 ## ====================
53 ## INFO
54 ## ====================
55 sub info {
56 0 ▶ my $self = shift;
Subroutine info: not called CC=1 SCAR=6.9
Pod undocumented
57 0 return $self->session->talk(
58 {
59 method => 'person/' . $self->id(),
60 }
61 );
62 } ## end sub info
63  
64 ## ====================
65 ## CREDITS
66 ## ====================
67 sub credits {
68 0 ▶ my $self = shift;
Subroutine credits: not called CC=1 SCAR=6.9
Pod undocumented
69 0 return $self->session->talk(
70 {
71 method => 'person/' . $self->id() . '/credits',
72 }
73 );
74 } ## end sub credits
75  
76 ## ====================
77 ## IMAGES
78 ## ====================
79 sub images {
80 0 ▶ my $self = shift;
Subroutine images: not called CC=2 SCAR=17.9
Pod undocumented
81 0 my $response = $self->session->talk(
82 {
83 method => 'person/' . $self->id() . '/images',
84 }
85 );
86 0 ▶ return $response->{profiles} || [];
Condition0%0/2
$response->{'profiles'} || []
l!l
00
MC/DC0%0/1
$response->{'profiles'} || []
$response->{'profiles'}
Truth table0%0/2
A
A= $response->{'profiles'}
Aresult
11
00
87 } ## end sub images
88  
89 ## ====================
90 ## VERSION
91 ## ====================
92 sub version {
93 0 ▶ my ($self) = @_;
Subroutine version: not called CC=3 SCAR=24.8
Pod undocumented
94 0 ▶ my $response = $self->session->talk(
Branch: 1 branch
BranchTrueFalseTotal
my $response = $self->session->talk({"method", 'person/' . $self->id, "want_headers", 1}) or return 0 0 0
95 {
96 method => 'person/' . $self->id(),
97 want_headers => 1,
98 }
99 ) or return;
100 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
101 0 $version =~ s{"}{}gx;
102 0 return $version;
103 } ## end sub version
104  
105 ## ====================
106 ## INFO HELPERS
107 ## ====================
108  
109 # Name
110 sub name {
111 0 ▶ my ($self) = @_;
Subroutine name: not called CC=3 SCAR=24.8
Pod undocumented
112 0 my $info = $self->info();
113 0 ▶ return unless $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 0 0
114 0 ▶ return $info->{name} || q();
Condition0%0/2
$info->{'name'} || ''
l!l
00
MC/DC0%0/1
$info->{'name'} || ''
$info->{'name'}
Truth table0%0/2
A
A= $info->{'name'}
Aresult
11
00
115 } ## end sub name
116  
117 # Alternative names
118 sub aka {
119 0 ▶ my ($self) = @_;
Subroutine aka: not called CC=4 SCAR=30.0
Pod undocumented
120 0 my $info = $self->info();
121 0 ▶ return unless $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 0 0
122 0 ▶ my @aka = $info->{also_known_as} || [];
Condition0%0/2
$info->{'also_known_as'} || []
l!l
00
MC/DC0%0/1
$info->{'also_known_as'} || []
$info->{'also_known_as'}
Truth table0%0/2
A
A= $info->{'also_known_as'}
Aresult
11
00
123 0 ▶ return @aka if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
124 0 return \@aka;
125 } ## end sub aka
126  
127 # Bio
128 sub bio {
129 0 ▶ my ($self) = @_;
Subroutine bio: not called CC=3 SCAR=24.8
Pod undocumented
130 0 my $info = $self->info();
131 0 ▶ return unless $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 0 0
132 0 ▶ return $info->{biography} || q();
Condition0%0/2
$info->{'biography'} || ''
l!l
00
MC/DC0%0/1
$info->{'biography'} || ''
$info->{'biography'}
Truth table0%0/2
A
A= $info->{'biography'}
Aresult
11
00
133 } ## end sub bio
134  
135 # Image
136 sub image {
137 0 ▶ my ($self) = @_;
Subroutine image: not called CC=3 SCAR=24.8
Pod undocumented
138 0 my $info = $self->info();
139 0 ▶ return unless $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 0 0
140 0 ▶ return $info->{profile_path} || q();
Condition0%0/2
$info->{'profile_path'} || ''
l!l
00
MC/DC0%0/1
$info->{'profile_path'} || ''
$info->{'profile_path'}
Truth table0%0/2
A
A= $info->{'profile_path'}
Aresult
11
00
141 } ## end sub image
142  
143 ## ====================
144 ## CREDIT HELPERS
145 ## ====================
146  
147 # Acted in
148 sub starred_in {
149 0 ▶ my $self = shift;
Subroutine starred_in: not called CC=4 SCAR=30.0
Pod undocumented
150 0 ▶ my $movies = $self->credits()->{cast} || [];
Condition0%0/2
$self->credits->{'cast'} || []
l!l
00
MC/DC0%0/1
$self->credits->{'cast'} || []
$self->credits->{'cast'}
Truth table0%0/2
A
A= $self->credits->{'cast'}
Aresult
11
00
151 0 my @names;
152 0 foreach (@$movies) { push @names, $_->{title}; }
153 0 ▶ return @names if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
154 0 return \@names;
155 } ## end sub starred_in
156  
157 # Crew member
158 0 ▶sub directed { return shift->_crew_names('Director'); }
Subroutine directed: not called CC=1 SCAR=6.9
Pod undocumented
159 0 ▶sub produced { return shift->_crew_names('Producer'); }
Subroutine produced: not called CC=1 SCAR=6.9
Pod undocumented
160 0 ▶sub executive_produced { return shift->_crew_names('Executive Producer'); }
Subroutine executive_produced: not called CC=1 SCAR=6.9
Pod undocumented
161 0 ▶sub wrote { return shift->_crew_names('Author|Novel|Screenplay|Writer'); }
Subroutine wrote: not called CC=1 SCAR=6.9
Pod undocumented
162  
163 #######################
164 # PRIVATE METHODS
165 #######################
166  
167 ## ====================
168 ## CREW NAMES
169 ## ====================
170 sub _crew_names {
171 0 ▶ my $self = shift;
Subroutine _crew_names: not called CC=5 SCAR=34.0
172 0 my $job = shift;
173  
174 0 my @names;
175 0 ▶ my $crew = $self->credits()->{crew} || [];
Condition0%0/2
$self->credits->{'crew'} || []
l!l
00
MC/DC0%0/1
$self->credits->{'crew'} || []
$self->credits->{'crew'}
Truth table0%0/2
A
A= $self->credits->{'crew'}
Aresult
11
00
176 0 foreach (@$crew) {
177 0 ▶ push @names, $_->{title} if ( $_->{job} =~ m{$job}xi );
Branch: 1 branch
BranchTrueFalseTotal
if $_->{"job"} =~ /$job/xi 0 0 0
178 }
179  
180 0 ▶ return @names if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
181 0 return \@names;
182 } ## end sub _crew_names
183  
184 #######################
185 1 1;
« blib/lib/TMDB/Genre.pm ↑ Summary blib/lib/TMDB/Collection.pm »