hi all,

i'm starting out doing some Object Oriented programming with mod_perl 
and I define one object like this:

sub new {
        my $self = shift;
        my $type = ref($self) || $self;

        ## bless our object into the class and return it
        return bless {
        first_name => '',
        last_name => '',
        email_address => '',
        @_
        }, $type;
}

sub AUTOLOAD {
        my $self = shift; ## grab the object we're being called on
        my $type = $self || ref($self);  ## get the object type

   return if $AUTOLOAD =~ /^DESTROY$/;

        my $name = $AUTOLOAD;

        $name =~ s/^.*://;

        unless( exists $self->{$name} ) {
                croak "Error: Can't access field '$name' in object of class 
$type";
        }

        if (@_) {
                return $self->{$name} = shift;
        } else {
                return $self->{$name};
        }
}

## more functions ##

Let's say this object is called SomePerson, and I create this object in 
one of my cgi scripts, like so (image SomePerson is part of package 
People):

$some_person = People::SomePerson->new;

how do I change the first_name, last_name, email_address variables?  
Would it be like this, if I'm doing it from inside the SomePerson 
object:

$self->{first_name} = "Etienne";

and like this from a regular cgi script:

$some_person->first_name = "Etienne";

or how?

Thanks in advance,

Etienne

Reply via email to