awohld has asked for the wisdom of the Perl Monks concerning the following question:
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_attri +bute_key" if @invalid_attribute_key; } bless $self, $class; return $self; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Module to Check Constructors?
by moritz (Cardinal) on Mar 09, 2012 at 17:04 UTC | |
by tobyink (Canon) on Mar 09, 2012 at 17:32 UTC | |
by choroba (Cardinal) on Mar 09, 2012 at 18:02 UTC | |
|
Re: Module to Check Constructors?
by Arunbear (Prior) on Mar 09, 2012 at 17:59 UTC | |
|
Re: Module to Check Constructors?
by JavaFan (Canon) on Mar 09, 2012 at 17:46 UTC |