package Some::Package;
use strict;
use warnings;
our $VERSION = '0.1';
our $AUTOLOAD;
my %fields = (
name => undef,
);
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my %args = @_;
my $self = {
_permitted => \%fields,
%fields,
};
bless($self, $class);
foreach my $arg (keys(%args)) {
$self->$arg($args{$arg});
}
sub AUTOLOAD {
my $self = shift;
my $type = ref($self) or croak "$self is not an object";
my $name = $AUTOLOAD;
$name =~ s/.*://;
unless(exists $self->{_permitted}->{$name} ) {
croak "Can't access `$name' field in class $type";
}
if (@_) {
return $self->{$name} = shift;
} else {
return $self->{$name};
}
}
1;
####
package Some::Package::Sub;
use strict;
use warnings;
our $VERSION = '0.1';
our $AUTOLOAD;
my %fields = (
name => undef,
needthis => undef,
);
1;
####
use strict;
use warnings;
use Some::Package;
use Some::Package::Sub;
my $object = Some::Package::Sub->new(
name => 'Test',
needthis => 'Value',
}