| 1 | package WWW::Moviepilot::Movie; | ||||||||||||||||||||||||||||
| 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::Person; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | WWW::Moviepilot::Movie - Handle moviepilot.de movies | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | my $movie = WWW::Moviepilot->new(...)->movie( 'matrix' ); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # all fields | ||||||||||||||||||||||||||||
| 22 | my @fields = $movie->fields; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # direct access to fields | ||||||||||||||||||||||||||||
| 25 | print $movie->display_title; # "Matrix" | ||||||||||||||||||||||||||||
| 26 | print $movie->title; # field does not exist => undef | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # *_lists in scalar context | ||||||||||||||||||||||||||||
| 29 | print scalar $movie->emotions_list; # "Spannend,Aufregend" | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # *_lists in list context | ||||||||||||||||||||||||||||
| 32 | print join ' +++ ', $movie->emotions_list # "Spannend +++ Aufregend" | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 METHODS | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head2 new | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | Creates a blank WWW::Moviepilot::Movie object. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | my $movie = WWW::Moviepilot::Movie->new; | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =cut | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 0 | my ($class, $args) = @_; | |||||||||||||||||||||||||||
| 46 | my $self = bless { | ||||||||||||||||||||||||||||
| 47 | cast => [], | ||||||||||||||||||||||||||||
| 48 | data => {}, | ||||||||||||||||||||||||||||
| 49 | name => undef, | ||||||||||||||||||||||||||||
| 50 | m => $args->{m} | ||||||||||||||||||||||||||||
| 51 | 0 | } => $class; | |||||||||||||||||||||||||||
| 52 | 0 | return $self; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head2 populate( $args ) | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Populates an object with data, you should not use this directly. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =cut | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub populate { | ||||||||||||||||||||||||||
|
Subroutine
populate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 63 | 0 | $self->{data} = $args->{data}; | |||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ( $self->restful_url ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | ($self->{name}) = $self->restful_url =~ m{/([^/]+)$}; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head2 character | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | If used together with a filmography search, you get the name of the character | ||||||||||||||||||||||||||||
| 72 | the person plays in the movie. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | my @filmography = $person->filmography; | ||||||||||||||||||||||||||||
| 75 | foreach my $movie (@filmography) { | ||||||||||||||||||||||||||||
| 76 | printf "%s plays %s\n", $person->last_name, $movie->character; | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub character { | ||||||||||||||||||||||||||
|
Subroutine
character: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 82 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 83 | 0 | return $self->{data}{character}; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head2 name | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Returns the internal moviepilot name for the movie. | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | my @movies = WWW::Moviepilot->new(...)->search_movie( 'matrix' ); | ||||||||||||||||||||||||||||
| 91 | foreach my $movie (@movies) { | ||||||||||||||||||||||||||||
| 92 | print $movie->name; | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||
| 95 | matrix | ||||||||||||||||||||||||||||
| 96 | armitage-iii-dual-matrix | ||||||||||||||||||||||||||||
| 97 | the-matrix-reloaded | ||||||||||||||||||||||||||||
| 98 | the-matrix-revolutions | ||||||||||||||||||||||||||||
| 99 | madrid | ||||||||||||||||||||||||||||
| 100 | mourir-a-madrid | ||||||||||||||||||||||||||||
| 101 | die-sieben-kleider-der-katrin | ||||||||||||||||||||||||||||
| 102 | super-mario-bros | ||||||||||||||||||||||||||||
| 103 | armitage-iii-polymatrix | ||||||||||||||||||||||||||||
| 104 | rendezvous-in-madrid | ||||||||||||||||||||||||||||
| 105 | herr-puntila-und-sein-knecht-matti | ||||||||||||||||||||||||||||
| 106 | drei-maedchen-in-madrid | ||||||||||||||||||||||||||||
| 107 | zwischen-madrid-und-paris | ||||||||||||||||||||||||||||
| 108 | marie-antoinette-2 | ||||||||||||||||||||||||||||
| 109 | mario-und-der-zauberer | ||||||||||||||||||||||||||||
| 110 | bezaubernde-marie-2 | ||||||||||||||||||||||||||||
| 111 | marie-lloyd | ||||||||||||||||||||||||||||
| 112 | marie-line | ||||||||||||||||||||||||||||
| 113 | marie-antoinette-3 | ||||||||||||||||||||||||||||
| 114 | maria-magdalena | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 120 | 0 | return $self->{name}; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | =head2 cast | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | Returns the cast for the movie. | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | my $movie = WWW::Moviepilot->new(...)->movie(...); | ||||||||||||||||||||||||||||
| 128 | my @cast = $movie->cast; | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | Returned is a list of L<WWW::Moviepilot::Person> objects. | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | ▶ | sub cast { | ||||||||||||||||||||||||||
|
Subroutine
cast: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 135 | 0 | my ($self, $movie) = @_; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # we have already a cast | ||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if ( @{ $self->{cast} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | return @{ $self->{cast} }; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ( !$movie && !$self->name ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$movie or $self->name
MC/DC0%0/2
$movie or $self->name
$movie
$self->name
Truth table0%0/3
A or B
A= $movieB= $self->name
| |||||||||||||||||||||||||||||
| 143 | 0 | croak "no movie name provided, can't fetch cast"; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $movie ||= $self->name; | ||||||||||||||||||||||||||
|
Condition0%0/3
$movie ||= $self->name
MC/DC0%0/2
$movie ||= $self->name
$movie
$self->name
Truth table0%0/3
A ||= B
A= $movieB= $self->name
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | my $uri = URI->new( $self->{m}->host . '/movies/' . uri_escape($movie) . '/casts.json' ); | |||||||||||||||||||||||||||
| 149 | 0 | $uri->query_form( api_key => $self->{m}->api_key ); | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | my $res = $self->{m}->ua->get( $uri->as_string ); | |||||||||||||||||||||||||||
| 152 | 0 | ▶ | if ( $res->is_error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 0 | croak $res->status_line; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | my $o = JSON::Any->from_json( $res->decoded_content ); | |||||||||||||||||||||||||||
| 157 | 0 | foreach my $entry ( @{ $o->{movies_people} } ) { | |||||||||||||||||||||||||||
| 158 | 0 | my $person = WWW::Moviepilot::Person->new({ m => $self->{m} }); | |||||||||||||||||||||||||||
| 159 | 0 | $person->populate({ data => $entry }); | |||||||||||||||||||||||||||
| 160 | 0 | push @{ $self->{cast} }, $person; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | return @{ $self->{cast} }; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =head2 fields | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | Returns a list with all fields for this movie. | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | my @fields = $movie->fields; | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # print all fields | ||||||||||||||||||||||||||||
| 173 | foreach my $field ( @fields ) { | ||||||||||||||||||||||||||||
| 174 | printf "%s: %s\n", $field. $movie->$field; | ||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | As of 2009-10-13, these fields are supported: | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =over 4 | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | =item * alternative_identifiers | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =item * average_community_rating | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =item * average_critics_rating | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =item * cinema_start_date | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | =item * countries_list | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =item * display_title | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =item * dvd_start_date | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =item * emotions_list | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | =item * genres_list | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =item * homepage | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =item * long_description | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =item * on_tv | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | =item * places_list | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | =item * plots_list | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =item * poster | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =item * premiere_date | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =item * production_year | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | =item * restful_url | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | =item * runtime | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | =item * short_description | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =item * times_list | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =back | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | =cut | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 0 | ▶ | sub fields { | ||||||||||||||||||||||||||
|
Subroutine
fields: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 228 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 229 | 0 | return keys %{ $self->{data}{movie} }; | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 2 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 233 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 234 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 235 | 0 | my $field = $AUTOLOAD; | |||||||||||||||||||||||||||
| 236 | 0 | $field =~ s/.*://; | |||||||||||||||||||||||||||
| 237 | 0 | ▶ | if ( !exists $self->{data}{movie}{$field} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 0 | return; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 0 | ▶ | if ( $field =~ /_list$/ && wantarray ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$field =~ /_list$/ and wantarray
MC/DC0%0/2
$field =~ /_list$/ and wantarray
$field =~ /_list$/
wantarray
Truth table0%0/3
A and B
A= $field =~ /_list$/B= wantarray
| |||||||||||||||||||||||||||||
| 242 | 0 | return split /,/, $self->{data}{movie}{$field}; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | return $self->{data}{movie}{$field}; | |||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | 2 | 1; | |||||||||||||||||||||||||||
| 249 | __END__ | ||||||||||||||||||||||||||||