blib/lib/Lib/Pepper/Exception.pm

filter: Statementstmt 79.1% 38 / 48 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 75.0% 12 / 16 Podpod 100% 4 / 4 totaltotal 60.0% 54 / 90 SCAR 25.1
CC
8
Cov
59%
checkResult
30.0
getErrorMessage
6.0
isSuccess
6.0
CRAP 12.3
« blib/lib/Lib/Pepper.pm ↑ Summary Pepper.xs »
1 package Lib::Pepper::Exception;
2 #---AUTOPRAGMASTART---
3 5 ▶use v5.42;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use diagnostics;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use mro 'c3';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Carp qw[carp croak confess cluck longmess shortmess];
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 our $VERSION = 0.5;
10 5 ▶use autodie qw( close );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Array::Contains;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Data::Printer;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 #---AUTOPRAGMAEND---
16  
17  
18 5 ▶use Lib::Pepper::Constants qw(:errors);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # Error code to message mapping
21 5 my %ERROR_MESSAGES = (
22 # Success
23 0 => 'Success',
24  
25 # Generic failures
26 -1 => 'Generic failure',
27 -2 => 'Invalid value provided',
28 -3 => 'Invalid state',
29 -4 => 'Functionality not licensed',
30 -5 => 'Out of memory',
31  
32 # Library initialization errors
33 -100 => 'Library initialization failed',
34 -101 => 'Library already initialized',
35 -102 => 'Library loading error',
36 -103 => 'Library not initialized',
37 -104 => 'Library version mismatch',
38 -105 => 'Library dependency error',
39 -106 => 'Library still in use',
40  
41 # Configuration errors
42 -200 => 'Configuration error',
43 -201 => 'Invalid configuration',
44 -202 => 'Missing configuration file',
45 -203 => 'Configuration file invalid',
46 -204 => 'Configuration incomplete',
47  
48 # Logging errors
49 -300 => 'Logging error',
50 -301 => 'Logging initialization failed',
51 -302 => 'Logging file creation failed',
52 -303 => 'Logging file write failed',
53  
54 # Persistence errors
55 -400 => 'Persistence error',
56 -401 => 'Database error',
57 -402 => 'File error',
58 -403 => 'Data corrupt',
59 -404 => 'No data found',
60 -405 => 'Invalid data',
61  
62 # Core errors
63 -500 => 'Core error',
64 -501 => 'Core initialization failed',
65 -502 => 'Core operation failed',
66  
67 # License errors
68 -700 => 'License error',
69 -701 => 'Invalid license',
70 -702 => 'License expired',
71 -703 => 'License not found',
72 -704 => 'License download failed',
73 -705 => 'License verification failed',
74 -706 => 'Feature not licensed',
75 -707 => 'Terminal not licensed',
76 -708 => 'License limit exceeded',
77  
78 # Handle errors
79 -1_000 => 'Invalid handle',
80 -1_001 => 'Null handle',
81 -1_002 => 'Handle not found',
82 -1_003 => 'Handle type mismatch',
83 -1_004 => 'Handle creation failed',
84  
85 # Option list errors
86 -1_100 => 'Option list error',
87 -1_101 => 'Option element not found',
88 -1_102 => 'Option type mismatch',
89 -1_103 => 'Invalid option key',
90 -1_104 => 'Option list empty',
91 -1_105 => 'Duplicate option key',
92 -1_106 => 'Option list operation failed',
93  
94 # Instance errors
95 -1_200 => 'Instance error',
96 -1_201 => 'Instance creation failed',
97 -1_202 => 'Instance not configured',
98 -1_203 => 'Instance invalid state',
99 -1_204 => 'Operation pending',
100 -1_205 => 'Instance not open',
101 -1_206 => 'Instance already open',
102 -1_207 => 'Instance configuration error',
103 -1_208 => 'Instance callback error',
104  
105 # State machine errors
106 -1_300 => 'State machine error',
107 -1_301 => 'Invalid state transition',
108 -1_302 => 'Operation not allowed',
109 -1_303 => 'State machine timeout',
110 -1_304 => 'Operation aborted',
111  
112 # Card type errors
113 -1_400 => 'Card type error',
114 -1_401 => 'Card type not found',
115 -1_402 => 'Card type configuration error',
116  
117 # Communication errors
118 -1_500 => 'Communication error',
119 -1_501 => 'Connection failed',
120 -1_502 => 'Disconnected',
121 -1_503 => 'Communication timeout',
122 -1_504 => 'Send error',
123 -1_505 => 'Receive error',
124 -1_506 => 'Protocol error',
125 -1_507 => 'Invalid response',
126 -1_508 => 'Terminal busy',
127 -1_509 => 'Terminal error',
128 );
129  
130 ▶sub checkResult($self, $result, $context) {
Subroutine checkResult: not called CC=5 SCAR=34.0
Pod documented
131 0 ▶ if(!defined $result) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 0 0 0
132 0 croak("Undefined result code in context: $context");
133 }
134  
135 0 ▶ if($result >= PEP_FUNCTION_RESULT_SUCCESS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result >= 0) 0 0 0
136 0 return 1;
137 }
138  
139 0 ▶ my $message = $ERROR_MESSAGES{$result} || "Unknown error code: $result";
Condition0%0/2
$ERROR_MESSAGES{$result} || "Unknown error code: $result"
l!l
00
MC/DC0%0/1
$ERROR_MESSAGES{$result} || "Unknown error code: $result"
$ERROR_MESSAGES{$result}
Truth table0%0/2
A
A= $ERROR_MESSAGES{$result}
Aresult
11
00
140 0 ▶ my $fullMessage = $context ? "$context: $message (code: $result)" : "$message (code: $result)";
Branch: 1 branch
BranchTrueFalseTotal
$context ? : 0 0 0
141  
142 0 croak($fullMessage);
143 }
144  
145 ▶sub getErrorMessage($self, $result) {
Subroutine getErrorMessage: not called CC=2 SCAR=17.9
Pod documented
146 0 ▶ return $ERROR_MESSAGES{$result} || "Unknown error code: $result";
Condition0%0/2
$ERROR_MESSAGES{$result} || "Unknown error code: $result"
l!l
00
MC/DC0%0/1
$ERROR_MESSAGES{$result} || "Unknown error code: $result"
$ERROR_MESSAGES{$result}
Truth table0%0/2
A
A= $ERROR_MESSAGES{$result}
Aresult
11
00
147 }
148  
149 ▶sub isSuccess($self, $result) {
Subroutine isSuccess: not called CC=2 SCAR=17.9
Pod documented
150 0 ▶ return defined($result) && $result >= PEP_FUNCTION_RESULT_SUCCESS;
Condition0%0/3
defined $result && $result >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $result && $result >= 0
defined $result $result >= 0
Truth table0%0/3
A && B
A= defined $resultB= $result >= 0
ABresult
0X0
100
111
151 }
152  
153 ▶sub isFailure($self, $result) {
Subroutine isFailure: not called CC=2 SCAR=17.9
Pod documented
154 0 ▶ return !defined($result) || $result < PEP_FUNCTION_RESULT_SUCCESS;
Condition0%0/3
!defined($result) || $result < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
!defined($result) || $result < 0
!defined($result) $result < 0
Truth table0%0/3
not(A) || B
A= !defined($result)B= $result < 0
ABresult
1X1
011
000
155 }
156  
157 5 1;
158  
159 __END__
« blib/lib/Lib/Pepper.pm ↑ Summary Pepper.xs »