1N/Apackage UNIVERSAL;
1N/A
1N/Aour $VERSION = '1.01';
1N/A
1N/A# UNIVERSAL should not contain any extra subs/methods beyond those
1N/A# that it exists to define. The use of Exporter below is a historical
1N/A# accident that can't be fixed without breaking code. Note that we
1N/A# *don't* set @ISA here, don't want all classes/objects inheriting from
1N/A# Exporter. It's bad enough that all classes have a import() method
1N/A# whenever UNIVERSAL.pm is loaded.
1N/Arequire Exporter;
1N/A*import = \&Exporter::import;
1N/A@EXPORT_OK = qw(isa can VERSION);
1N/A
1N/A1;
1N/A__END__
1N/A
1N/A=head1 NAME
1N/A
1N/AUNIVERSAL - base class for ALL classes (blessed references)
1N/A
1N/A=head1 SYNOPSIS
1N/A
1N/A $is_io = $fd->isa("IO::Handle");
1N/A $is_io = Class->isa("IO::Handle");
1N/A
1N/A $sub = $obj->can("print");
1N/A $sub = Class->can("print");
1N/A
1N/A use UNIVERSAL qw( isa can VERSION );
1N/A $yes = isa $ref, "HASH" ;
1N/A $sub = can $ref, "fandango" ;
1N/A $ver = VERSION $obj ;
1N/A
1N/A=head1 DESCRIPTION
1N/A
1N/AC<UNIVERSAL> is the base class which all bless references will inherit from,
1N/Asee L<perlobj>.
1N/A
1N/AC<UNIVERSAL> provides the following methods and functions:
1N/A
1N/A=over 4
1N/A
1N/A=item C<< $obj->isa( TYPE ) >>
1N/A
1N/A=item C<< CLASS->isa( TYPE ) >>
1N/A
1N/A=item C<isa( VAL, TYPE )>
1N/A
1N/AWhere
1N/A
1N/A=over 4
1N/A
1N/A=item C<TYPE>
1N/A
1N/Ais a package name
1N/A
1N/A=item C<$obj>
1N/A
1N/Ais a blessed reference or a string containing a package name
1N/A
1N/A=item C<CLASS>
1N/A
1N/Ais a package name
1N/A
1N/A=item C<VAL>
1N/A
1N/Ais any of the above or an unblessed reference
1N/A
1N/A=back
1N/A
1N/AWhen used as an instance or class method (C<< $obj->isa( TYPE ) >>),
1N/AC<isa> returns I<true> if $obj is blessed into package C<TYPE> or
1N/Ainherits from package C<TYPE>.
1N/A
1N/AWhen used as a class method (C<< CLASS->isa( TYPE ) >>: sometimes
1N/Areferred to as a static method), C<isa> returns I<true> if C<CLASS>
1N/Ainherits from (or is itself) the name of the package C<TYPE> or
1N/Ainherits from package C<TYPE>.
1N/A
1N/AWhen used as a function, like
1N/A
1N/A use UNIVERSAL qw( isa ) ;
1N/A $yes = isa $h, "HASH";
1N/A $yes = isa "Foo", "Bar";
1N/A
1N/Aor
1N/A
1N/A require UNIVERSAL ;
1N/A $yes = UNIVERSAL::isa $a, "ARRAY";
1N/A
1N/AC<isa> returns I<true> in the same cases as above and also if C<VAL> is an
1N/Aunblessed reference to a perl variable of type C<TYPE>, such as "HASH",
1N/A"ARRAY", or "Regexp".
1N/A
1N/A=item C<< $obj->can( METHOD ) >>
1N/A
1N/A=item C<< CLASS->can( METHOD ) >>
1N/A
1N/A=item C<can( VAL, METHOD )>
1N/A
1N/AC<can> checks if the object or class has a method called C<METHOD>. If it does
1N/Athen a reference to the sub is returned. If it does not then I<undef> is
1N/Areturned. This includes methods inherited or imported by C<$obj>, C<CLASS>, or
1N/AC<VAL>.
1N/A
1N/AC<can> cannot know whether an object will be able to provide a method
1N/Athrough AUTOLOAD, so a return value of I<undef> does not necessarily mean
1N/Athe object will not be able to handle the method call. To get around
1N/Athis some module authors use a forward declaration (see L<perlsub>)
1N/Afor methods they will handle via AUTOLOAD. For such 'dummy' subs, C<can>
1N/Awill still return a code reference, which, when called, will fall through
1N/Ato the AUTOLOAD. If no suitable AUTOLOAD is provided, calling the coderef
1N/Awill cause an error.
1N/A
1N/AC<can> can be called as a class (static) method, an object method, or a
1N/Afunction.
1N/A
1N/AWhen used as a function, if C<VAL> is a blessed reference or package name which
1N/Ahas a method called C<METHOD>, C<can> returns a reference to the subroutine.
1N/AIf C<VAL> is not a blessed reference, or if it does not have a method
1N/AC<METHOD>, I<undef> is returned.
1N/A
1N/A=item C<VERSION ( [ REQUIRE ] )>
1N/A
1N/AC<VERSION> will return the value of the variable C<$VERSION> in the
1N/Apackage the object is blessed into. If C<REQUIRE> is given then
1N/Ait will do a comparison and die if the package version is not
1N/Agreater than or equal to C<REQUIRE>.
1N/A
1N/AC<VERSION> can be called as either a class (static) method, an object
1N/Amethod or a function.
1N/A
1N/A
1N/A=back
1N/A
1N/A=head1 EXPORTS
1N/A
1N/ANone by default.
1N/A
1N/AYou may request the import of all three functions (C<isa>, C<can>, and
1N/AC<VERSION>), however it isn't usually necessary to do so. Perl magically
1N/Amakes these functions act as methods on all objects. The one exception is
1N/AC<isa>, which is useful as a function when operating on non-blessed
1N/Areferences.
1N/A
1N/A=cut