Crypto/Exception.pm

filter: Statementstmt 99.5% 204 / 205 Branchbran 85.0% 17 / 20 Conditioncond 75.0% 9 / 12 MC/DCmcdc 62.5% 5 / 8 Subroutinesub 100% 40 / 40 Podpod 100% 5 / 5 totaltotal 96.5% 280 / 290 CC 16 SCAR 9.2
CC
16
Cov
97%
trap_into
7.0
__ANON__
6.2
as_string
3.0
CRAP 2.5
« Crypto/Role/ShallowClone.pm ↑ Summary Crypto/Script/Compiler/Opcode.pm »
1 package Bitcoin::Crypto::Exception;
2 76 $Bitcoin::Crypto::Exception::VERSION = '4.006';
3 76 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 76 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 76 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 76 ▶use Feature::Compat::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 76 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 use overload
11 76 ▶ q{""} => "as_string",
Subroutine BEGIN: called CC=1 SCAR=0.0
12 76 fallback => 1;
13  
14 76 has param 'message' => (
15 isa => Str,
16 writer => -hidden,
17 );
18  
19 has field 'caller' => (
20 isa => Maybe [ArrayRef],
21 513 ▶ default => sub {
Subroutine __ANON__: called CC=6 SCAR=18.2
22 513 for my $call_level (1 .. 20) {
23 3709 my ($package, $file, $line) = caller $call_level;
24 3709 ▶ my $package_ok = defined $package && $package !~ /^(Bitcoin::Crypto|Try::Tiny|Type::Coercion)/;
Condition66%2/3
defined $package && !($package =~ /^(Bitcoin::Crypto|Try::Tiny|Type::Coercion)/u)
!ll&&!rl&&r
02935774
MC/DC50%1/2
defined $package && !($package =~ /^(Bitcoin::Crypto|Try::Tiny|Type::Coercion)/u)
defined $package !($package =~ /^(Bitcoin::Crypto|Try::Tiny|Type::Coercion)/u)
Truth table66%2/3
A && not(B)
A= defined $packageB= !($package =~ /^(Bitcoin::Crypto|Try::Tiny|Type::Coercion)/u)
ABresult
0X0
100
111
25 3709 ▶ my $file_ok = defined $file && $file !~ /\(eval \d+\)/;
Condition66%2/3
defined $file && !($file =~ /\(eval \d+\)/u)
!ll&&!rl&&r
03163393
MC/DC50%1/2
defined $file && !($file =~ /\(eval \d+\)/u)
defined $file !($file =~ /\(eval \d+\)/u)
Truth table66%2/3
A && not(B)
A= defined $fileB= !($file =~ /\(eval \d+\)/u)
ABresult
0X0
100
111
26  
27 3709 ▶ if ($package_ok && $file_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package_ok and $file_ok) 513 3196 3709
Condition100%3/3
$package_ok and $file_ok
!ll&&!rl&&r
2935261513
MC/DC100%2/2
$package_ok and $file_ok
$package_ok $file_ok
Truth table100%3/3
A and B
A= $package_okB= $file_ok
ABresult
0X0
100
111
28 513 return [$package, $file, $line];
29 }
30 }
31 0 return undef;
32 },
33 76 );
34  
35 sub raise
36 615 ▶{
Subroutine raise: called CC=2 SCAR=6.9
Pod documented
37 615 my ($self, $error) = @_;
38  
39 615 ▶ if (defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) 503 112 615
40 503 $self = $self->new(message => $error);
41 }
42  
43 615 die $self;
44 }
45  
46 sub throw
47 1 ▶{
Subroutine throw: called CC=1 SCAR=0.0
Pod documented
48 1 goto \&raise;
49 }
50  
51 sub trap_into
52 5185 ▶{
Subroutine trap_into: called CC=7 SCAR=19.5
Pod documented
53 # try to be fast here. Only unpack arguments if executing the sub fails
54 5185 try {
55 5185 return $_[1]->();
56 }
57 catch ($ex) {
58 155 my ($class, $sub, $prefix) = @_;
59  
60 155 ▶ if (blessed $ex) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($ex)) 129 26 155
61 129 ▶ if ($ex->isa($class)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ex->isa($class)) 112 17 129
62 112 ▶ $ex->_set_message("$prefix: " . $ex->message)
Branch: 1 branch
BranchTrueFalseTotal
if $prefix 112 0 112
63 if $prefix;
64  
65 112 $ex->raise;
66 }
67  
68 17 ▶ if ($ex->isa('Bitcoin::Crypto::Exception')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ex->isa("Bitcoin::Crypto::Exception")) 15 2 17
69 15 ▶ $class->raise(($prefix ? "$prefix: " : '') . $ex->message);
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 15 0 15
70 }
71 }
72  
73 28 my $ex_string = "$ex";
74 28 chomp $ex_string; # remove \n from die_no_trace
75 28 ▶ $class->raise($prefix ? "$prefix: $ex_string" : $ex_string);
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 23 5 28
76 }
77 }
78  
79 sub as_string
80 587 ▶{
Subroutine as_string: called CC=2 SCAR=6.9
Pod documented
81 587 my ($self) = @_;
82  
83 587 my $raised = $self->message;
84 587 $raised =~ s/\s+\z//;
85  
86 587 my $caller = $self->caller;
87 587 ▶ if (defined $caller) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $caller) 587 0 587
88 587 $raised .= ' (raised at ' . $caller->[1] . ', line ' . $caller->[2] . ')';
89 }
90  
91 587 my $class = ref $self;
92 587 $class =~ s/Bitcoin::Crypto::Exception:://;
93  
94 587 return "An error occured in Bitcoin subroutines: [$class] $raised";
95 }
96  
97 {
98  
99 package Bitcoin::Crypto::Exception::Transaction;
100 76 $Bitcoin::Crypto::Exception::Transaction::VERSION = '4.006';
101 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 }
104  
105 {
106  
107 76 package Bitcoin::Crypto::Exception::UTXO;
108 76 $Bitcoin::Crypto::Exception::UTXO::VERSION = '4.006';
109 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
110  
111 }
112  
113 {
114  
115 76 package Bitcoin::Crypto::Exception::Sign;
116 76 $Bitcoin::Crypto::Exception::Sign::VERSION = '4.006';
117 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
118  
119 }
120  
121 {
122  
123 76 package Bitcoin::Crypto::Exception::KeyCreate;
124 76 $Bitcoin::Crypto::Exception::KeyCreate::VERSION = '4.006';
125 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
126 }
127  
128 {
129  
130 76 package Bitcoin::Crypto::Exception::KeyDerive;
131 76 $Bitcoin::Crypto::Exception::KeyDerive::VERSION = '4.006';
132 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
133 }
134  
135 {
136  
137 76 package Bitcoin::Crypto::Exception::MnemonicGenerate;
138 76 $Bitcoin::Crypto::Exception::MnemonicGenerate::VERSION = '4.006';
139 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
140 }
141  
142 {
143  
144 76 package Bitcoin::Crypto::Exception::MnemonicCheck;
145 76 $Bitcoin::Crypto::Exception::MnemonicCheck::VERSION = '4.006';
146 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
147 }
148  
149 {
150  
151 76 package Bitcoin::Crypto::Exception::Base58;
152 76 $Bitcoin::Crypto::Exception::Base58::VERSION = '4.006';
153 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
154 }
155  
156 {
157  
158 76 package Bitcoin::Crypto::Exception::Base58InputFormat;
159 76 $Bitcoin::Crypto::Exception::Base58InputFormat::VERSION = '4.006';
160 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception::Base58';
Subroutine BEGIN: called CC=1 SCAR=0.0
161 }
162  
163 {
164  
165 76 package Bitcoin::Crypto::Exception::Base58InputChecksum;
166 76 $Bitcoin::Crypto::Exception::Base58InputChecksum::VERSION = '4.006';
167 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception::Base58';
Subroutine BEGIN: called CC=1 SCAR=0.0
168 }
169  
170 {
171  
172 76 package Bitcoin::Crypto::Exception::Bech32;
173 76 $Bitcoin::Crypto::Exception::Bech32::VERSION = '4.006';
174 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
175 }
176  
177 {
178  
179 76 package Bitcoin::Crypto::Exception::Bech32InputFormat;
180 76 $Bitcoin::Crypto::Exception::Bech32InputFormat::VERSION = '4.006';
181 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception::Bech32';
Subroutine BEGIN: called CC=1 SCAR=0.0
182 }
183  
184 {
185  
186 76 package Bitcoin::Crypto::Exception::Bech32InputData;
187 76 $Bitcoin::Crypto::Exception::Bech32InputData::VERSION = '4.006';
188 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception::Bech32';
Subroutine BEGIN: called CC=1 SCAR=0.0
189 }
190  
191 {
192  
193 76 package Bitcoin::Crypto::Exception::Bech32InputChecksum;
194 76 $Bitcoin::Crypto::Exception::Bech32InputChecksum::VERSION = '4.006';
195 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception::Bech32';
Subroutine BEGIN: called CC=1 SCAR=0.0
196 }
197  
198 {
199  
200 76 package Bitcoin::Crypto::Exception::SegwitProgram;
201 76 $Bitcoin::Crypto::Exception::SegwitProgram::VERSION = '4.006';
202 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
203 }
204  
205 {
206  
207 76 package Bitcoin::Crypto::Exception::ScriptType;
208 76 $Bitcoin::Crypto::Exception::ScriptType::VERSION = '4.006';
209 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
210 }
211  
212 {
213  
214 76 package Bitcoin::Crypto::Exception::ScriptOpcode;
215 76 $Bitcoin::Crypto::Exception::ScriptOpcode::VERSION = '4.006';
216 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
217 }
218  
219 {
220  
221 76 package Bitcoin::Crypto::Exception::ScriptPush;
222 76 $Bitcoin::Crypto::Exception::ScriptPush::VERSION = '4.006';
223 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
224 }
225  
226 {
227  
228 76 package Bitcoin::Crypto::Exception::Block;
229 76 $Bitcoin::Crypto::Exception::Block::VERSION = '4.006';
230 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
231 }
232  
233 {
234  
235 76 package Bitcoin::Crypto::Exception::ScriptTree;
236 76 $Bitcoin::Crypto::Exception::ScriptTree::VERSION = '4.006';
237 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
238 }
239  
240 {
241  
242 76 package Bitcoin::Crypto::Exception::ScriptCompilation;
243 76 $Bitcoin::Crypto::Exception::ScriptCompilation::VERSION = '4.006';
244 76 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
245  
246 76 extends 'Bitcoin::Crypto::Exception';
247  
248 76 has field 'script' => (
249 isa => ArrayRef,
250 writer => 1,
251 predicate => 1,
252 );
253  
254 76 has field 'error_position' => (
255 isa => PositiveOrZeroInt,
256 writer => 1,
257 predicate => 1,
258 );
259  
260 sub as_string
261 73 ▶ {
Subroutine as_string: called CC=3 SCAR=11.0
Pod documented
262 73 my ($self) = @_;
263 73 my $message = $self->SUPER::as_string;
264  
265 73 ▶ if ($self->has_script && $self->has_error_position) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_script and $self->has_error_position) 57 16 73
Condition66%2/3
$self->has_script and $self->has_error_position
!ll&&!rl&&r
16057
MC/DC50%1/2
$self->has_script and $self->has_error_position
$self->has_script $self->has_error_position
Truth table66%2/3
A and B
A= $self->has_scriptB= $self->has_error_position
ABresult
0X0
100
111
266 57 my @script = @{$self->script};
267 57 $script[$self->error_position] = '> ' . $script[$self->error_position] . ' <-- here';
268 57 $message .= "\n" . join ' ', @script;
269 }
270  
271 73 return $message;
272 }
273 }
274  
275 {
276  
277 76 package Bitcoin::Crypto::Exception::ScriptRuntime;
278 76 $Bitcoin::Crypto::Exception::ScriptRuntime::VERSION = '4.006';
279 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
280 }
281  
282 {
283  
284 76 package Bitcoin::Crypto::Exception::TransactionScript;
285 76 $Bitcoin::Crypto::Exception::TransactionScript::VERSION = '4.006';
286 76 ▶use parent -norequire,
Subroutine BEGIN: called CC=1 SCAR=0.0
287 'Bitcoin::Crypto::Exception::Transaction',
288 76 'Bitcoin::Crypto::Exception::ScriptRuntime';
289 }
290  
291 {
292  
293 76 package Bitcoin::Crypto::Exception::NetworkCheck;
294 76 $Bitcoin::Crypto::Exception::NetworkCheck::VERSION = '4.006';
295 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
296 }
297  
298 {
299  
300 76 package Bitcoin::Crypto::Exception::NetworkConfig;
301 76 $Bitcoin::Crypto::Exception::NetworkConfig::VERSION = '4.006';
302 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
303 }
304  
305 {
306  
307 76 package Bitcoin::Crypto::Exception::Address;
308 76 $Bitcoin::Crypto::Exception::Address::VERSION = '4.006';
309 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
310 }
311  
312 {
313  
314 76 package Bitcoin::Crypto::Exception::AddressGenerate;
315 76 $Bitcoin::Crypto::Exception::AddressGenerate::VERSION = '4.006';
316 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception::Address';
Subroutine BEGIN: called CC=1 SCAR=0.0
317 }
318  
319 {
320  
321 76 package Bitcoin::Crypto::Exception::PSBT;
322 76 $Bitcoin::Crypto::Exception::PSBT::VERSION = '4.006';
323 76 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
324 }
325  
326 76 1;
327  
328 __END__
« Crypto/Role/ShallowClone.pm ↑ Summary Crypto/Script/Compiler/Opcode.pm »