DRI/Exception.pm

filter: Statementstmt 97.9% 48 / 49 Branchbran 63.6% 14 / 22 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 94.7% 18 / 19 Podpod 0.0% 0 / 16 totaltotal 72.1% 83 / 115 CC 16 SCAR 11.0
CC
16
Cov
84%
backtrace
6.0
new
5.7
err_insufficient_parameters
2.1
CRAP 3.0
« DRI/Protocol/EPP/Extensions/Nominet/Message.pm ↑ Summary DRI/DRD/AFNIC.pm »
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 104 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 104 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 104 ▶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 {
79 92 ▶ my ($class,$error,$area,$code,$msg)=@_;
Subroutine new: called CC=5 SCAR=17.5
Pod undocumented
80 92 ▶ my $self={ is_error => (defined $error ? $error : 1 ),
Branch: 1 branch
BranchTrueFalseTotal
defined $error ? : 92 0 92
Condition50%3/6
$area || '?'
l!l
920
$code || 0
l!l
920
$msg || ''
l!l
920
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
Aresult
11
00
Truth table50%1/2
A
A= $code
Aresult
11
00
Truth table50%1/2
A
A= $msg
Aresult
11
00
81 area => $area || '?',
82 code => $code || 0,
83 msg => $msg || '',
84 };
85  
86 92 $self->{bt}=Carp::longmess();
87  
88 92 bless $self,$class;
89 92 return $self;
90 }
91  
92 90 ▶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 84 ▶sub area { return shift->{area}; }
Subroutine area: called CC=1 SCAR=0.0
Pod undocumented
96 84 ▶sub code { return shift->{code}; }
Subroutine code: called CC=1 SCAR=0.0
Pod undocumented
97 84 ▶sub msg { return shift->{msg}; }
Subroutine msg: called CC=1 SCAR=0.0
Pod undocumented
98  
99 sub backtrace
100 {
101 76 ▶ my $self=shift;
Subroutine backtrace: called CC=6 SCAR=17.9
Pod undocumented
102 76 my $m=$self->{bt};
103 76 my (@bt1,@bt2);
104 76 ▶ foreach (split(/\n/,$m)) { if (/^\s*Net::DRI::(?:BaseClass|Exception)::/) { push @bt1,$_; } else { push @bt2,$_; } }
Branch: 1 branch
BranchTrueFalseTotal
if (/^\s*Net::DRI::(?:BaseClass|Exception)::/) { } 147 531 678
105  
106 76 ▶ shift(@bt2) if ($bt2[0]=~m!Net/DRI/BaseClass!);
Branch: 1 branch
BranchTrueFalseTotal
if $bt2[0] =~ m[Net/DRI/BaseClass] 0 76 76
107 76 ▶ shift(@bt2) if ($bt2[0]=~m|Net/DRI/Exception(?!\.t)|);
Branch: 1 branch
BranchTrueFalseTotal
if $bt2[0] =~ m[Net/DRI/Exception(?!\.t)] 74 2 76
108 76 my ($f,$l);
109 76 ▶ if (@bt1)
Branch: 1 branch
BranchTrueFalseTotal
if (@bt1) { } 74 2 76
110 {
111 74 ($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 76 my @b;
117 76 push @b,sprintf('EXCEPTION %d@%s from line %d of file %s:',$self->code(),$self->area(),$l,$f);
118 76 push @b,$self->msg();
119 76 return (@b,@bt2);
120 }
121  
122 ## Do not parse result of this call. If needed, use accessors above (is_error(), area(), code(), msg())
123 76 ▶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 78 ▶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
BranchTrueFalseTotal
ref $e ? : 0 78 78
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
BranchTrueFalseTotal
$_[0] ? : 1 0 1
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
BranchTrueFalseTotal
$_[0] ? : 1 0 1
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
BranchTrueFalseTotal
$_[0] ? : 1 0 1
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
BranchTrueFalseTotal
$_[0] ? : 2 0 2
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
BranchTrueFalseTotal
$_[0] ? : 1 0 1
136  
137 sub method_not_implemented ## no critic (Subroutines::RequireFinalReturn)
138 {
139 1 ▶ my ($m,$w)=@_;
Subroutine method_not_implemented: called CC=1 SCAR=0.0
Pod undocumented
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 104 1;
« DRI/Protocol/EPP/Extensions/Nominet/Message.pm ↑ Summary DRI/DRD/AFNIC.pm »