#!/usr/bin/perl

use strict;
use warnings;

my $obj = AtestClass->new();     #make a new object of the class

print "We created an object\n";

$obj->getSet('one',111);         #set an attribute
$obj->getSet('two',222);         # and another one

print "using the getter for 'one' we got " . $obj->getSet('one') ."\n";
print "  and for 'two'" . $obj->getSet('two') . "\n";

exit(0);

package AtestClass;     #name space and therefore class name

sub new{ #Constructor, can have ANY name, but convention is 'new'
    my $class = shift;  #when called we are called with the class name
                        # convention says use $class and $self
    my $self = {};      #create an anonymous hash where this object 
                        # will store its data
    bless $self,$class; #this is to be an object of the class
    return $self;       #and return the object reference
}

sub getSet{ #set or get an attribute of the current object
    my $self = shift;   #the first argument is the object reference

    my $what = shift;   #what to set/get, the key

    if (@_) {           #there is a value to set, ie a remaining arg
        $self->{"$what"} = shift; #so set it into the hash
    }
    return($self->{$what}); #it is a read not a set
}
