in reply to Inheritence of a Constructor that uses a file-scoped lexical?
First of all, please avoid the word fields as it is very confusing in OO. (pseudo hashes, etc...) as they are not lexically scoped (don't use my with fields).
Second, I see no inheritance operator in your classSome::Package::Sub. It misses the line
Third: The line my %fields is totally useless in the package Some::Package::Sub, as it is lexically scoped, and only consultable from with the package itself. I would suggest to create an init subroutine, and call this from inside the new statement. f.e.use base qw(Some::Package);
And in the Some::Package::Subsub new { my $proto = shift; my $class = ref($proto) || $proto; my %args = @_; bless($self, $class); $self->init(); foreach my $arg (keys(%args)) { $self->$arg($args{$arg}); } }
It least, this is the way I would do it, but since I am not perfect....sub init { my $self=shift; $self->{_permitted} = \%fields; #... and add the other fields also };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Inheritence of a Constructor that uses a file-scoped lexical?
by Orsmo (Beadle) on Oct 29, 2002 at 14:33 UTC |