in reply to Implementing State pattern

You're calling alertness as a method, on the $state object. That means alertness() the sub receives $state the object as its first argument. You shift that into $curAlertness, and return it. You're also not doing anything with the other parameter that you pass in ($vars->{ALERTNESS}), so the $state object never gets updated.

I suspect you want something like this for the implementation of alertness:

sub alertness { my $self = shift; if( @_ ) { $self->{STATE} = shift; } return $self->{STATE}; }