| 1 | ## Domain Registry Interface, Encapsulatng errors (fatal or not) as exceptions in an OO way | ||||||||||||||||||||||||||||||||||||||||
| 2 | ## | ||||||||||||||||||||||||||||||||||||||||
| 3 | ## Copyright (c) 2005,2007-2013,2015 Patrick Mevzek <netdri@dotandco.com>. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||
| 4 | ## | ||||||||||||||||||||||||||||||||||||||||
| 5 | ## This file is part of Net::DRI | ||||||||||||||||||||||||||||||||||||||||
| 6 | ## | ||||||||||||||||||||||||||||||||||||||||
| 7 | ## Net::DRI is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||
| 8 | ## it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||||||||||||||
| 9 | ## the Free Software Foundation; either version 2 of the License, or | ||||||||||||||||||||||||||||||||||||||||
| 10 | ## (at your option) any later version. | ||||||||||||||||||||||||||||||||||||||||
| 11 | ## | ||||||||||||||||||||||||||||||||||||||||
| 12 | ## See the LICENSE file that comes with this distribution for more details. | ||||||||||||||||||||||||||||||||||||||||
| 13 | #################################################################################################### | ||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||
| 15 | package Net::DRI::Exception; | ||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||
| 17 | 103 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 18 | 103 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||
| 20 | 103 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||
| 22 | =pod | ||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||
| 26 | Net::DRI::Exception - Class to store all exceptions inside Net::DRI | ||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||
| 28 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||
| 30 | my $s=Net::DRI::Exception->new(0,'area',500,'message'); | ||||||||||||||||||||||||||||||||||||||||
| 31 | die($s); | ||||||||||||||||||||||||||||||||||||||||
| 32 | ## OR | ||||||||||||||||||||||||||||||||||||||||
| 33 | Net::DRI::Exception->die(0,'area',500,'message'); | ||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||
| 35 | $s->is_error(); ## gives 0 or 1, first argument of new/die | ||||||||||||||||||||||||||||||||||||||||
| 36 | ## (internal error that should not happen are 1, others are 0) | ||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||
| 38 | $s->area(); ## gives back the area (second argument of new/die) | ||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||
| 40 | $s->code(); ## gives back the code (third argument of new/die) | ||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||
| 42 | $s->msg(); ## gives back the message (fourth argument of new/die) | ||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||
| 44 | $s->as_string(); ## gives back a nicely formatted full backtrace | ||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||
| 46 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||
| 48 | For now, support questions should be sent to: | ||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||
| 50 | E<lt>netdri@dotandco.comE<gt> | ||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||
| 52 | Please also see the SUPPORT file in the distribution. | ||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||
| 54 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||
| 56 | E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt> | ||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||
| 58 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||
| 60 | Patrick Mevzek, E<lt>netdri@dotandco.comE<gt> | ||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||
| 62 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||
| 64 | Copyright (c) 2005,2007-2013,2015 Patrick Mevzek <netdri@dotandco.com>. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||
| 66 | This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||
| 67 | it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||||||||||||||
| 68 | the Free Software Foundation; either version 2 of the License, or | ||||||||||||||||||||||||||||||||||||||||
| 69 | (at your option) any later version. | ||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||
| 71 | See the LICENSE file that comes with this distribution for more details. | ||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||
| 75 | #################################################################################################### | ||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||
| 77 | sub new | ||||||||||||||||||||||||||||||||||||||||
| 78 | 91 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 79 | 91 | my ($class,$error,$area,$code,$msg)=@_; | |||||||||||||||||||||||||||||||||||||||
| 80 | 91 | ▶ | my $self={ is_error => (defined $error ? $error : 1 ), | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$area || '?'
$code || 0
$msg || ''
MC/DC0%0/1
$area || '?'
$area
MC/DC0%0/1
$code || 0
$code
MC/DC0%0/1
$msg || ''
$msg
Truth table50%1/2
A
A= $area
Truth table50%1/2
A
A= $code
Truth table50%1/2
A
A= $msg
| |||||||||||||||||||||||||||||||||||||||||
| 81 | area => $area || '?', | ||||||||||||||||||||||||||||||||||||||||
| 82 | code => $code || 0, | ||||||||||||||||||||||||||||||||||||||||
| 83 | msg => $msg || '', | ||||||||||||||||||||||||||||||||||||||||
| 84 | }; | ||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||
| 86 | 91 | $self->{bt}=Carp::longmess(); | |||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||
| 88 | 91 | bless $self,$class; | |||||||||||||||||||||||||||||||||||||||
| 89 | 91 | return $self; | |||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||
| 92 | 89 | ▶ | sub die { die(new(@_)); } ## no critic (Subroutines::ProhibitBuiltinHomonyms Subroutines::RequireArgUnpacking) | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
die: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||
| 94 | 8 | ▶ | sub is_error { return shift->{is_error}; } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 95 | 83 | ▶ | sub area { return shift->{area}; } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
area: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 96 | 83 | ▶ | sub code { return shift->{code}; } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
code: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 97 | 83 | ▶ | sub msg { return shift->{msg}; } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
msg: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||
| 99 | sub backtrace | ||||||||||||||||||||||||||||||||||||||||
| 100 | 75 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
backtrace: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 101 | 75 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||
| 102 | 75 | my $m=$self->{bt}; | |||||||||||||||||||||||||||||||||||||||
| 103 | 75 | my (@bt1,@bt2); | |||||||||||||||||||||||||||||||||||||||
| 104 | 75 | ▶ | foreach (split(/\n/,$m)) { if (/^\s*Net::DRI::(?:BaseClass|Exception)::/) { push @bt1,$_; } else { push @bt2,$_; } } | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||
| 106 | 75 | ▶ | shift(@bt2) if ($bt2[0]=~m!Net/DRI/BaseClass!); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 107 | 75 | ▶ | shift(@bt2) if ($bt2[0]=~m|Net/DRI/Exception(?!\.t)|); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 108 | 75 | my ($f,$l); | |||||||||||||||||||||||||||||||||||||||
| 109 | 75 | ▶ | if (@bt1) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||||||||||||||
| 111 | 73 | ($f,$l)=(pop(@bt1)=~m/ called at (\S+) line (\d+)\.?\s*$/); | |||||||||||||||||||||||||||||||||||||||
| 112 | } else | ||||||||||||||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | ($f,$l)=(shift(@bt2)=~m/ at (\S+) line (\d+)\.?\s*$/); | |||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||
| 116 | 75 | my @b; | |||||||||||||||||||||||||||||||||||||||
| 117 | 75 | push @b,sprintf('EXCEPTION %d@%s from line %d of file %s:',$self->code(),$self->area(),$l,$f); | |||||||||||||||||||||||||||||||||||||||
| 118 | 75 | push @b,$self->msg(); | |||||||||||||||||||||||||||||||||||||||
| 119 | 75 | return (@b,@bt2); | |||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||
| 122 | ## Do not parse result of this call. If needed, use accessors above (is_error(), area(), code(), msg()) | ||||||||||||||||||||||||||||||||||||||||
| 123 | 75 | ▶ | sub as_string { return join("\n",shift->backtrace())."\n"; } | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub print { print shift->as_string(); } ## no critic (Subroutines::ProhibitBuiltinHomonyms Subroutines::RequireFinalReturn) | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||
| 126 | #################################################################################################### | ||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||
| 128 | 77 | ▶ | sub err_failed_load_module { my ($w,$m,$e)=@_; Net::DRI::Exception->die(1,$w,8,'Failed to load Perl module '.$m.' : '.(ref($e)? $e->as_string() : $e)); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn) | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
err_failed_load_module: called CC=2 SCAR=7.2
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | sub err_insufficient_parameters { Net::DRI::Exception->die(1,'internal',2,'Insufficient parameters'.($_[0]? ': '.$_[0] : '')); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn) | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
err_insufficient_parameters: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | ▶ | sub err_invalid_parameters { Net::DRI::Exception->die(1,'internal',3,'Invalid parameters'.($_[0]? ': '.$_[0] : '')); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn) | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
err_invalid_parameters: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | ▶ | sub usererr_insufficient_parameters { Net::DRI::Exception->die(0,'internal',2,'Insufficient parameters'.($_[0]? ': '.$_[0] : '')); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn) | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
usererr_insufficient_parameters: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | ▶ | sub usererr_invalid_parameters { Net::DRI::Exception->die(0,'internal',3,'Invalid parameters'.($_[0]? ': '.$_[0] : '')); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn) | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
usererr_invalid_parameters: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | sub err_assert { Net::DRI::Exception->die(1,'internal',4,'Assert failed'.($_[0]? ': '.$_[0] : '')); } ## no critic (Subroutines::RequireArgUnpacking Subroutines::RequireFinalReturn) | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
err_assert: called CC=2 SCAR=7.6
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||
| 137 | sub method_not_implemented ## no critic (Subroutines::RequireFinalReturn) | ||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
method_not_implemented: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | my ($m,$w)=@_; | |||||||||||||||||||||||||||||||||||||||
| 140 | 1 | ($w)=split(/=/,$w); | |||||||||||||||||||||||||||||||||||||||
| 141 | 1 | Net::DRI::Exception->die(1,'internal',1,sprintf('Method "%s" not implemented in "%s"',$m,$w)); | |||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||
| 144 | #################################################################################################### | ||||||||||||||||||||||||||||||||||||||||
| 145 | 103 | 1; | |||||||||||||||||||||||||||||||||||||||