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