in reply to Inheritence of a Constructor that uses a file-scoped lexical?

In this slight modification to your code, the amount of code duplication is kept to an absolute minimum. All there is in each derived class is a function encapsulating the specific field set definition for that class. The constructor, which is defined only in the base class, calls the field subroutine in the actual class.

This is an example of the Strategy pattern.

package Some::Package; sub new { my $proto = shift; my $class = ref($proto) || $proto; my %args = @_; my $fields_hr = $class->fields; my $self = bless { _permitted => $fields_hr, %$fields_hr, }, $class; foreach my $arg ( keys %args ) { $self->$arg( $args{$arg} ); } $self } sub AUTOLOAD { my $self = shift; my $type = ref($self) or croak "$self is not an object"; my $name = $AUTOLOAD; $name =~ s/.*://; exists $self->{_permitted}->{$name} or croak "Can't access `$name' field in class $type"; @_ and $self->{$name} = shift; $self->{$name} } # the base class also defines some field(s). sub fields { return { name => undef } } # # A derived class need only define the fields, and any other # class-specific data/behavior. # package Some::Package::Sub; use base qw(Some::Package); sub fields { return { name => undef, needthis => undef, } }