.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Tie::RefHash::Weak 3pm" .TH Tie::RefHash::Weak 3pm "2021-01-06" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Tie::RefHash::Weak \- A Tie::RefHash subclass with weakened references in the keys. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Tie::RefHash::Weak; \& tie my %h, \*(AqTie::RefHash::Weak\*(Aq; \& \& # OR: \& \& use Tie::RefHash::Weak \*(Aqfieldhash\*(Aq; \& fieldhash my %h; \& \& { # new scope \& my $val = "foo"; \& \& $h{\e$val} = "bar"; # key is weak ref \& \& print join(", ", keys %h); # contains \e$val, returns regular reference \& } \& # $val goes out of scope, refcount goes to zero \& # weak references to \e$val are now undefined \& \& keys %h; # no longer contains \e$val \& \& # see also Tie::RefHash .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The Tie::RefHash module can be used to access hashes by reference. This is useful when you index by object, for example. .PP The problem with Tie::RefHash, and cross indexing, is that sometimes the index should not contain strong references to the objecs. Tie::RefHash's internal structures contain strong references to the key, and provide no convenient means to make those references weak. .PP This subclass of Tie::RefHash has weak keys, instead of strong ones. The values are left unaltered, and you'll have to make sure there are no strong references there yourself. .SH "FUNCTIONS" .IX Header "FUNCTIONS" For compatibility with Hash::Util::FieldHash, this module will, upon request, export the following two functions. You may also write \&\f(CW\*(C`use Tie::RefHash::Weak \*(Aq:all\*(Aq\*(C'\fR. .ie n .IP "fieldhash %hash" 4 .el .IP "fieldhash \f(CW%hash\fR" 4 .IX Item "fieldhash %hash" This ties the hash and returns a reference to it. .IP "fieldhashes \e%hash1, \e%hash2 ..." 4 .IX Item "fieldhashes %hash1, %hash2 ..." This ties each hash that is passed to it as a reference. It returns the list of references in list context, or the number of hashes in scalar context. .SH "THREAD SAFETY" .IX Header "THREAD SAFETY" Tie::RefHash version 1.32 and above have correct handling of threads (with respect to changing reference addresses). If your module requires Tie::RefHash::Weak to be thread aware you need to depend on both Tie::RefHash::Weak and Tie::RefHash version 1.32 (or later). .PP Version 0.02 and later of Tie::RefHash::Weak depend on a thread-safe version of Tie::RefHash anyway, so if you are using the latest version this should already be taken care of for you. .SH "5.10.0 COMPATIBILITY" .IX Header "5.10.0 COMPATIBILITY" Due to a minor change in Perl 5.10.0 a bug in the handling of magic freeing was uncovered causing segmentation faults. .PP This has been patched but not released yet, as of 0.08. .SH "CAVEAT" .IX Header "CAVEAT" You can use an \s-1LVALUE\s0 reference (such as \f(CW\*(C`\esubstr ...\*(C'\fR) as a hash key, but due to a bug in perl (see ) it might not be possible to weaken a reference to it, in which case the hash element will never be deleted automatically. .SH "AUTHORS" .IX Header "AUTHORS" Yuval Kogman .PP some maintenance by Hans Dieter Pearcey .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" .Vb 3 \& Copyright (c) 2004 Yuval Kogman. All rights reserved \& This program is free software; you can redistribute \& it and/or modify it under the same terms as Perl itself. .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Tie::RefHash, Class::DBI (the live object cache), \&\*(L"Perl_magic_killbackrefs\*(R" in mg.c