foreach my $attrname ( $self->_standard_keys() ) { my ($argname) = ($attrname =~ /^_(.*)/); if (exists $arg{$argname}) { $self->{$attrname} = $arg{$argname} } elsif ($caller_is_obj) { $self->{$attrname} = $caller->{$attrname} } else { $self->{$attrname} = $self->_default_for($attrname) } } $self->_incr_count(); return $self; } # Destructor adjusts class count sub DESTROY { $_[0]->_decr_count(); } # get or set room&shelf together sub get_location { ($_[0]->get_room(), $_[0]->get_shelf()) } sub set_location { my ($self, $room, $shelf) = @_; $self->set_room($room) if $room; $self->set_shelf($shelf) if $shelf; return; } # Implement other get_... and set_... methods (create as necessary) sub AUTOLOAD { no strict "refs"; my ($self, $newval) = @_; # Was it a get_... method? if ($AUTOLOAD =~ /.*::get(_\w+)/ && $self->_accessible($1, 'read')) { my $attr_name = $1; *{$AUTOLOAD} = sub { return $_[0]->{$attr_name} }; return $self->{$attr_name}; } # Was it a set_... method? if ($AUTOLOAD =~ /.*::set(_\w+)/ && $self->_accessible($1, 'write')) { my $attr_name = $1; *{$AUTOLOAD} = sub { $_[0]->{$attr_name} = $_[1]; return }; $self->{$1} = $newval; return; } # Must have been a mistake then... croak "No such method: $AUTOLOAD"; } 1; # Ensure that the module can be succesfully use'd