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