sub new { my ( $class, @attributes ) = @_; my $self = {@attributes}; # make sure we got valid argument keys if ( @attributes ) { my $key_hash = {@attributes}; my @keys = keys %$key_hash; my @invalid_attribute_key = grep { my $tested_attributes = $_; not grep { $tested_attributes eq $_ } qw(attribute_1 attribute_2 attribute_3); } @keys; croak "invalid attribute key(s) in constructor: @invalid_attribute_key" if @invalid_attribute_key; } bless $self, $class; return $self; }