File Coverage

blib/lib/Class/WhiteHole.pm
Criterion Covered Total %
statement 12 12 100.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 3 3 100.0
pod n/a
total 17 20 85.0


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