home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / WhiteHole.pm < prev    next >
Encoding:
Perl POD Document  |  2003-07-24  |  2.0 KB  |  89 lines

  1. # $Id: WhiteHole.pm,v 1.4 2001/02/07 11:42:37 schwern Exp $
  2.  
  3. package Class::WhiteHole;
  4.  
  5. require 5;
  6. use strict;
  7. use vars qw(@ISA $VERSION $ErrorMsg);
  8.  
  9. $VERSION = '0.04';
  10. @ISA = ();
  11.  
  12. # From 5.6.0's perldiag.
  13. $ErrorMsg = qq{Can\'t locate object method "%s" via package "%s" }.
  14.             qq{at %s line %d.\n};
  15.  
  16.  
  17.  
  18. =head1 NAME
  19.  
  20. Class::WhiteHole - base class to treat unhandled method calls as errors
  21.  
  22.  
  23. =head1 SYNOPSIS
  24.  
  25.   package Bar;
  26.  
  27.   # DBI inherits from DynaLoader which inherits from AutoLoader
  28.   # Bar wants to avoid this accidental inheritance of AutoLoader.
  29.   use base qw(Class::WhiteHole DBI);
  30.  
  31.  
  32. =head1 DESCRIPTION
  33.  
  34. Its possible to accidentally inherit an AUTOLOAD method.  Often this
  35. will happen if a class somewhere in the chain uses AutoLoader or
  36. defines one of their own.  This can lead to confusing error messages
  37. when method lookups fail.
  38.  
  39. Sometimes you want to avoid this accidental inheritance.  In that
  40. case, inherit from Class::WhiteHole.  All unhandled methods will
  41. produce normal Perl error messages.
  42.  
  43.  
  44. =head1 BUGS & CAVEATS
  45.  
  46. Be sure to have Class::WhiteHole before the class from which you're
  47. inheriting AUTOLOAD in the ISA.  Usually you'll want Class::WhiteHole
  48. to come first.
  49.  
  50. If your class inherits autoloaded routines this class may cause them
  51. to stop working.  Choose wisely before using.
  52.  
  53. White holes are only a hypothesis and may not really exist.
  54.  
  55.  
  56. =head1 COPYRIGHT
  57.  
  58. Copyright 2000 Michael G Schwern <schwern@pobox.com> all rights
  59. reserved.  This program is free software; you can redistribute it
  60. and/or modify it under the same terms as Perl itself.
  61.  
  62.  
  63. =head1 AUTHOR
  64.  
  65. Michael G Schwern <schwern@pobox.com>
  66.  
  67. =head1 SEE ALSO
  68.  
  69. L<Class::BlackHole>
  70.  
  71. =cut
  72.  
  73. sub AUTOLOAD {
  74.     my($proto) = shift;
  75.     my($class) = ref $proto || $proto;
  76.  
  77.     my($meth) = $Class::WhiteHole::AUTOLOAD =~ m/::([^:]+)$/;
  78.  
  79.     return if $meth eq 'DESTROY';
  80.  
  81.     my($callpack, $callfile, $callline) = caller;
  82.  
  83.     die sprintf $ErrorMsg, $meth, $class, $callfile, $callline;
  84. }
  85.  
  86.  
  87. 1;
  88.  
  89.