package MyClass; sub new { my $class= shift; my %self= @_ ==1 && ref $_[0] eq 'HASH'? %{ $_[0] } : @_; bless \%self, $class; } sub attribite1 { # read-only accessor $_[0]{attribute1} } sub attribute2 { # read-write accessor $_[0]{attribute2}= $_[1] if @_ > 1; $_[0]{attribute2} }