sub new { my $class = shift; my $self = { FLYBEHAVIOUR => undef, QUACKBEHAVIOUR => undef, }; my @protected = qw/FLYBEHAVIOUR QUACKBEHAVIOUR/; my @private= qw//; my $closure = sub { my $field = shift; grep( /$field$/, @private ) and caller(0) eq __PACKAGE__ || confess "$field is private"; grep( /$field/, @protected ) and caller(0)->isa(__PACKAGE__) || confess "$field is protected"; if (@_) { $self->{$field} = shift; } return $self->{$field}; }; bless( $closure, $class ); return $closure; }