From 4fcbc3669aa997848e15198cc9fb856287a6788c Mon Sep 17 00:00:00 2001 From: markm Date: Wed, 9 Sep 1998 07:00:04 +0000 Subject: Initial import of Perl5. The king is dead; long live the king! --- contrib/perl5/lib/UNIVERSAL.pm | 97 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 contrib/perl5/lib/UNIVERSAL.pm (limited to 'contrib/perl5/lib/UNIVERSAL.pm') diff --git a/contrib/perl5/lib/UNIVERSAL.pm b/contrib/perl5/lib/UNIVERSAL.pm new file mode 100644 index 0000000..dc02423 --- /dev/null +++ b/contrib/perl5/lib/UNIVERSAL.pm @@ -0,0 +1,97 @@ +package UNIVERSAL; + +# UNIVERSAL should not contain any extra subs/methods beyond those +# that it exists to define. The use of Exporter below is a historical +# accident that should be fixed sometime. +require Exporter; +*import = \&Exporter::import; +@EXPORT_OK = qw(isa can); + +1; +__END__ + +=head1 NAME + +UNIVERSAL - base class for ALL classes (blessed references) + +=head1 SYNOPSIS + + $io = $fd->isa("IO::Handle"); + $sub = $obj->can('print'); + + $yes = UNIVERSAL::isa($ref, "HASH"); + +=head1 DESCRIPTION + +C is the base class which all bless references will inherit from, +see L + +C provides the following methods + +=over 4 + +=item isa ( TYPE ) + +C returns I if C is blessed into package C +or inherits from package C. + +C can be called as either a static or object method call. + +=item can ( METHOD ) + +C checks if the object has a method called C. If it does +then a reference to the sub is returned. If it does not then I +is returned. + +C can be called as either a static or object method call. + +=item VERSION ( [ REQUIRE ] ) + +C will return the value of the variable C<$VERSION> in the +package the object is blessed into. If C is given then +it will do a comparison and die if the package version is not +greater than or equal to C. + +C can be called as either a static or object method call. + +=back + +The C and C methods can also be called as subroutines + +=over 4 + +=item UNIVERSAL::isa ( VAL, TYPE ) + +C returns I if the first argument is a reference and either +of the following statements is true. + +=over 8 + +=item + +C is a blessed reference and is blessed into package C +or inherits from package C + +=item + +C is a reference to a C of perl variable (er 'HASH') + +=back + +=item UNIVERSAL::can ( VAL, METHOD ) + +If C is a blessed reference which has a method called C, +C returns a reference to the subroutine. If C is not +a blessed reference, or if it does not have a method C, +I is returned. + +=back + +These subroutines should I be imported via S>. +If you want simple local access to them you can do + + *isa = \&UNIVERSAL::isa; + +to import isa into your package. + +=cut -- cgit v1.1