package VBVar; use strict; our %VarTypes = ( ARRAY => 'VBVar::Array', SCALAR => 'VBVar::Scalar', HASH => 'VBVar::Hash' ); ## Have our child classes refer to VBVar as needed @VBVar::Array::ISA = ('VBVar'); @VBVar::Scalar::ISA = ('VBVar'); @VBVar::Hash::ISA = ('VBVar'); ## ## Blesses the reference we pass in to the appropriate ## VBVar type. ## sub new { my $type = shift; my $self = shift; bless $self, $VarTypes{ref $self}; } ## Return the value of VBVar if contents are an array sub VBVar::Array::value_of { my $self = shift; my @indices = @_; # If someone passed in a list of indices to return if (@indices) { return $self->[@indices]; } # Otherwise, return the whole array else { return @$self; } } ## Return the value of VBVar if contents are ## a scalar sub VBVar::Scalar::value_of { return ${ $_[0] }; }