# -*- mode: cperl; cperl-indent-level: 2 -*-
#
# This foolishness is copyright 1998 Mark-Jason Dominus.
# (mjd-perl-identity@plover.com)
# He shamefacedly takes full responsibility.
#




package Identity;
use Carp;
# use Symbol;

# Ignore this; it's not really of general interest.
sub import {
  my $caller_pack = caller;
#  print STDERR "exporter args: (@_); caller pack: $caller_pack\n";
  my $my_pack = shift;
  foreach $import (@_) {
    if ($import =~ /^[\$\@]?num$/) {
      my @array;
      tie @array => $my_pack;
      *{$caller_pack . '::num'} = \@array;
    } elsif ($import =~ /^[\$\%]?str$/) {
      my %hash;
      tie %hash => $my_pack;
      *{$caller_pack . '::str'} = \%hash;
    } else {
      croak "I only know how to import `\%str' and `\@num'.  Aborting\n";
    }
  }
}

sub TIEHASH {
  my $pack = shift;
  bless {} => $pack;
}

sub TIEARRAY {
  my $pack = shift;
  bless [] => $pack;
}

# This is where the magic is.
sub FETCH {
  $_[1];
}

sub cut_it_out {
  croak "Not allowed to do that to an Identity variable; aborting";
}

*STORE = \&cut_it_out;
*DELETE = \&cut_it_out;
*CLEAR = \&cut_it_out;
*EXISTS = \&cut_it_out;
*FIRSTKEY = \&cut_it_out;
*NEXTKEY = \&cut_it_out;

1;
