| 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 | ▶ | use Error 0.12; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | package Error::Unhandled; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | @ISA = qw(Error); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | $VERSION = '1.02'; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 4 | ▶ | sub throw { | ||||||||||||||||||||||||||
|
Subroutine
throw: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 35 | 4 | local $Error::Depth = $Error::Depth + 1; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # if we are not rethrow-ing then create the object to throw | ||||||||||||||||||||||||||||
| 38 | 4 | ▶ | $self = $self->new(@_) unless ref($self); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 4 | my $i = 0; | |||||||||||||||||||||||||||
| 41 | 4 | my $handled = 0; | |||||||||||||||||||||||||||
| 42 | 4 | ▶ | while(my $subname = (caller($i++))[3]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 13 | ▶ | if ($subname eq '(eval)' && (caller($i))[3] eq 'Error::subs::try') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$subname eq "(eval)" and (caller $i)[3] eq "Error::subs::try"
MC/DC100%2/2
$subname eq "(eval)" and (caller $i)[3] eq "Error::subs::try"
$subname eq "(eval)"
(caller $i)[3] eq "Error::subs::try"
Truth table100%3/3
A and B
A= $subname eq "(eval)"B= (caller $i)[3] eq "Error::subs::try"
| |||||||||||||||||||||||||||||
| 44 | 2 | $handled = 1; | |||||||||||||||||||||||||||
| 45 | 2 | last; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 4 | ▶ | unless ($handled) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 2 | ▶ | if (exists $self->{unhandled}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | ref($self->{unhandled}) eq 'CODE' and $self->{unhandled}->($self); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } else { | ||||||||||||||||||||||||||||
| 52 | 1 | $self->unhandled; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 3 | die $Error::THROWN = $self; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub unhandled { | ||||||||||||||||||||||||||
|
Subroutine
unhandled: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | 1; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||||||||||