gargle has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monks,
How does one go to extend a base class that's implemented by means of a closure?
I have a base class in which the constructor initializes three fields
# constructor sub new { my $class = shift; my $self = { NAME => undef, ADDRESS => undef, PHONE => undef, }; my $closure = sub { my $field = shift; if (@_) { $self->{$field} = shift; } return $self->{$field}; }; bless( $closure, $class ); return $closure; }
I'd like to extend this class and add two more fields:
# constructor sub new { my $class = shift; my $self = { CELLULAR => undef, EMAIL => undef, }; my $closure = sub { my $field = shift; if (@_) { $self->{$field} = shift; } return $self->{$field}; }; bless( $closure, $class ); return $closure; }
How do I make the extended class call the constructor of the base class and make sure that the two new fields are added at the same time?
I searched but couldn't find any documentation about this, not on perl monks, not on google :(
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: OO: extending a closure object
by diotalevi (Canon) on Feb 22, 2006 at 20:25 UTC | |
by gargle (Chaplain) on Feb 23, 2006 at 08:18 UTC | |
by Roy Johnson (Monsignor) on Feb 23, 2006 at 21:31 UTC | |
Re: OO: extending a closure object
by Roy Johnson (Monsignor) on Feb 22, 2006 at 20:24 UTC |