Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.2 KiB

  1. package UNIVERSAL;
  2. # UNIVERSAL should not contain any extra subs/methods beyond those
  3. # that it exists to define. The use of Exporter below is a historical
  4. # accident that should be fixed sometime.
  5. require Exporter;
  6. *import = \&Exporter::import;
  7. @EXPORT_OK = qw(isa can);
  8. 1;
  9. __END__
  10. =head1 NAME
  11. UNIVERSAL - base class for ALL classes (blessed references)
  12. =head1 SYNOPSIS
  13. $io = $fd->isa("IO::Handle");
  14. $sub = $obj->can('print');
  15. $yes = UNIVERSAL::isa($ref, "HASH");
  16. =head1 DESCRIPTION
  17. C<UNIVERSAL> is the base class which all bless references will inherit from,
  18. see L<perlobj>
  19. C<UNIVERSAL> provides the following methods
  20. =over 4
  21. =item isa ( TYPE )
  22. C<isa> returns I<true> if C<REF> is blessed into package C<TYPE>
  23. or inherits from package C<TYPE>.
  24. C<isa> can be called as either a static or object method call.
  25. =item can ( METHOD )
  26. C<can> checks if the object has a method called C<METHOD>. If it does
  27. then a reference to the sub is returned. If it does not then I<undef>
  28. is returned.
  29. C<can> can be called as either a static or object method call.
  30. =item VERSION ( [ REQUIRE ] )
  31. C<VERSION> will return the value of the variable C<$VERSION> in the
  32. package the object is blessed into. If C<REQUIRE> is given then
  33. it will do a comparison and die if the package version is not
  34. greater than or equal to C<REQUIRE>.
  35. C<VERSION> can be called as either a static or object method call.
  36. =back
  37. The C<isa> and C<can> methods can also be called as subroutines
  38. =over 4
  39. =item UNIVERSAL::isa ( VAL, TYPE )
  40. C<isa> returns I<true> if the first argument is a reference and either
  41. of the following statements is true.
  42. =over 8
  43. =item
  44. C<VAL> is a blessed reference and is blessed into package C<TYPE>
  45. or inherits from package C<TYPE>
  46. =item
  47. C<VAL> is a reference to a C<TYPE> of perl variable (er 'HASH')
  48. =back
  49. =item UNIVERSAL::can ( VAL, METHOD )
  50. If C<VAL> is a blessed reference which has a method called C<METHOD>,
  51. C<can> returns a reference to the subroutine. If C<VAL> is not
  52. a blessed reference, or if it does not have a method C<METHOD>,
  53. I<undef> is returned.
  54. =back
  55. These subroutines should I<not> be imported via S<C<use UNIVERSAL qw(...)>>.
  56. If you want simple local access to them you can do
  57. *isa = \&UNIVERSAL::isa;
  58. to import isa into your package.
  59. =cut