| 1 | package TMDB::Person; | ||||||||||||
| 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 | |||||||||||||
| 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=0.0
Pod
undocumented
| |||||||||||||
| 34 | 1 | my $class = shift; | |||||||||||
| 35 | 1 | 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 | 1 | my $self = $class->SUPER::new(%opts); | |||||||||||
| 49 | 1 | return $self; | |||||||||||
| 50 | } ## end sub new | ||||||||||||
| 51 | |||||||||||||
| 52 | ## ==================== | ||||||||||||
| 53 | ## INFO | ||||||||||||
| 54 | ## ==================== | ||||||||||||
| 55 | 5 | ▶ | sub info { | ||||||||||
|
Subroutine
info: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 56 | 5 | my $self = shift; | |||||||||||
| 57 | 5 | return $self->session->talk( | |||||||||||
| 58 | { | ||||||||||||
| 59 | method => 'person/' . $self->id(), | ||||||||||||
| 60 | } | ||||||||||||
| 61 | ); | ||||||||||||
| 62 | } ## end sub info | ||||||||||||
| 63 | |||||||||||||
| 64 | ## ==================== | ||||||||||||
| 65 | ## CREDITS | ||||||||||||
| 66 | ## ==================== | ||||||||||||
| 67 | 7 | ▶ | sub credits { | ||||||||||
|
Subroutine
credits: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 68 | 7 | my $self = shift; | |||||||||||
| 69 | 7 | return $self->session->talk( | |||||||||||
| 70 | { | ||||||||||||
| 71 | method => 'person/' . $self->id() . '/credits', | ||||||||||||
| 72 | } | ||||||||||||
| 73 | ); | ||||||||||||
| 74 | } ## end sub credits | ||||||||||||
| 75 | |||||||||||||
| 76 | ## ==================== | ||||||||||||
| 77 | ## IMAGES | ||||||||||||
| 78 | ## ==================== | ||||||||||||
| 79 | 0 | ▶ | sub images { | ||||||||||
|
Subroutine
images: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 80 | 0 | my $self = shift; | |||||||||||
| 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'} || []
MC/DC0%0/1
$response->{'profiles'} || []
$response->{'profiles'}
Truth table0%0/2
A
A= $response->{'profiles'}
| |||||||||||||
| 87 | } ## end sub images | ||||||||||||
| 88 | |||||||||||||
| 89 | ## ==================== | ||||||||||||
| 90 | ## VERSION | ||||||||||||
| 91 | ## ==================== | ||||||||||||
| 92 | 1 | ▶ | sub version { | ||||||||||
|
Subroutine
version: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||
| 93 | 1 | my ($self) = @_; | |||||||||||
| 94 | 1 | ▶ | my $response = $self->session->talk( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 95 | { | ||||||||||||
| 96 | method => 'person/' . $self->id(), | ||||||||||||
| 97 | want_headers => 1, | ||||||||||||
| 98 | } | ||||||||||||
| 99 | ) or return; | ||||||||||||
| 100 | 1 | ▶ | my $version = $response->{etag} || q(); | ||||||||||
|
Condition50%1/2
$response->{'etag'} || ''
MC/DC0%0/1
$response->{'etag'} || ''
$response->{'etag'}
Truth table50%1/2
A
A= $response->{'etag'}
| |||||||||||||
| 101 | 1 | $version =~ s{"}{}gx; | |||||||||||
| 102 | 1 | return $version; | |||||||||||
| 103 | } ## end sub version | ||||||||||||
| 104 | |||||||||||||
| 105 | ## ==================== | ||||||||||||
| 106 | ## INFO HELPERS | ||||||||||||
| 107 | ## ==================== | ||||||||||||
| 108 | |||||||||||||
| 109 | # Name | ||||||||||||
| 110 | 1 | ▶ | sub name { | ||||||||||
|
Subroutine
name: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||
| 111 | 1 | my ($self) = @_; | |||||||||||
| 112 | 1 | my $info = $self->info(); | |||||||||||
| 113 | 1 | ▶ | return unless $info; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 114 | 1 | ▶ | return $info->{name} || q(); | ||||||||||
|
Condition50%1/2
$info->{'name'} || ''
MC/DC0%0/1
$info->{'name'} || ''
$info->{'name'}
Truth table50%1/2
A
A= $info->{'name'}
| |||||||||||||
| 115 | } ## end sub name | ||||||||||||
| 116 | |||||||||||||
| 117 | # Alternative names | ||||||||||||
| 118 | 1 | ▶ | sub aka { | ||||||||||
|
Subroutine
aka: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||
| 119 | 1 | my ($self) = @_; | |||||||||||
| 120 | 1 | my $info = $self->info(); | |||||||||||
| 121 | 1 | ▶ | return unless $info; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 122 | 1 | ▶ | my @aka = $info->{also_known_as} || []; | ||||||||||
|
Condition50%1/2
$info->{'also_known_as'} || []
MC/DC0%0/1
$info->{'also_known_as'} || []
$info->{'also_known_as'}
Truth table50%1/2
A
A= $info->{'also_known_as'}
| |||||||||||||
| 123 | 1 | ▶ | return @aka if wantarray; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 124 | 1 | return \@aka; | |||||||||||
| 125 | } ## end sub aka | ||||||||||||
| 126 | |||||||||||||
| 127 | # Bio | ||||||||||||
| 128 | 1 | ▶ | sub bio { | ||||||||||
|
Subroutine
bio: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||
| 129 | 1 | my ($self) = @_; | |||||||||||
| 130 | 1 | my $info = $self->info(); | |||||||||||
| 131 | 1 | ▶ | return unless $info; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 132 | 1 | ▶ | return $info->{biography} || q(); | ||||||||||
|
Condition50%1/2
$info->{'biography'} || ''
MC/DC0%0/1
$info->{'biography'} || ''
$info->{'biography'}
Truth table50%1/2
A
A= $info->{'biography'}
| |||||||||||||
| 133 | } ## end sub bio | ||||||||||||
| 134 | |||||||||||||
| 135 | # Image | ||||||||||||
| 136 | 1 | ▶ | sub image { | ||||||||||
|
Subroutine
image: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||
| 137 | 1 | my ($self) = @_; | |||||||||||
| 138 | 1 | my $info = $self->info(); | |||||||||||
| 139 | 1 | ▶ | return unless $info; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 140 | 1 | ▶ | return $info->{profile_path} || q(); | ||||||||||
|
Condition50%1/2
$info->{'profile_path'} || ''
MC/DC0%0/1
$info->{'profile_path'} || ''
$info->{'profile_path'}
Truth table50%1/2
A
A= $info->{'profile_path'}
| |||||||||||||
| 141 | } ## end sub image | ||||||||||||
| 142 | |||||||||||||
| 143 | ## ==================== | ||||||||||||
| 144 | ## CREDIT HELPERS | ||||||||||||
| 145 | ## ==================== | ||||||||||||
| 146 | |||||||||||||
| 147 | # Acted in | ||||||||||||
| 148 | 1 | ▶ | sub starred_in { | ||||||||||
|
Subroutine
starred_in: called CC=4 SCAR=14.6
Pod
undocumented
| |||||||||||||
| 149 | 1 | my $self = shift; | |||||||||||
| 150 | 1 | ▶ | my $movies = $self->credits()->{cast} || []; | ||||||||||
|
Condition50%1/2
$self->credits->{'cast'} || []
MC/DC0%0/1
$self->credits->{'cast'} || []
$self->credits->{'cast'}
Truth table50%1/2
A
A= $self->credits->{'cast'}
| |||||||||||||
| 151 | 1 | my @names; | |||||||||||
| 152 | 0 | foreach (@$movies) { push @names, $_->{title}; } | |||||||||||
| 153 | 1 | ▶ | return @names if wantarray; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 154 | 1 | return \@names; | |||||||||||
| 155 | } ## end sub starred_in | ||||||||||||
| 156 | |||||||||||||
| 157 | # Crew member | ||||||||||||
| 158 | 1 | ▶ | sub directed { return shift->_crew_names('Director'); } | ||||||||||
|
Subroutine
directed: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 159 | 1 | ▶ | sub produced { return shift->_crew_names('Producer'); } | ||||||||||
|
Subroutine
produced: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 160 | 1 | ▶ | sub executive_produced { return shift->_crew_names('Executive Producer'); } | ||||||||||
|
Subroutine
executive_produced: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 161 | 1 | ▶ | sub wrote { return shift->_crew_names('Author|Novel|Screenplay|Writer'); } | ||||||||||
|
Subroutine
wrote: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 162 | |||||||||||||
| 163 | ####################### | ||||||||||||
| 164 | # PRIVATE METHODS | ||||||||||||
| 165 | ####################### | ||||||||||||
| 166 | |||||||||||||
| 167 | ## ==================== | ||||||||||||
| 168 | ## CREW NAMES | ||||||||||||
| 169 | ## ==================== | ||||||||||||
| 170 | 5 | ▶ | sub _crew_names { | ||||||||||
|
Subroutine
_crew_names: called CC=5 SCAR=18.1
| |||||||||||||
| 171 | 5 | my $self = shift; | |||||||||||
| 172 | 5 | my $job = shift; | |||||||||||
| 173 | |||||||||||||
| 174 | 5 | my @names; | |||||||||||
| 175 | 5 | ▶ | my $crew = $self->credits()->{crew} || []; | ||||||||||
|
Condition50%1/2
$self->credits->{'crew'} || []
MC/DC0%0/1
$self->credits->{'crew'} || []
$self->credits->{'crew'}
Truth table50%1/2
A
A= $self->credits->{'crew'}
| |||||||||||||
| 176 | 5 | foreach (@$crew) { | |||||||||||
| 177 | 0 | ▶ | push @names, $_->{title} if ( $_->{job} =~ m{$job}xi ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 178 | } | ||||||||||||
| 179 | |||||||||||||
| 180 | 5 | ▶ | return @names if wantarray; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 181 | 5 | return \@names; | |||||||||||
| 182 | } ## end sub _crew_names | ||||||||||||
| 183 | |||||||||||||
| 184 | ####################### | ||||||||||||
| 185 | 3 | 1; | |||||||||||