source: trunk/third/perl/lib/UNIVERSAL.pm @ 14545

Revision 14545, 2.3 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r14544, which included commits to RCS files with non-trunk default branches.
Line 
1package UNIVERSAL;
2
3# UNIVERSAL should not contain any extra subs/methods beyond those
4# that it exists to define. The use of Exporter below is a historical
5# accident that should be fixed sometime.
6require Exporter;
7*import = \&Exporter::import;
8@EXPORT_OK = qw(isa can);
9
101;
11__END__
12
13=head1 NAME
14
15UNIVERSAL - base class for ALL classes (blessed references)
16
17=head1 SYNOPSIS
18
19    $io = $fd->isa("IO::Handle");
20    $sub = $obj->can('print');
21
22    $yes = UNIVERSAL::isa($ref, "HASH");
23
24=head1 DESCRIPTION
25
26C<UNIVERSAL> is the base class which all bless references will inherit from,
27see L<perlobj>
28
29C<UNIVERSAL> provides the following methods
30
31=over 4
32
33=item isa ( TYPE )
34
35C<isa> returns I<true> if C<REF> is blessed into package C<TYPE>
36or inherits from package C<TYPE>.
37
38C<isa> can be called as either a static or object method call.
39
40=item can ( METHOD )
41
42C<can> checks if the object has a method called C<METHOD>. If it does
43then a reference to the sub is returned. If it does not then I<undef>
44is returned.
45
46C<can> can be called as either a static or object method call.
47
48=item VERSION ( [ REQUIRE ] )
49
50C<VERSION> will return the value of the variable C<$VERSION> in the
51package the object is blessed into. If C<REQUIRE> is given then
52it will do a comparison and die if the package version is not
53greater than or equal to C<REQUIRE>.
54
55C<VERSION> can be called as either a static or object method call.
56
57=back
58
59The C<isa> and C<can> methods can also be called as subroutines
60
61=over 4
62
63=item UNIVERSAL::isa ( VAL, TYPE )
64
65C<isa> returns I<true> if one of the following statements is true.
66
67=over 8
68
69=item *
70
71C<VAL> is a reference blessed into either package C<TYPE> or a package
72which inherits from package C<TYPE>.
73
74=item *
75
76C<VAL> is a reference to a C<TYPE> of Perl variable (e.g. 'HASH').
77
78=item *
79
80C<VAL> is the name of a package that inherits from (or is itself)
81package C<TYPE>.
82
83=back
84
85=item UNIVERSAL::can ( VAL, METHOD )
86
87If C<VAL> is a blessed reference which has a method called C<METHOD>,
88C<can> returns a reference to the subroutine.   If C<VAL> is not
89a blessed reference, or if it does not have a method C<METHOD>,
90I<undef> is returned.
91
92=back
93
94These subroutines should I<not> be imported via S<C<use UNIVERSAL qw(...)>>.
95If you want simple local access to them you can do
96
97  *isa = \&UNIVERSAL::isa;
98
99to import isa into your package.
100
101=cut
Note: See TracBrowser for help on using the repository browser.