use Encapsulation; sub new { bless {}, shift; } sub foo { my $self = shift; return $self->{foo} unless @_; $self->{foo} = shift; } 1;