Dear monks,
I am trying to achieve the following functionality: I have an inside-out class where the underlying data structures of the objects are scalar references. I'd like to be able to access the contents referenced by objects from this class as arrays, i.e.:
use Foo::Bar;
my $fb = Foo::Bar->new;
$fb->[0] = 12; # here Foo::Bar::STORE($self,$index,$value) is called
print $fb; # not sure, maybe Foo::Bar=SCALAR(0x1835bfc)?
Along similar lines, I'd like to be able to push @$fb, etc. (which would call the PUSH method). I have perused the documentation for
perltie and
overload and I think it must be some combination of that, but the best I could come up with was using:
use Foo::Bar;
tie my @array, 'Foo::Bar';
$array[0] = 12; # here Foo::Bar::STORE($self,$index,$value) is called
...which is not really what I want. I want the constructor, data structure (scalar ref) and interface to remain the same, and just add syntax sugar. I'm guessing I have to call TIEARRAY in some way in the
new constructor?
Thanks for any and all help!