package MyAry;

use strict;
use vars qw(@ISA @EXPORT);

use Exporter;
use Tie::Array;

@ISA = qw(Exporter Tie::Array);
@EXPORT = qw(item forward back reset);

sub TIEARRAY {
    my $class = shift;
    return bless {
	ARRAY=>[],
	POS=>0,
    }, $class;
}

sub FETCH {
    my $self = shift;
    my ($index) = @_;
    return $self->{ARRAY}[$index];
}

sub STORE {
    my $self = shift;
    my ($index, $value) = @_;
    return $self->{ARRAY}[$index] = $value;
}

sub FETCHSIZE {
    my $self = shift;
    return scalar(@{$self->{ARRAY}});
}

sub STORESIZE {
    my $self = shift;
    my ($value) = @_;
    $#{$self->{ARRAY}} = $value-1;
}

sub item (\@@) {
    my $self = tied @{+shift};
    if (@_) { return $self->{ARRAY}[$self->{POS}] = shift; }
    return $self->{ARRAY}[$self->{POS}];
}

sub forward (\@) {
    my $self = tied @{+shift};
    ++ $self->{POS};
}

sub back (\@) {
    my $self = tied @{+shift};
    -- $self->{POS};
}

sub reset (\@) {
    my $self = tied @{+shift};
    $self->{POS} = 0;
}
