Leaked source code of windows server 2003
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.

101 lines
2.4 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 one of the following statements is true.
  41. =over 8
  42. =item *
  43. C<VAL> is a reference blessed into either package C<TYPE> or a package
  44. which inherits from package C<TYPE>.
  45. =item *
  46. C<VAL> is a reference to a C<TYPE> of Perl variable (e.g. 'HASH').
  47. =item *
  48. C<VAL> is the name of a package that inherits from (or is itself)
  49. package C<TYPE>.
  50. =back
  51. =item UNIVERSAL::can ( VAL, METHOD )
  52. If C<VAL> is a blessed reference which has a method called C<METHOD>,
  53. C<can> returns a reference to the subroutine. If C<VAL> is not
  54. a blessed reference, or if it does not have a method C<METHOD>,
  55. I<undef> is returned.
  56. =back
  57. These subroutines should I<not> be imported via S<C<use UNIVERSAL qw(...)>>.
  58. If you want simple local access to them you can do
  59. *isa = \&UNIVERSAL::isa;
  60. to import isa into your package.
  61. =cut