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 72 $Bitcoin::Crypto::Exception::VERSION = '4.005';
3 72 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 72 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 72 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 72 ▶use Feature::Compat::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 72 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 use overload
11 72 ▶ q{""} => "as_string",
Subroutine BEGIN: called CC=1 SCAR=0.0
12 72 fallback => 1;
13  
14 72 has param 'message' => (
15 isa => Str,
16 writer => -hidden,
17 );
18  
19 has field 'caller' => (
20 isa => Maybe [ArrayRef],
21 455 ▶ default => sub {
Subroutine __ANON__: called CC=6 SCAR=18.2
22 455 for my $call_level (1 .. 20) {
23 3437 my ($package, $file, $line) = caller $call_level;
24 3437 ▶ 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
02726711
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 3437 ▶ my $file_ok = defined $file && $file !~ /\(eval \d+\)/;
Condition66%2/3
defined $file && !($file =~ /\(eval \d+\)/u)
!ll&&!rl&&r
02863151
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 3437 ▶ if ($package_ok && $file_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package_ok and $file_ok) 455 2982 3437
Condition100%3/3
$package_ok and $file_ok
!ll&&!rl&&r
2726256455
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 455 return [$package, $file, $line];
29 }
30 }
31 0 return undef;
32 },
33 72 );
34  
35 sub raise
36 552 ▶{
Subroutine raise: called CC=2 SCAR=6.9
Pod documented
37 552 my ($self, $error) = @_;
38  
39 552 ▶ if (defined $error) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $error) 445 107 552
40 445 $self = $self->new(message => $error);
41 }
42  
43 552 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 4224 ▶{
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 4224 try {
55 4224 return $_[1]->();
56 }
57 catch ($ex) {
58 147 my ($class, $sub, $prefix) = @_;
59  
60 147 ▶ if (blessed $ex) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($ex)) 123 24 147
61 123 ▶ if ($ex->isa($class)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ex->isa($class)) 107 16 123
62 107 ▶ $ex->_set_message("$prefix: " . $ex->message)
Branch: 1 branch
BranchTrueFalseTotal
if $prefix 107 0 107
63 if $prefix;
64  
65 107 $ex->raise;
66 }
67  
68 16 ▶ if ($ex->isa('Bitcoin::Crypto::Exception')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ex->isa("Bitcoin::Crypto::Exception")) 14 2 16
69 14 ▶ $class->raise(($prefix ? "$prefix: " : '') . $ex->message);
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 14 0 14
70 }
71 }
72  
73 26 my $ex_string = "$ex";
74 26 chomp $ex_string; # remove \n from die_no_trace
75 26 ▶ $class->raise($prefix ? "$prefix: $ex_string" : $ex_string);
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 21 5 26
76 }
77 }
78  
79 sub as_string
80 503 ▶{
Subroutine as_string: called CC=2 SCAR=6.9
Pod documented
81 503 my ($self) = @_;
82  
83 503 my $raised = $self->message;
84 503 $raised =~ s/\s+\z//;
85  
86 503 my $caller = $self->caller;
87 503 ▶ if (defined $caller) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $caller) 503 0 503
88 503 $raised .= ' (raised at ' . $caller->[1] . ', line ' . $caller->[2] . ')';
89 }
90  
91 503 my $class = ref $self;
92 503 $class =~ s/Bitcoin::Crypto::Exception:://;
93  
94 503 return "An error occured in Bitcoin subroutines: [$class] $raised";
95 }
96  
97 {
98  
99 package Bitcoin::Crypto::Exception::Transaction;
100 72 $Bitcoin::Crypto::Exception::Transaction::VERSION = '4.005';
101 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 }
104  
105 {
106  
107 72 package Bitcoin::Crypto::Exception::UTXO;
108 72 $Bitcoin::Crypto::Exception::UTXO::VERSION = '4.005';
109 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
110  
111 }
112  
113 {
114  
115 72 package Bitcoin::Crypto::Exception::Sign;
116 72 $Bitcoin::Crypto::Exception::Sign::VERSION = '4.005';
117 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
118  
119 }
120  
121 {
122  
123 72 package Bitcoin::Crypto::Exception::KeyCreate;
124 72 $Bitcoin::Crypto::Exception::KeyCreate::VERSION = '4.005';
125 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
126 }
127  
128 {
129  
130 72 package Bitcoin::Crypto::Exception::KeyDerive;
131 72 $Bitcoin::Crypto::Exception::KeyDerive::VERSION = '4.005';
132 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
133 }
134  
135 {
136  
137 72 package Bitcoin::Crypto::Exception::MnemonicGenerate;
138 72 $Bitcoin::Crypto::Exception::MnemonicGenerate::VERSION = '4.005';
139 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
140 }
141  
142 {
143  
144 72 package Bitcoin::Crypto::Exception::MnemonicCheck;
145 72 $Bitcoin::Crypto::Exception::MnemonicCheck::VERSION = '4.005';
146 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
147 }
148  
149 {
150  
151 72 package Bitcoin::Crypto::Exception::Base58;
152 72 $Bitcoin::Crypto::Exception::Base58::VERSION = '4.005';
153 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
154 }
155  
156 {
157  
158 72 package Bitcoin::Crypto::Exception::Base58InputFormat;
159 72 $Bitcoin::Crypto::Exception::Base58InputFormat::VERSION = '4.005';
160 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception::Base58';
Subroutine BEGIN: called CC=1 SCAR=0.0
161 }
162  
163 {
164  
165 72 package Bitcoin::Crypto::Exception::Base58InputChecksum;
166 72 $Bitcoin::Crypto::Exception::Base58InputChecksum::VERSION = '4.005';
167 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception::Base58';
Subroutine BEGIN: called CC=1 SCAR=0.0
168 }
169  
170 {
171  
172 72 package Bitcoin::Crypto::Exception::Bech32;
173 72 $Bitcoin::Crypto::Exception::Bech32::VERSION = '4.005';
174 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
175 }
176  
177 {
178  
179 72 package Bitcoin::Crypto::Exception::Bech32InputFormat;
180 72 $Bitcoin::Crypto::Exception::Bech32InputFormat::VERSION = '4.005';
181 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception::Bech32';
Subroutine BEGIN: called CC=1 SCAR=0.0
182 }
183  
184 {
185  
186 72 package Bitcoin::Crypto::Exception::Bech32InputData;
187 72 $Bitcoin::Crypto::Exception::Bech32InputData::VERSION = '4.005';
188 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception::Bech32';
Subroutine BEGIN: called CC=1 SCAR=0.0
189 }
190  
191 {
192  
193 72 package Bitcoin::Crypto::Exception::Bech32InputChecksum;
194 72 $Bitcoin::Crypto::Exception::Bech32InputChecksum::VERSION = '4.005';
195 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception::Bech32';
Subroutine BEGIN: called CC=1 SCAR=0.0
196 }
197  
198 {
199  
200 72 package Bitcoin::Crypto::Exception::SegwitProgram;
201 72 $Bitcoin::Crypto::Exception::SegwitProgram::VERSION = '4.005';
202 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
203 }
204  
205 {
206  
207 72 package Bitcoin::Crypto::Exception::ScriptType;
208 72 $Bitcoin::Crypto::Exception::ScriptType::VERSION = '4.005';
209 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
210 }
211  
212 {
213  
214 72 package Bitcoin::Crypto::Exception::ScriptOpcode;
215 72 $Bitcoin::Crypto::Exception::ScriptOpcode::VERSION = '4.005';
216 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
217 }
218  
219 {
220  
221 72 package Bitcoin::Crypto::Exception::ScriptPush;
222 72 $Bitcoin::Crypto::Exception::ScriptPush::VERSION = '4.005';
223 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
224 }
225  
226 {
227  
228 72 package Bitcoin::Crypto::Exception::Block;
229 72 $Bitcoin::Crypto::Exception::Block::VERSION = '4.005';
230 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
231 }
232  
233 {
234  
235 72 package Bitcoin::Crypto::Exception::ScriptTree;
236 72 $Bitcoin::Crypto::Exception::ScriptTree::VERSION = '4.005';
237 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
238 }
239  
240 {
241  
242 72 package Bitcoin::Crypto::Exception::ScriptCompilation;
243 72 $Bitcoin::Crypto::Exception::ScriptCompilation::VERSION = '4.005';
244 72 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
245  
246 72 extends 'Bitcoin::Crypto::Exception';
247  
248 72 has field 'script' => (
249 isa => ArrayRef,
250 writer => 1,
251 predicate => 1,
252 );
253  
254 72 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 72 package Bitcoin::Crypto::Exception::ScriptRuntime;
278 72 $Bitcoin::Crypto::Exception::ScriptRuntime::VERSION = '4.005';
279 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
280 }
281  
282 {
283  
284 72 package Bitcoin::Crypto::Exception::TransactionScript;
285 72 $Bitcoin::Crypto::Exception::TransactionScript::VERSION = '4.005';
286 72 ▶use parent -norequire,
Subroutine BEGIN: called CC=1 SCAR=0.0
287 'Bitcoin::Crypto::Exception::Transaction',
288 72 'Bitcoin::Crypto::Exception::ScriptRuntime';
289 }
290  
291 {
292  
293 72 package Bitcoin::Crypto::Exception::NetworkCheck;
294 72 $Bitcoin::Crypto::Exception::NetworkCheck::VERSION = '4.005';
295 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
296 }
297  
298 {
299  
300 72 package Bitcoin::Crypto::Exception::NetworkConfig;
301 72 $Bitcoin::Crypto::Exception::NetworkConfig::VERSION = '4.005';
302 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
303 }
304  
305 {
306  
307 72 package Bitcoin::Crypto::Exception::Address;
308 72 $Bitcoin::Crypto::Exception::Address::VERSION = '4.005';
309 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
310 }
311  
312 {
313  
314 72 package Bitcoin::Crypto::Exception::AddressGenerate;
315 72 $Bitcoin::Crypto::Exception::AddressGenerate::VERSION = '4.005';
316 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception::Address';
Subroutine BEGIN: called CC=1 SCAR=0.0
317 }
318  
319 {
320  
321 72 package Bitcoin::Crypto::Exception::PSBT;
322 72 $Bitcoin::Crypto::Exception::PSBT::VERSION = '4.005';
323 72 ▶use parent -norequire, 'Bitcoin::Crypto::Exception';
Subroutine BEGIN: called CC=1 SCAR=0.0
324 }
325  
326 72 1;
327  
328 __END__
« Crypto/Role/ShallowClone.pm ↑ Summary Crypto/Script/Compiler/Opcode.pm »