package MyDVDs; # Creates a reference as a hash ref, "blesses it" into the # current package, and returns the reference. sub new { my $self = {}; bless $self; return $self; } # Simple get/set accessor. If you pass it something, it will add or # replace (set) whatever is there. Always returns whatever it has (get). sub title { my $self = shift; $self->{title} = shift if @_; return $self->{title}; } sub year { my $self = shift; $self->{year} = shift if @_; return $self->{year}; } # A variation, storing data in an array. A simple improvement might be # to remove duplicates. sub stars { my $self = shift; push @{$self->{stars}}, @_ if @_; return join(', ', @{$self->{stars}}); } sub director { my $self = shift; $self->{director} = shift if @_; return $self->{director}; }