#!perl -w use strict; =head1 NAME GetterSetter.pm =head1 DESCRIPTION Base class to use field variable names to get, name(), and set, name($value). All fields must be initialized. =head1 USAGE package GoGetter; use GetterSetter; our @ISA = qw/GetterSetter/; . . . my $helper = GoGetter->new( ); $helper->action("BLAST nih"); print "Action is: $helper->action()\n"; =head1 NOTES Simple coding but opens class to slower set and get. Caution: this makes all data public. =head1 AUTHOR One of many AUTOLOAD examples =head1 METHODS Method documentation follows =over 4 =cut # Inheritance class which ISA GetterSetter package GetterSetter; use Carp; our $AUTOLOAD; BEGIN { our ($VERSION); $VERSION = "0.001"; $VERSION = eval $VERSION; } =item AUTOLOAD( ) called by Perl to resolve names =item $value = $obj->NAME( ); Get or return the objects hash name. =item $obj->NAME($VALUE); Set the $obj hash name to $value. Return the objects hash value. Error out if no name exists. =cut sub AUTOLOAD { my $self = shift; my $type = ref($self) or croak "$self is not an object"; my $name = $AUTOLOAD; $name =~ s/.*://; # strip fully-qualified portion croak "Can't access `$name' field in class $type" unless (exists $self->{$name}); if (@_) { return $self->{$name} = shift; } else { return $self->{$name}; } } =item $numeric->DESTROY; Explicit destroy required because of AUTOLOAD, by default it does nothing. Overload for any Object cleanup at deconstruction of objects. =cut sub DESTROY { } 1;