1Tie::RefHash::Weak(3) User Contributed Perl DocumentationTie::RefHash::Weak(3)
2
3
4

NAME

6       Tie::RefHash::Weak - A Tie::RefHash subclass with weakened references
7       in the keys.
8

SYNOPSIS

10               use Tie::RefHash::Weak;
11               tie my %h, 'Tie::RefHash::Weak';
12
13               # OR:
14
15               use Tie::RefHash::Weak 'fieldhash';
16               fieldhash my %h;
17
18               { # new scope
19                       my $val = "foo";
20
21                       $h{\$val} = "bar"; # key is weak ref
22
23                       print join(", ", keys %h); # contains \$val, returns regular reference
24               }
25               # $val goes out of scope, refcount goes to zero
26               # weak references to \$val are now undefined
27
28               keys %h; # no longer contains \$val
29
30               # see also Tie::RefHash
31

DESCRIPTION

33       The Tie::RefHash module can be used to access hashes by reference. This
34       is useful when you index by object, for example.
35
36       The problem with Tie::RefHash, and cross indexing, is that sometimes
37       the index should not contain strong references to the objecs.
38       Tie::RefHash's internal structures contain strong references to the
39       key, and provide no convenient means to make those references weak.
40
41       This subclass of Tie::RefHash has weak keys, instead of strong ones.
42       The values are left unaltered, and you'll have to make sure there are
43       no strong references there yourself.
44

FUNCTIONS

46       For compatibility with Hash::Util::FieldHash, this module will, upon
47       request, export the following two functions. You may also write "use
48       Tie::RefHash::Weak ':all'".
49
50       fieldhash %hash
51           This ties the hash and returns a reference to it.
52
53       fieldhashes \%hash1, \%hash2 ...
54           This ties each hash that is passed to it as a reference. It returns
55           the list of references in list context, or the number of hashes in
56           scalar context.
57

THREAD SAFETY

59       Tie::RefHash version 1.32 and above have correct handling of threads
60       (with respect to changing reference addresses). If your module requires
61       Tie::RefHash::Weak to be thread aware you need to depend on both
62       Tie::RefHash::Weak and Tie::RefHash version 1.32 (or later).
63
64       Version 0.02 and later of Tie::RefHash::Weak depend on a thread-safe
65       version of Tie::RefHash anyway, so if you are using the latest version
66       this should already be taken care of for you.
67

5.10.0 COMPATIBILITY

69       Due to a minor change in Perl 5.10.0 a bug in the handling of magic
70       freeing was uncovered causing segmentation faults.
71
72       This has been patched but not released yet, as of 0.08.
73

CAVEAT

75       You can use an LVALUE reference (such as "\substr ...") as a hash key,
76       but due to a bug in perl (see
77       <http://rt.perl.org/rt3/Public/Bug/Display.html?id=46943>) it might not
78       be possible to weaken a reference to it, in which case the hash element
79       will never be deleted automatically.
80

AUTHORS

82       Yuval Kogman <nothingmuch@woobling.org>
83
84       some maintenance by Hans Dieter Pearcey <hdp@pobox.com>
85
87               Copyright (c) 2004 Yuval Kogman. All rights reserved
88               This program is free software; you can redistribute
89               it and/or modify it under the same terms as Perl itself.
90

SEE ALSO

92       Tie::RefHash, Class::DBI (the live object cache),
93       "Perl_magic_killbackrefs" in mg.c
94
95
96
97perl v5.32.1                      2021-01-27             Tie::RefHash::Weak(3)
Impressum