#!/usr/bin/perl

use strict;
use warnings;

package AtestClass2;    #name space and the class name

my $counter = 0;        #class variable
#remember we are in the AtestClass2.pm file and so this variable is
# file-scoped here - it is almost as though there is a block {} around
# the entire file

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 = {};      #where this class will store data
    $counter++;         #count how many times we create objects
    print "We created a new object, we now have $counter\n";
    bless $self,$class; #this is to be an object of the class
    return $self;       #bless is what tells Perl this is an object
}

#getSet is unchanged
sub getSet{ #set or get an attribute of the current object
    my $self = shift;   #when called the first param is the object

    my $what = shift;   #what to set, they key

    if (@_) {           #there is a value to set
        my $value = shift; # and set it to
        $self->{"$what"} = $value;
        return;         #return with the set value
    }
    return($self->{$what}); #it is a read not a set
}

sub DESTROY { #the destructor, generally we do not need to specify 
            #a destructor
    $counter--;         #we are freeing one
    print "object released, there are now $counter objects\n";
}

1;
