in reply to Re^2: Fields pragma - the poor man's OO framework?
in thread Fields pragma - the poor man's OO framework?
Now, you have all the benefits of static fieldname checking without going into the depths of a deprecated feature. Maybe it's just me, but I'd strongly prefer that.use Tie::Hash::FixedKeys; my @keys = qw( a b c ); sub new { my $class = shift; my %args = @_; my $self = {}; tie %$self, 'Tie::Hash::FixedKeys', @keys; foreach my $k ( @keys ) { if ( exists $args{$k} ) { $self->{$k} = $args->{$k}; } } return bless $self, $class; }
Of course, the better solution is to create your own OO framework that auto-generates mutators based on some static list of mutator names. Writing one is the matter of a couple hours. You can even crib heavily from CPAN and call it your own work. That way, everything is a method call. Direct attribute access is horrible practice.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Fields pragma - the poor man's OO framework?
by Arunbear (Prior) on Jul 07, 2008 at 10:07 UTC | |
by dragonchild (Archbishop) on Jul 07, 2008 at 12:58 UTC | |
by waba (Monk) on Jul 08, 2008 at 18:54 UTC |