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