I got to thinking. Actually generalised accessors for inside-out objects are not that difficult, not need some ev[ai]l doings.
my %speed;
my %reg;
my %owner;
my %mileage;
sub set {
my ($self, $attr, $value) = @_;
my $key = refaddr $self;
my $hashref;
eval "\$hashref = \\\%$attr";
if ( !defined $hashref ) {
carp 'Invalid attribute name';
return;
}
$hashref->{$key} = $value;
}
sub get {
my ($self, $attr, $value) = @_;
my $key = refaddr $self;
my $hashref;
eval "\$hashref = \\\%$attr";
if ( !defined $hashref ) {
carp 'Invalid attribute name';
return;
}
return $hashref->{$key};
}
BTW: I also found how to do formatting: <pre>...</pre>
No comments:
Post a Comment