"lose the looses", from Abhijit Menon-Sen.
[p5sagit/p5-mst-13.2.git] / ext / List / Util / lib / Scalar / Util.pm
CommitLineData
f4a2945e 1# Scalar::Util.pm
2#
3# Copyright (c) 1997-2000 Graham Barr <gbarr@pobox.com>. All rights reserved.
4# This program is free software; you can redistribute it and/or
5# modify it under the same terms as Perl itself.
6
7package Scalar::Util;
8
9require Exporter;
10require List::Util; # List::Util loads the XS
11
ee4ffb48 12our @ISA = qw(Exporter);
13our @EXPORT_OK = qw(blessed dualvar reftype weaken isweak tainted readonly);
14our $VERSION = $List::Util::VERSION;
f4a2945e 15
f4a2945e 161;
17
18__END__
19
20=head1 NAME
21
22Scalar::Util - A selection of general-utility scalar subroutines
23
24=head1 SYNOPSIS
25
26 use Scalar::Util qw(blessed dualvar reftype weaken isweak);
27
28=head1 DESCRIPTION
29
30C<Scalar::Util> contains a selection of subroutines that people have
31expressed would be nice to have in the perl core, but the usage would
32not really be high enough to warrant the use of a keyword, and the size
33so small such that being individual extensions would be wasteful.
34
35By default C<Scalar::Util> does not export any subroutines. The
36subroutines defined are
37
38=over 4
39
40=item blessed EXPR
41
42If EXPR evaluates to a blessed reference the name of the package
43that it is blessed into is returned. Otherwise C<undef> is returned.
44
45=item dualvar NUM, STRING
46
47Returns a scalar that has the value NUM in a numeric context and the
48value STRING in a string context.
49
50 $foo = dualvar 10, "Hello";
51 $num = $foo + 2; # 12
52 $str = $foo . " world"; # Hello world
53
54=item isweak EXPR
55
56If EXPR is a scalar which is a weak reference the result is true.
57
ee4ffb48 58=item readonly SCALAR
59
60Returns true if SCALAR is readonly.
61
f4a2945e 62=item reftype EXPR
63
64If EXPR evaluates to a reference the type of the variable referenced
65is returned. Otherwise C<undef> is returned.
66
ee4ffb48 67=item tainted EXPR
68
69Return true if the result of EXPR is tainted
70
f4a2945e 71=item weaken REF
72
73REF will be turned into a weak reference. This means that it will not
74hold a reference count on the object it references. Also when the reference
75count on that object reaches zero, REF will be set to undef.
76
77This is useful for keeping copies of references , but you don't want to
78prevent the object being DESTROY-ed at it's usual time.
79
80=back
81
82=head1 COPYRIGHT
83
84Copyright (c) 1997-2000 Graham Barr <gbarr@pobox.com>. All rights reserved.
85This program is free software; you can redistribute it and/or modify it
86under the same terms as Perl itself.
87
88except weaken and isweak which are
89
90Copyright (c) 1999 Tuomas J. Lukka <lukka@iki.fi>. All rights reserved.
91This program is free software; you can redistribute it and/or modify it
92under the same terms as perl itself.
93
94=head1 BLATANT PLUG
95
96The weaken and isweak subroutines in this module and the patch to the core Perl
97were written in connection with the APress book `Tuomas J. Lukka's Definitive
98Guide to Object-Oriented Programming in Perl', to avoid explaining why certain
99things would have to be done in cumbersome ways.
100
101=cut