Commit | Line | Data |
def3c102 |
1 | package UNIVERSAL; |
2 | |
84902520 |
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 |
6 | require Exporter; |
84902520 |
7 | *import = \&Exporter::import; |
a66bc3b0 |
8 | @EXPORT_OK = qw(isa can); |
def3c102 |
9 | |
10 | 1; |
11 | __END__ |
12 | |
13 | =head1 NAME |
14 | |
15 | UNIVERSAL - 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 |
22 | $yes = UNIVERSAL::isa($ref, "HASH"); |
23 | |
def3c102 |
24 | =head1 DESCRIPTION |
25 | |
26 | C<UNIVERSAL> is the base class which all bless references will inherit from, |
27 | see L<perlobj> |
28 | |
29 | C<UNIVERSAL> provides the following methods |
30 | |
31 | =over 4 |
32 | |
33 | =item isa ( TYPE ) |
34 | |
35 | C<isa> returns I<true> if C<REF> is blessed into package C<TYPE> |
36 | or inherits from package C<TYPE>. |
37 | |
38 | C<isa> can be called as either a static or object method call. |
39 | |
40 | =item can ( METHOD ) |
41 | |
42 | C<can> checks if the object has a method called C<METHOD>. If it does |
7e1af8bc |
43 | then a reference to the sub is returned. If it does not then I<undef> |
def3c102 |
44 | is returned. |
45 | |
46 | C<can> can be called as either a static or object method call. |
47 | |
48 | =item VERSION ( [ REQUIRE ] ) |
49 | |
50 | C<VERSION> will return the value of the variable C<$VERSION> in the |
51 | package the object is blessed into. If C<REQUIRE> is given then |
52 | it will do a comparison and die if the package version is not |
53 | greater than or equal to C<REQUIRE>. |
54 | |
55 | C<VERSION> can be called as either a static or object method call. |
56 | |
57 | =back |
58 | |
84902520 |
59 | The 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 | |
cb50131a |
65 | C<isa> returns I<true> if one of the following statements is true. |
def3c102 |
66 | |
67 | =over 8 |
68 | |
cb50131a |
69 | =item * |
def3c102 |
70 | |
cb50131a |
71 | C<VAL> is a reference blessed into either package C<TYPE> or a package |
72 | which inherits from package C<TYPE>. |
def3c102 |
73 | |
cb50131a |
74 | =item * |
def3c102 |
75 | |
cb50131a |
76 | C<VAL> is a reference to a C<TYPE> of Perl variable (e.g. 'HASH'). |
77 | |
78 | =item * |
79 | |
80 | C<VAL> is the name of a package that inherits from (or is itself) |
81 | package C<TYPE>. |
def3c102 |
82 | |
83 | =back |
84 | |
84902520 |
85 | =item UNIVERSAL::can ( VAL, METHOD ) |
a66bc3b0 |
86 | |
87 | If C<VAL> is a blessed reference which has a method called C<METHOD>, |
88 | C<can> returns a reference to the subroutine. If C<VAL> is not |
89 | a blessed reference, or if it does not have a method C<METHOD>, |
90 | I<undef> is returned. |
91 | |
def3c102 |
92 | =back |
93 | |
84902520 |
94 | These subroutines should I<not> be imported via S<C<use UNIVERSAL qw(...)>>. |
95 | If you want simple local access to them you can do |
96 | |
97 | *isa = \&UNIVERSAL::isa; |
98 | |
99 | to import isa into your package. |
100 | |
def3c102 |
101 | =cut |