perl 5.000
[p5sagit/p5-mst-13.2.git] / lib / TieHash.pm
1 package TieHash;
2 use Carp;
3
4 sub new {
5     my $pack = shift;
6     $pack->TIEHASH(@_);
7 }
8
9 # Grandfather "new"
10
11 sub TIEHASH {
12     my $pack = shift;
13     if (defined &{"{$pack}::new"}) {
14         carp "WARNING: calling ${pack}->new since ${pack}->TIEHASH is missing"
15             if $^W;
16         $pack->new(@_);
17     }
18     else {
19         croak "$pack doesn't define a TIEHASH method";
20     }
21 }
22
23 sub EXISTS {
24     my $pack = ref $_[0];
25     croak "$pack doesn't define an EXISTS method";
26 }
27
28 sub CLEAR {
29     my $self = shift;
30     my $key = $self->FIRSTKEY(@_);
31     my @keys;
32
33     while (defined $key) {
34         push @keys, $key;
35         $key = $self->NEXTKEY(@_, $key);
36     }
37     foreach $key (@keys) {
38         $self->DELETE(@_, $key);
39     }
40 }
41
42 1;