package TimeTO; # TO to pass the time around use warnings; use strict; use Carp; # constructor sub new { my $class = shift; my $self = { DATE => undef, TIME => undef, }; my $closure = sub { my $field = shift; if (@_) { $self->{$field} = shift; } return $self->{$field}; }; bless ($closure,$class); return $closure; } # a public accessor to set DATE sub setDate { &{ $_[0] }("DATE", @_[1..$#_] ) } # a public getter to get DATE sub getDate { &{ $_[0] }("DATE") } # a public accessor to set TIME sub setTime { &{ $_[0] }("TIME", @_[1..$#_] ) } # a public getter to get TIME sub getTime { &{ $_[0] }("TIME") } 1;