File: Hash.pm

package info (click to toggle)
libthread-tie-perl 0.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 192 kB
  • sloc: perl: 126; makefile: 2
file content (121 lines) | stat: -rw-r--r-- 2,956 bytes parent folder | download
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package Thread::Tie::Hash;

# Make sure we have version info for this module
# Make sure we do everything by the book from now on

$VERSION = '0.16';
use strict;

# Load only the stuff that we really need

use load;

# Satisfy -require-

1;

#---------------------------------------------------------------------------

# Following subroutines are loaded on demand only

__END__

#---------------------------------------------------------------------------

# standard Perl features

#---------------------------------------------------------------------------
#  IN: 1 class for which to bless
#      2..N key-value pairs to initialize with
# OUT: 1 instantiated object

sub TIEHASH { my $class = shift; bless {@_},$class } #TIEHASH

#---------------------------------------------------------------------------
#  IN: 1 instantiated object
#      2 key of element to fetch
# OUT: 1 value of element

sub FETCH { $_[0]->{$_[1]} } #FETCH

#---------------------------------------------------------------------------
#  IN: 1 instantiated object
#      2 key for which to store
#      3 new value

sub STORE { $_[0]->{$_[1]} = $_[2] } #STORE

#---------------------------------------------------------------------------
#  IN: 1 instantiated object

sub CLEAR { %{$_[0]} = () } #CLEAR

#---------------------------------------------------------------------------
#  IN: 1 instantiated object
# OUT: 1 first key of hash
#      2 value associated with first key

sub FIRSTKEY {

# Reset the each() magic
# Return first key/value pair

    scalar( keys %{$_[0]} );
    each %{$_[0]};
} #FIRSTKEY

#---------------------------------------------------------------------------
#  IN: 1 instantiated object
# OUT: 1 next key of hash
#      2 value associated with next key

sub NEXTKEY { each %{$_[0]} } #NEXTKEY

#---------------------------------------------------------------------------
#  IN: 1 instantiated object
#      2 key of element to check
# OUT: 1 flag: whether element exists

sub EXISTS { exists $_[0]->{$_[1]} } #EXISTS

#---------------------------------------------------------------------------
#  IN: 1 instantiated object
#      2 key of element to delete

sub DELETE { delete $_[0]->{$_[1]} } #DELETE

#---------------------------------------------------------------------------

__END__

=head1 NAME

Thread::Tie::Hash - default class for tie-ing hashes to threads

=head1 DESCRIPTION

Helper class for L<Thread::Tie>.  See documentation there.

=head1 CREDITS

Implementation inspired by L<Tie::StdHash>.

=head1 AUTHOR

Elizabeth Mattijsen, <liz@dijkmat.nl>.

maintained by LNATION <email@lnation.org>

Please report bugs to <email@lnation.org>>.

=head1 COPYRIGHT

Copyright (c) 2002-2003 Elizabeth Mattijsen <liz@dijkmat.nl>. 2019 - 2025 LNATION <email@lnation.org>
All rights reserved.  This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=head1 SEE ALSO

L<Thread::Tie>.

=cut