package Movie; use strict; use warnings; use overload '""' => \&string; sub new { my $class = shift; my ($title, $year) = @_; my $movie = { title=>$title, year=>$year, stars=>[] }; bless $movie, $class; } sub add_actor { my $movie = shift; my $actor = shift; push @{$movie->{stars}}, $actor; } sub actors { my $movie = shift; sort @{$movie->{stars}}; } sub string { my $movie = shift; "$movie->{title} ($movie->{year})"; } 1;