# MyDay.pm # Interface to objects representing days package MyDay; use strict; use warnings; sub new { # This is boilerplate code you can copy. # But you'd be better off with a module so you don't have to do it by hand. # Check out Class::Tiny or Moo my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; bless ($self, $class); return $self; } sub mood { my $self = shift; # If there's an argument provided, set the value, # then in either case, return the current value. if ( @_ ) { $self->{'mood'} = shift; } return $self->{'mood'}; } sub predict { my $self = shift; my $prediction; # Get the mood by calling the mood() method on your object # ... referred to as $self here while you're inside it if ( $self->mood eq 'happy' ) { $prediction = 'be great'; } elsif ( $self->mood eq 'sad' ) { $prediction = 'get better'; } return $prediction; # undef if no mood } 1; # module must return a true value