NAME

UNIVERSAL - Default general behaviour for all objects.

SYNOPSIS

use UNIVERSAL;

if($obj->isa('IO::Handle')) {
	...
}

$func = $obj->can('some_method_name');

$class = $obj->class;

if($var->is_instance) {
	...
}

DESCRIPTION

The UNIVERSAL package defines methods that are inherited by all other classes. These methods are

isa( CLASS )

isa returns true if its object is blessed into a sub-class of CLASS

isa is also exportable and can be called as a sub with two arguments. This allows the ability to check what a reference points to. Example

use UNIVERSAL qw(isa);

if(isa($ref, 'ARRAY')) {
	...
}
can( METHOD )

can checks to see if its object has a method called METHOD, if it does then a reference to the sub is returned, if it does not then undef is returned.

class()

class returns the class name of its object.

is_instance()

is_instance returns true if its object is an instance of some class, false if its object is the class (package) itself. Example

A->is_instance();       # Flase

$var = 'A';
$var->is_instance();    # False

$ref = bless [], 'A';
$ref->is_instance();    # True

NOTE

isa and can are implemented in XS code. 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.

AUTHOR

Graham Barr <Graham.Barr@tiuk.ti.com>

COPYRIGHT

Copyright (c) 1995 Graham Barr. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

REVISION

$Revision: 1.2 $