File: UniqueHash.pm

package info (click to toggle)
cgiirc 0.5.9-3squeeze1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 896 kB
  • ctags: 443
  • sloc: perl: 9,125; ansic: 163; sh: 99; makefile: 43
file content (81 lines) | stat: -rw-r--r-- 1,589 bytes parent folder | download | duplicates (4)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# $Id: UniqueHash.pm,v 1.2 2002/04/27 19:21:54 dgl Exp $
#!/usr/bin/perl
# from pircd, edited by david leadbeater..
# 
# IRCUniqueHash.pm
# Created: Wed Apr 21 09:44:03 1999 by jay.kominek@colorado.edu
# Revised: Wed Apr 21 09:59:55 1999 by jay.kominek@colorado.edu
# Copyright 1999 Jay F. Kominek (jay.kominek@colorado.edu)
#
# Consult the file 'LICENSE' for the complete terms under which you
# may use self file.
#
#####################################################################
# A hash class which enforces IRC-style unique name spaces
#####################################################################

package IRC::UniqueHash;
use strict;
my(@tmp);

sub TIEHASH {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  my $self  = { };

  bless $self, $class;
  return $self;
}

sub FETCH {
  my($self,$key) = @_;

  return $self->{data}->{irclc($key)}->{value};
}

sub STORE {
  my($self,$key,$value) = @_;
  
  my $name = irclc($key);
  $self->{data}->{$name}->{name} = $key;
  $self->{data}->{$name}->{value} = $value;
}

sub DELETE {
  my($self,$key) = @_;

  delete($self->{data}->{irclc($key)});
}

sub CLEAR {
  my $self = shift;

  %$self = ( );
}

sub EXISTS {
  my($self,$key) = @_;

  return exists $self->{data}->{irclc($key)};
}

sub FIRSTKEY {
  my $self = shift;

  @{$self->{_tmp}} = keys %{$self->{data}};
  
  return $self->{data}->{shift @{$self->{_tmp}}}->{name};
}

sub NEXTKEY {
  my ($self,$lastkey) = @_;

  return undef unless @{$self->{_tmp}};
  return $self->{data}->{shift @{$self->{_tmp}}}->{name};
}

sub irclc {
  return lc $_[0];
}

1;