summaryrefslogtreecommitdiff
path: root/lib/TieHash.pm
blob: 0cb4afa20d1483019a901323c10bd202b74e401f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package TieHash;
use Carp;

sub new {
    my $pack = shift;
    $pack->TIEHASH(@_);
}

# Grandfather "new"

sub TIEHASH {
    my $pack = shift;
    if (defined &{"{$pack}::new"}) {
	carp "WARNING: calling ${pack}->new since ${pack}->TIEHASH is missing"
	    if $^W;
	$pack->new(@_);
    }
    else {
	croak "$pack doesn't define a TIEHASH method";
    }
}

sub EXISTS {
    my $pack = ref $_[0];
    croak "$pack doesn't define an EXISTS method";
}

sub CLEAR {
    my $self = shift;
    my $key = $self->FIRSTKEY(@_);
    my @keys;

    while (defined $key) {
	push @keys, $key;
	$key = $self->NEXTKEY(@_, $key);
    }
    foreach $key (@keys) {
	$self->DELETE(@_, $key);
    }
}

1;