in reply to Storing Info with Accessors
As an aside, you've chosen a rather roundabout way to make accessors with that string eval. Why not just use a closure:
sub _create_accessors { my %orderObjectFields = @_; foreach my $field ( keys %orderObjectFields ) { my $default = $orderObjectFields{$field}; no strict 'refs'; *{ __PACKAGE__ . "::$field" } = sub { my $value = ( scalar @_ > 1 ? $_[0]->{$field} = $_[1] : $_[0]->{$fie +ld} ); $value = $default unless defined $value; $value; }; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Storing Info with Accessors
by graq (Curate) on Aug 02, 2001 at 12:30 UTC | |
by bikeNomad (Priest) on Aug 02, 2001 at 17:34 UTC |