Syntax-K

Know-How für Ihr Projekt

Perl Documentation

NAME

UNIVERSAL - base class for ALL classes (blessed references)

SYNOPSIS

$is_io    = $fd->isa("IO::Handle");
$is_io    = Class->isa("IO::Handle");
$does_log = $obj->DOES("Logger");
$does_log = Class->DOES("Logger");
$sub      = $obj->can("print");
$sub      = Class->can("print");
$sub      = eval { $ref->can("fandango") };
$ver      = $obj->VERSION;
# but never do this!
$is_io    = UNIVERSAL::isa($fd, "IO::Handle");
$sub      = UNIVERSAL::can($obj, "print");

DESCRIPTION

UNIVERSAL is the base class from which all blessed references inherit. See perlobj.

UNIVERSAL provides the following methods:

WARNINGS

NOTE: can directly uses Perl's internal code for method lookup, and isa uses a very similar method and cache-ing strategy. This may cause strange effects if the Perl code dynamically changes @ISA in any package.

You may add other methods to the UNIVERSAL class via Perl or XS code. You do not need to use UNIVERSAL to make these methods available to your program (and you should not do so).

EXPORTS

None.

Previous versions of this documentation suggested using isa as a function to determine the type of a reference:

$yes = UNIVERSAL::isa($h, "HASH");
$yes = UNIVERSAL::isa("Foo", "Bar");

The problem is that this code would never call an overridden isa method in any class. Instead, use reftype from Scalar::Util for the first case:

use Scalar::Util 'reftype';
$yes = reftype( $h ) eq "HASH";

and the method form of isa for the second:

$yes = Foo->isa("Bar");