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