X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FUNIVERSAL.pm;h=dc02423029edddd61ef853b75833ec4eb27b5e7c;hb=1ba752a043289c0682ba096aba08751ac71b298a;hp=c0e7ebdee2b2a0f5b2d9e43cc5a64c34ac454774;hpb=3314ffc68a11690bd9977cbdd7ea0601ad6ced13;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/UNIVERSAL.pm b/lib/UNIVERSAL.pm index c0e7ebd..dc02423 100644 --- a/lib/UNIVERSAL.pm +++ b/lib/UNIVERSAL.pm @@ -1,8 +1,11 @@ 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; -@ISA = qw(Exporter); -@EXPORT_OK = qw(isa); +*import = \&Exporter::import; +@EXPORT_OK = qw(isa can); 1; __END__ @@ -13,12 +16,11 @@ UNIVERSAL - base class for ALL classes (blessed references) =head1 SYNOPSIS - use UNIVERSAL qw(isa); - - $yes = isa($ref, "HASH"); $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, @@ -54,11 +56,11 @@ C can be called as either a static or object method call. =back -C also optionally exports the following subroutines +The C and C methods can also be called as subroutines =over 4 -=item isa ( REF, TYPE ) +=item UNIVERSAL::isa ( VAL, TYPE ) C returns I if the first argument is a reference and either of the following statements is true. @@ -67,15 +69,29 @@ of the following statements is true. =item -C is a blessed reference and is blessed into package C +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') +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