| 1 | package WWW::Moviepilot::Person; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use JSON::Any; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use WWW::Moviepilot::Movie; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | WWW::Moviepilot::Person - Handle moviepilot.de people | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | my $person = WWW::Moviepilot->new->(...)->person( 'paul-newman' ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # all fields | ||||||||||||||||||||||||||||
| 22 | my @fields = $person->fields; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # direct access to fields | ||||||||||||||||||||||||||||
| 25 | print $person->date_of_death; # "2008-09-26" | ||||||||||||||||||||||||||||
| 26 | print $person->title; # field does not exist => undef | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head1 METHODS | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head2 new | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | Creates a blank WWW::Moviepilot::Person object. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | my $person = WWW::Moviepilot::Person->new; | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =cut | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 0 | my ($class, $args) = @_; | |||||||||||||||||||||||||||
| 40 | my $self = bless { | ||||||||||||||||||||||||||||
| 41 | filmography => [], | ||||||||||||||||||||||||||||
| 42 | name => undef, | ||||||||||||||||||||||||||||
| 43 | m => $args->{m}, | ||||||||||||||||||||||||||||
| 44 | 0 | } => $class; | |||||||||||||||||||||||||||
| 45 | 0 | return $self; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head2 populate( $args ) | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Populates an object with data, you should not use this directly. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub populate { | ||||||||||||||||||||||||||
|
Subroutine
populate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 56 | 0 | $self->{data} = $args->{data}; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ( $self->restful_url ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | ($self->{name}) = $self->restful_url =~ m{/([^/]+)$}; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head2 character | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | If used together with a movie search, you get the name of the character | ||||||||||||||||||||||||||||
| 65 | the person plays in the movie. | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | my @cast = $movie->cast; | ||||||||||||||||||||||||||||
| 68 | foreach my $person (@cast) { | ||||||||||||||||||||||||||||
| 69 | printf "%s plays %s\n", $person->last_name, $person->character; | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub character { | ||||||||||||||||||||||||||
|
Subroutine
character: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 76 | 0 | return $self->{data}{character}; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head2 name | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Returns the internal moviepilot name for the person. | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | my @people = WWW::Moviepilot->new(...)->search_person( 'paul-newman' ); | ||||||||||||||||||||||||||||
| 84 | foreach my $person (@people) { | ||||||||||||||||||||||||||||
| 85 | print $person->name; | ||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 92 | 0 | return $self->{name}; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head2 filmography | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | Returns the filmography for the person. | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | my $person = WWW::Moviepilot->new(...)->person(...); | ||||||||||||||||||||||||||||
| 100 | my @filmography = $person->cast; | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | Returned is a list of L<WWW::Moviepilot::Person> objects. | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub filmography { | ||||||||||||||||||||||||||
|
Subroutine
filmography: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | # we have already a filmography | ||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ( @{ $self->{filmography} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | return @{ $self->{filmography} }; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ( !$name && !$self->name ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name or $self->name
MC/DC0%0/2
$name or $self->name
$name
$self->name
Truth table0%0/3
A or B
A= $nameB= $self->name
| |||||||||||||||||||||||||||||
| 115 | 0 | croak "no name provided, can't fetch filmography"; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | $name ||= $self->name; | ||||||||||||||||||||||||||
|
Condition0%0/3
$name ||= $self->name
MC/DC0%0/2
$name ||= $self->name
$name
$self->name
Truth table0%0/3
A ||= B
A= $nameB= $self->name
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | my $uri = URI->new( $self->{m}->host . '/people/' . uri_escape($name) . '/filmography.json' ); | |||||||||||||||||||||||||||
| 121 | 0 | $uri->query_form( api_key => $self->{m}->api_key ); | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | my $res = $self->{m}->ua->get( $uri->as_string ); | |||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ( $res->is_error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | croak $res->status_line; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | my $o = JSON::Any->from_json( $res->decoded_content ); | |||||||||||||||||||||||||||
| 129 | 0 | foreach my $entry ( @{ $o->{movies_people} } ) { | |||||||||||||||||||||||||||
| 130 | 0 | my $movie = WWW::Moviepilot::Movie->new({ m => $self->{m} }); | |||||||||||||||||||||||||||
| 131 | 0 | $movie->populate({ data => $entry }); | |||||||||||||||||||||||||||
| 132 | 0 | push @{ $self->{filmography} }, $movie; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | return @{ $self->{filmography} }; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =head2 fields | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Returns a list with all fields for this person. | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | my @fields = $person->fields; | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | # print all fields | ||||||||||||||||||||||||||||
| 145 | foreach my $field (@fields) { | ||||||||||||||||||||||||||||
| 146 | printf "%s: %s\n", $field. $person->$field; | ||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | As of 2009-10-14, these fields are supported: | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =over 4 | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =item * date_of_birth | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =item * date_of_death | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =item * first_name | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =item * homepage | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =item * last_name | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =item * long_description | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | =item * pseudonyms | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =item * restful_url | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | =item * sex | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =item * short_description | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =back | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =cut | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub fields { | ||||||||||||||||||||||||||
|
Subroutine
fields: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 178 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 179 | 0 | return keys %{ $self->{data}{person} }; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 2 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 183 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 184 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 185 | 0 | my $field = $AUTOLOAD; | |||||||||||||||||||||||||||
| 186 | 0 | $field =~ s/.*://; | |||||||||||||||||||||||||||
| 187 | 0 | ▶ | if ( !exists $self->{data}{person}{$field} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | 0 | return; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | return $self->{data}{person}{$field}; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 2 | 1; | |||||||||||||||||||||||||||
| 195 | __END__ | ||||||||||||||||||||||||||||