#!/usr/bin/perl # # Copyright 2000 M-J. Dominus and the Mad Hungarian Software Works # Unauthorized distribution strictly prohibited # package ArrayHashMonster; require 5.00502; use strict; our $VERSION = '0.03'; BEGIN { @ArrayHashMonster::Siphuncle::ISA = __PACKAGE__ } sub new { my ($pack, $acode, $hcode) = @_; my $siphuncle = $pack->new_siphuncle; my @a; tie @a => $pack, $siphuncle, $acode, $hcode; \@a; } sub new_siphuncle { my ($pack) = @_; my %h; tie %h => $pack; return \%h; } sub set_flag { my ($self, $flagref) = @_; $self->{FLAG} = $flagref; } sub TIEHASH { my ($pack) = @_; my $self = {FLAG => undef}; bless $self => $pack . '::Siphuncle'; } sub TIEARRAY { my ($pack, $siphuncle, $acode, $hcode) = @_; my $flag = undef; my $self = {FLAG => \$flag, SIPHUNCLE => $siphuncle, ACODE => $acode, HCODE => $hcode}; (tied %$siphuncle)->set_flag(\$flag); bless $self => $pack; } sub FETCH { my ($self, $key) = @_; if (ref($self) =~ /Siphuncle/) { ${$self->{FLAG}} = $key; return 1; } elsif ($key == 0) { return $self->{SIPHUNCLE}; } elsif (defined $ {$self->{FLAG}}) { my $rv = $self->{HCODE}->($ {$self->{FLAG}}); undef $ {$self->{FLAG}}; return $rv; } else { return $self->{ACODE}->($key); } } 1;