summaryrefslogtreecommitdiff
path: root/pod/perltie.pod
diff options
context:
space:
mode:
authorTassilo von Parseval <tassilo.parseval@post.rwth-aachen.de>2003-12-06 12:50:59 +0100
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-12-06 19:50:07 +0000
commita3bcc51ebd4e201d85a37d8410b7a375b8d94244 (patch)
tree57797ca6128a5011622a6e805fb66f6d2a0fbaa5 /pod/perltie.pod
parent5c98da1c029548d157089bc95672bf854902dd76 (diff)
downloadperl-a3bcc51ebd4e201d85a37d8410b7a375b8d94244.tar.gz
SCALAR/FIRSTKEY for tied hashes in scalar context
Message-id: <20031206105059.GA13989@ethan> p4raw-id: //depot/perl@21855
Diffstat (limited to 'pod/perltie.pod')
-rw-r--r--pod/perltie.pod24
1 files changed, 23 insertions, 1 deletions
diff --git a/pod/perltie.pod b/pod/perltie.pod
index b81a51b464..468855c685 100644
--- a/pod/perltie.pod
+++ b/pod/perltie.pod
@@ -474,7 +474,8 @@ the constructor. FETCH and STORE access the key and value pairs. EXISTS
reports whether a key is present in the hash, and DELETE deletes one.
CLEAR empties the hash by deleting all the key and value pairs. FIRSTKEY
and NEXTKEY implement the keys() and each() functions to iterate over all
-the keys. UNTIE is called when C<untie> happens, and DESTROY is called when
+the keys. SCALAR is triggered when the tied hash is evaluated in scalar
+context. UNTIE is called when C<untie> happens, and DESTROY is called when
the tied variable is garbage collected.
If this seems like a lot, then feel free to inherit from merely the
@@ -757,6 +758,25 @@ thing, but we'll have to go through the LIST field indirectly.
return each %{ $self->{LIST} }
}
+=item SCALAR this
+
+This is called when the hash is evaluated in scalar context. In order
+to mimic the behaviour of untied hashes, this method should return a
+false value when the tied hash is considered empty. If this method does
+not exist, perl will make some educated guesses and return false when
+the hash is not inside an iteration. In this case, FIRSTKEY is called
+and the result will be a false value if FIRSTKEY returns the empty list,
+true otherwise.
+
+In our example we can just call C<scalar> on the underlying hash
+referenced by C<$self-E<gt>{LIST}>:
+
+ sub SCALAR {
+ carp &whowasi if $DEBUG;
+ my $self = shift;
+ return scalar %{ $self->{LIST} }
+ }
+
=item UNTIE this
This is called when C<untie> occurs. See L<The C<untie> Gotcha> below.
@@ -1107,4 +1127,6 @@ TIEHANDLE by Sven Verdoolaege <F<skimo@dns.ufsia.ac.be>> and Doug MacEachern <F<
UNTIE by Nick Ing-Simmons <F<nick@ing-simmons.net>>
+SCALAR by Tassilo von Parseval <F<tassilo.von.parseval@rwth-aachen.de>>
+
Tying Arrays by Casey West <F<casey@geeknest.com>>