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 };
In reply to Re: Inheritence of a Constructor that uses a file-scoped lexical?
by mce
in thread Inheritence of a Constructor that uses a file-scoped lexical?
by Orsmo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |