package ArrayBase; use strict; my @Attributes; BEGIN { @Attributes = qw( FIRST SECOND ); my $i = 0; for (@Attributes) { eval "sub $_ () { $i }"; $i++; } } sub ATTRIBUTES { @Attributes } sub new { my $class = shift; my $self = []; $self->[FIRST] = shift; bless $self => $class; } sub first { my $self = shift; $self->[FIRST] = shift if @_; $self->[FIRST]; } sub second { my $self = shift; $self->[SECOND] = shift if @_; $self->[SECOND]; } 1;