| 1 | package UNIVERSAL;
|
|---|
| 2 |
|
|---|
| 3 | our $VERSION = '1.01';
|
|---|
| 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 can't be fixed without breaking code. Note that we
|
|---|
| 8 | # *don't* set @ISA here, don't want all classes/objects inheriting from
|
|---|
| 9 | # Exporter. It's bad enough that all classes have a import() method
|
|---|
| 10 | # whenever UNIVERSAL.pm is loaded.
|
|---|
| 11 | require Exporter;
|
|---|
| 12 | *import = \&Exporter::import;
|
|---|
| 13 | @EXPORT_OK = qw(isa can VERSION);
|
|---|
| 14 |
|
|---|
| 15 | 1;
|
|---|
| 16 | __END__
|
|---|
| 17 |
|
|---|
| 18 | =head1 NAME
|
|---|
| 19 |
|
|---|
| 20 | UNIVERSAL - base class for ALL classes (blessed references)
|
|---|
| 21 |
|
|---|
| 22 | =head1 SYNOPSIS
|
|---|
| 23 |
|
|---|
| 24 | $is_io = $fd->isa("IO::Handle");
|
|---|
| 25 | $is_io = Class->isa("IO::Handle");
|
|---|
| 26 |
|
|---|
| 27 | $sub = $obj->can("print");
|
|---|
| 28 | $sub = Class->can("print");
|
|---|
| 29 |
|
|---|
| 30 | use UNIVERSAL qw( isa can VERSION );
|
|---|
| 31 | $yes = isa $ref, "HASH" ;
|
|---|
| 32 | $sub = can $ref, "fandango" ;
|
|---|
| 33 | $ver = VERSION $obj ;
|
|---|
| 34 |
|
|---|
| 35 | =head1 DESCRIPTION
|
|---|
| 36 |
|
|---|
| 37 | C<UNIVERSAL> is the base class which all bless references will inherit from,
|
|---|
| 38 | see L<perlobj>.
|
|---|
| 39 |
|
|---|
| 40 | C<UNIVERSAL> provides the following methods and functions:
|
|---|
| 41 |
|
|---|
| 42 | =over 4
|
|---|
| 43 |
|
|---|
| 44 | =item C<< $obj->isa( TYPE ) >>
|
|---|
| 45 |
|
|---|
| 46 | =item C<< CLASS->isa( TYPE ) >>
|
|---|
| 47 |
|
|---|
| 48 | =item C<isa( VAL, TYPE )>
|
|---|
| 49 |
|
|---|
| 50 | Where
|
|---|
| 51 |
|
|---|
| 52 | =over 4
|
|---|
| 53 |
|
|---|
| 54 | =item C<TYPE>
|
|---|
| 55 |
|
|---|
| 56 | is a package name
|
|---|
| 57 |
|
|---|
| 58 | =item C<$obj>
|
|---|
| 59 |
|
|---|
| 60 | is a blessed reference or a string containing a package name
|
|---|
| 61 |
|
|---|
| 62 | =item C<CLASS>
|
|---|
| 63 |
|
|---|
| 64 | is a package name
|
|---|
| 65 |
|
|---|
| 66 | =item C<VAL>
|
|---|
| 67 |
|
|---|
| 68 | is any of the above or an unblessed reference
|
|---|
| 69 |
|
|---|
| 70 | =back
|
|---|
| 71 |
|
|---|
| 72 | When used as an instance or class method (C<< $obj->isa( TYPE ) >>),
|
|---|
| 73 | C<isa> returns I<true> if $obj is blessed into package C<TYPE> or
|
|---|
| 74 | inherits from package C<TYPE>.
|
|---|
| 75 |
|
|---|
| 76 | When used as a class method (C<< CLASS->isa( TYPE ) >>: sometimes
|
|---|
| 77 | referred to as a static method), C<isa> returns I<true> if C<CLASS>
|
|---|
| 78 | inherits from (or is itself) the name of the package C<TYPE> or
|
|---|
| 79 | inherits from package C<TYPE>.
|
|---|
| 80 |
|
|---|
| 81 | When used as a function, like
|
|---|
| 82 |
|
|---|
| 83 | use UNIVERSAL qw( isa ) ;
|
|---|
| 84 | $yes = isa $h, "HASH";
|
|---|
|
|---|