File Coverage

blib/lib/Error/Unhandled.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             ##########################################################################
2             #
3             # Error::Unhandled - a Module for letting Errors do their own handling
4             #
5             # Author: Toby Everett
6             # Revision: 1.02
7             # Last Change: Fixed Makefile.pl bug
8             ##########################################################################
9             # Copyright 1995 Graham Barr, 1999 Toby Everett. All rights reserved.
10             #
11             # This file is distributed under the Artistic License. See
12             # http://www.ActiveState.com/corporate/artistic_license.htm or
13             # the license that comes with your perl distribution.
14             #
15             # For comments, questions, bugs or general interest, feel free to
16             # contact Toby Everett at teverett@alascom.att.com
17             #
18             # Graham Barr was responsible for the prototype throw method which I copied
19             # and extended to implement this throw method.
20             ##########################################################################
21              
22 1     1   2390 use Error 0.12;
  0            
  0            
23              
24             package Error::Unhandled;
25              
26             use strict;
27             use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
28              
29             @ISA = qw(Error);
30              
31             $VERSION = '1.02';
32              
33             sub throw {
34             my $self = shift;
35             local $Error::Depth = $Error::Depth + 1;
36              
37             # if we are not rethrow-ing then create the object to throw
38             $self = $self->new(@_) unless ref($self);
39              
40             my $i = 0;
41             my $handled = 0;
42             while(my $subname = (caller($i++))[3]) {
43             if ($subname eq '(eval)' && (caller($i))[3] eq 'Error::subs::try') {
44             $handled = 1;
45             last;
46             }
47             }
48             unless ($handled) {
49             if (exists $self->{unhandled}) {
50             ref($self->{unhandled}) eq 'CODE' and $self->{unhandled}->($self);
51             } else {
52             $self->unhandled;
53             }
54             }
55             die $Error::THROWN = $self;
56             }
57              
58             sub unhandled {
59             }
60              
61             1;
62              
63             __END__