use Carp qw(croak); sub set_colour { my $this = shift croak 'set_colour requires an argument' unless @_; $this->{colour} = shift; } # if you like combined setter/getters use Scalar::Util qw(reftype); sub colour { my $this = shift; if ( @_ ) { my $arg = shift; croak 'Illegal value for method colour' unless reftype $arg eq 'ARRAY'; $this->{colour} = $arg; } return @{ $this->{colour}||[] }; }