package Movie; use strict; use warnings FATAL => qw( all ); use Lingua::EN::Inflect qw(A PL_N NUM NUMWORDS inflect); my $current_year = (localtime())[5] + 1900; sub title { $_[0]->{'title'} } # returns the start year of a movie sub start_year { $_[0]->{'start year'} } # returns a numeric end year of a movie for comparisons sub end_year { my $self = shift; $self->{'end year'} or return $self->{'start year'}; $self->{'end year'} eq 'tbd' and return $current_year; $self->{'end year'} } # returns a string with the run time of a television series. sub run_time { my $self = shift; $self->{'media'} eq 'tv' or return(); $self->{'end year'} eq 'tbd' and return "which is still running"; my $sy = $self->start_year; my $ey = $self->end_year; $ey == $sy and return "which ran for less than a year"; my $run_time = $ey - $sy; inflect("which ran for NUMWORDS($run_time) PL_N(year,$run_time)"); } # returns the media type of a movie sub media { my $self = shift; $self->{'media'} eq 'tv' ? 'television series' : $self->{'media'} } # returns what the movie is based on and by who or what sub basis { my $self = shift; $self->{'based on'} or return(); qq(based on the $self->{'based on'} by $self->{'company'}) } # returns a string with nearly all the properties of a movie sub movie_is { my $self = shift; A(join(' ', grep { defined $_ } $self->start_year, $self->media, $self->basis, $self->run_time )).'.'; } 1;