This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Continue what #4494 started; introduce uid and gid formats.
[perl5.git] / lib / UNIVERSAL.pm
CommitLineData
def3c102 1package UNIVERSAL;
2
84902520
TB
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.
def3c102 6require Exporter;
84902520 7*import = \&Exporter::import;
a66bc3b0 8@EXPORT_OK = qw(isa can);
def3c102 9
101;
11__END__
12
13=head1 NAME
14
15UNIVERSAL - base class for ALL classes (blessed references)
16
17=head1 SYNOPSIS
18
def3c102 19 $io = $fd->isa("IO::Handle");
20 $sub = $obj->can('print');
21
84902520
TB
22 $yes = UNIVERSAL::isa($ref, "HASH");
23
def3c102 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
7e1af8bc 43then a reference to the sub is returned. If it does not then I<undef>
def3c102 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
84902520 59The C<isa> and C<can> methods can also be called as subroutines
def3c102 60
61=over 4
62
84902520 63=item UNIVERSAL::isa ( VAL, TYPE )
def3c102 64
65C<isa> returns I<true> if the first argument is a reference and either
66of the following statements is true.
67
68=over 8
69
70=item
71
a66bc3b0 72C<VAL> is a blessed reference and is blessed into package C<TYPE>
def3c102 73or inherits from package C<TYPE>
74
75=item
76
a66bc3b0 77C<VAL> is a reference to a C<TYPE> of perl variable (er 'HASH')
def3c102 78
79=back
80
84902520 81=item UNIVERSAL::can ( VAL, METHOD )
a66bc3b0
MG
82
83If C<VAL> is a blessed reference which has a method called C<METHOD>,
84C<can> returns a reference to the subroutine. If C<VAL> is not
85a blessed reference, or if it does not have a method C<METHOD>,
86I<undef> is returned.
87
def3c102 88=back
89
84902520
TB
90These subroutines should I<not> be imported via S<C<use UNIVERSAL qw(...)>>.
91If you want simple local access to them you can do
92
93 *isa = \&UNIVERSAL::isa;
94
95to import isa into your package.
96
def3c102 97=cut