#!/usr/bin/perl

use strict;
use warnings;

package AutoInc;    #namespace and therefore class name

sub TIESCALAR { #the constructor for objects of this type, scalars
    # when tying to a scalar the constructor MUST have this name
    # so that Perl can find it
    my $class = shift;
    my $counter = 0; #we need nothing more than a scalar
    bless \$counter,$class;
    return \$counter;
}

sub FETCH { #called when the object is read, must have this name
    my $self = shift;
    return $$self++;
}

sub STORE { #called when he stores to it, must have this name
    my $self = shift; #the object reference
    my $val = shift; #second param is the new value
    $$self = $val; #set it
    return;
}

1;
