This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix C<print $_> in debugger
[perl5.git] / lib / UNIVERSAL.pm
CommitLineData
def3c102 1package UNIVERSAL;
2
3require Exporter;
4@ISA = qw(Exporter);
a66bc3b0 5@EXPORT_OK = qw(isa can);
def3c102 6
71;
8__END__
9
10=head1 NAME
11
12UNIVERSAL - base class for ALL classes (blessed references)
13
14=head1 SYNOPSIS
15
16 use UNIVERSAL qw(isa);
17
18 $yes = isa($ref, "HASH");
19 $io = $fd->isa("IO::Handle");
20 $sub = $obj->can('print');
21
22=head1 DESCRIPTION
23
24C<UNIVERSAL> is the base class which all bless references will inherit from,
25see L<perlobj>
26
27C<UNIVERSAL> provides the following methods
28
29=over 4
30
31=item isa ( TYPE )
32
33C<isa> returns I<true> if C<REF> is blessed into package C<TYPE>
34or inherits from package C<TYPE>.
35
36C<isa> can be called as either a static or object method call.
37
38=item can ( METHOD )
39
40C<can> checks if the object has a method called C<METHOD>. If it does
7e1af8bc 41then a reference to the sub is returned. If it does not then I<undef>
def3c102 42is returned.
43
44C<can> can be called as either a static or object method call.
45
46=item VERSION ( [ REQUIRE ] )
47
48C<VERSION> will return the value of the variable C<$VERSION> in the
49package the object is blessed into. If C<REQUIRE> is given then
50it will do a comparison and die if the package version is not
51greater than or equal to C<REQUIRE>.
52
53C<VERSION> can be called as either a static or object method call.
54
55=back
56
57C<UNIVERSAL> also optionally exports the following subroutines
58
59=over 4
60
a66bc3b0 61=item isa ( VAL, TYPE )
def3c102 62
63C<isa> returns I<true> if the first argument is a reference and either
64of the following statements is true.
65
66=over 8
67
68=item
69
a66bc3b0 70C<VAL> is a blessed reference and is blessed into package C<TYPE>
def3c102 71or inherits from package C<TYPE>
72
73=item
74
a66bc3b0 75C<VAL> is a reference to a C<TYPE> of perl variable (er 'HASH')
def3c102 76
77=back
78
a66bc3b0
MG
79=item can ( VAL, METHOD )
80
81If C<VAL> is a blessed reference which has a method called C<METHOD>,
82C<can> returns a reference to the subroutine. If C<VAL> is not
83a blessed reference, or if it does not have a method C<METHOD>,
84I<undef> is returned.
85
def3c102 86=back
87
88=cut