UK.pm

filter: Statementstmt 92.2% 190 / 206 Branchbran 80.4% 111 / 138 Conditioncond 71.6% 43 / 60 MC/DCmcdc 46.6% 14 / 30 Subroutinesub 100% 18 / 18 Podpod 100% 2 / 2 totaltotal 83.2% 378 / 454 CC 98 SCAR 31.1
CC
98
Cov
85%
is_valid
39.4
_standard_check
25.9
_check_result
16.7
CRAP 22.5
↑ Summary UK/Rule.pm »
1 package BankAccount::Validator::UK;
2  
3 3 $BankAccount::Validator::UK::VERSION = '0.64';
4 3 $BankAccount::Validator::UK::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 BankAccount::Validator::UK - Interface to validate UK bank account.
9  
10 =head1 VERSION
11  
12 Version 0.64
13  
14 =cut
15  
16 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use BankAccount::Validator::UK::Rule;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 has sc => (is => 'rw');
24 3 has an => (is => 'rw');
25 3 has mod => (is => 'rw');
26 3 has attempt => (is => 'rw');
27 3 has last_ex => (is => 'rw');
28 3 has trace => (is => 'rw');
29 35 ▶has debug => (is => 'ro', default => sub { 0 });
Subroutine __ANON__: called CC=1 SCAR=0.0
30 36 ▶has last_check => (is => 'rw', default => sub { 0 });
Subroutine __ANON__: called CC=1 SCAR=0.0
31 36 ▶has multi_rule => (is => 'ro', default => sub { 0 });
Subroutine __ANON__: called CC=1 SCAR=0.0
32 36 ▶has sort_code => (is => 'ro', default => sub { BankAccount::Validator::UK::Rule::get_sort_codes() });
Subroutine __ANON__: called CC=1 SCAR=0.0
33  
34 =head1 DESCRIPTION
35  
36 The module uses the algorithm provided by VOCALINK to validate the bank sort code
37 and account number. It is done by modulus checking method as specified in the
38 document which is available on their website L<VOCALINK|https://www.vocalink.com/tools/modulus-checking/>
39 It currently supports the document L<v7.20|https://www.vocalink.com/media/y3nfvmjy/validating-account-numbers-v7-2.pdf> drafted 31st May 2022.
40  
41 Institutions covered by this document are below:
42  
43 =over 4
44  
45 =item * Allied Irish
46  
47 =item * Bank of England
48  
49 =item * Bank of Ireland
50  
51 =item * Bank of Scotland
52  
53 =item * Barclays
54  
55 =item * Bradford and Bingley Building Society
56  
57 =item * Charity Bank
58  
59 =item * Citibank
60  
61 =item * Clear Bank
62  
63 =item * Clydesdale
64  
65 =item * Contis Financial Services
66  
67 =item * Co-Operative Bank
68  
69 =item * Coutts
70  
71 =item * First Trust
72  
73 =item * Halifax
74  
75 =item * Hoares Bank
76  
77 =item * HSBC
78  
79 =item * Lloyds
80  
81 =item * Metro Bank
82  
83 =item * NatWest
84  
85 =item * Nationwide Building Society
86  
87 =item * Northern
88  
89 =item * Orwell Union Ltd.
90  
91 =item * Royal Bank of Scotland
92  
93 =item * Santander
94  
95 =item * Secure Trust
96  
97 =item * Starling Bank
98  
99 =item * Tesco Bank
100  
101 =item * TSB
102  
103 =item * Ulster Bank
104  
105 =item * Unity Trust Bank
106  
107 =item * Virgin Bank
108  
109 =item * Williams & Glyn
110  
111 =item * Woolwich
112  
113 =item * Yorkshire Bank
114  
115 =back
116  
117 =head2 NOTE
118  
119 If the modulus check shows the account number as valid this means that the account
120 number is a possible account number for the sorting code but does'nt necessarily
121 mean that it's an account number being used at that sorting code. Any account
122 details found as invalid should be checked with the account holder where possible.
123  
124 =head1 CONSTRUCTOR
125  
126 The constructor simply expects debug flag, which is optional. By the default the
127 debug flag is off.
128  
129 use strict; use warnings;
130 use BankAccount::Validator::UK;
131  
132 # Debug is turned off.
133 my $account1 = BankAccount::Validator::UK->new;
134  
135 # Debug is turned on.
136 my $account2 = BankAccount::Validator::UK->new(debug => 1);
137  
138 =head1 METHODS
139  
140 =head2 is_valid($sort_code, $account_number)
141  
142 It expects two parameters i.e. the sort code and the account number.The sort code
143 can be either nn-nn-nn or nnnnnn format. If the account number starts with 0 then
144 its advisable to pass in as string i.e. '0nnnnnnn'.
145  
146 use strict; use warnings;
147 use BankAccount::Validator::UK;
148  
149 my $account = BankAccount::Validator::UK->new;
150 print "[10-79-99][88837491] is valid.\n"
151 if $account->is_valid(107999, 88837491);
152  
153 print "[18-00-02][00000190] is valid.\n"
154 if $account->is_valid('18-00-02', '00000190');
155  
156 =cut
157  
158 sub is_valid {
159 41 ▶ my ($self, $sc, $an) = @_;
Subroutine is_valid: called CC=36 SCAR=36.7
Pod documented
160  
161 41 ▶ die("ERROR: Missing bank sort code.\n") unless defined $sc;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sc 1 40 41
162 40 ▶ die("ERROR: Missing bank account number.\n") unless defined $an;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $an 1 39 40
163  
164 39 ($sc, $an) = _prepare($sc, $an);
165 37 ▶ die("ERROR: Invalid sort code.\n") unless (length($sc) == 6);
Branch: 1 branch
BranchTrueFalseTotal
unless length $sc == 6 1 36 37
166 36 ▶ die("ERROR: Invalid account number.\n") unless (length($an) == 8);
Branch: 1 branch
BranchTrueFalseTotal
unless length $an == 8 1 35 36
167  
168 35 my $_sort_code = _init('u', $sc);
169 35 my $_account_number = _init('a', $an);
170 35 my $_rules = _get_rules($sc);
171  
172 35 ▶ next if (scalar(@{$_rules}) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$_rules;} == 0 0 35 35
173  
174 35 $self->{sc} = $sc;
175 35 $self->{an} = $an;
176 35 ▶ $self->{multi_rule} = (scalar(@{$_rules}) > 1)?(1):(0);
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$_rules;} > 1 ? : 25 10 35
177 35 foreach my $_rule (@{$_rules}) {
178 45 $self->{attempt}++;
179 _init('u', '090126', $_sort_code)
180 45 ▶ if ($_rule->{ex} == 8);
Branch: 1 branch
BranchTrueFalseTotal
if $_rule->{"ex"} == 8 1 44 45
181  
182 45 ▶ if (($_rule->{ex} == 6)
Branch: 1 branch
BranchTrueFalseTotal
if ($_rule->{"ex"} == 6 and $_account_number->{"a"} =~ /^[4|5|6|7|8]$/ and $_account_number->{"g"} == $_account_number->{"h"}) 2 43 45
Condition83%5/6
$_rule->{"ex"} == 6 and $_account_number->{"a"} =~ /^[4|5|6|7|8]$/ and $_account_number->{"g"} == $_account_number->{"h"}
!ll&&!rl&&r
3852
$_rule->{"ex"} == 6 and $_account_number->{"a"} =~ /^[4|5|6|7|8]$/
!ll&&!rl&&r
3807
MC/DC66%2/3
$_rule->{"ex"} == 6 and $_account_number->{"a"} =~ /^[4|5|6|7|8]$/ and $_account_number->{"g"} == $_account_number->{"h"}
$_rule->{"ex"} == 6 $_account_number->{"a"} =~ /^[4|5|6|7|8]$/ $_account_number->{"g"} == $_account_number->{"h"}
Truth table75%3/4
A and B and C
A= $_rule->{"ex"} == 6B= $_account_number->{"a"} =~ /^[4|5|6|7|8]$/C= $_account_number->{"g"} == $_account_number->{"h"}
ABCresult
0XX0
10X0
1100
1111
183 &&
184 ($_account_number->{a} =~ /^[4|5|6|7|8]$/)
185 &&
186 ($_account_number->{g} == $_account_number->{h})) {
187  
188 2 $self->{last_ex} = $_rule->{ex};
189 2 $self->{last_check} = 1;
190 2 push @{$self->{trace}}, {'ex' => $_rule->{ex},
191 'mod' => $_rule->{mod},
192 2 'res' => 'VALID'};
193 2 next;
194 }
195  
196 43 ▶ if (($_rule->{ex} == 7) && ($_account_number->{g} == 9)) {
Branch: 6 branches
BranchTrueFalseTotal
if ($_rule->{'ex'} == 7 and $_account_number->{'g'} == 9) { } 1 42 43
elsif ($_rule->{'ex'} == 8) { } 1 41 42
elsif ($_rule->{'ex'} =~ /^[2|9]$/) { } 5 36 41
elsif ($_rule->{'ex'} == 10) { } 5 31 36
elsif ($_rule->{'ex'} == 3) { } 0 31 31
elsif ($_rule->{'ex'} == 5) { } 10 21 31
Condition66%2/3
$_rule->{"ex"} == 7 and $_account_number->{"g"} == 9
!ll&&!rl&&r
4201
MC/DC50%1/2
$_rule->{"ex"} == 7 and $_account_number->{"g"} == 9
$_rule->{"ex"} == 7 $_account_number->{"g"} == 9
Truth table66%2/3
A and B
A= $_rule->{"ex"} == 7B= $_account_number->{"g"} == 9
ABresult
0X0
100
111
197 1 _init('u','000000', $_rule);
198 1 _init('a','00', $_rule);
199 }
200 elsif ($_rule->{ex} == 8) {
201 1 _init('u', '090126', $_sort_code);
202 }
203 elsif ($_rule->{ex} =~ /^[2|9]$/) {
204 5 ▶ if ($_rule->{ex} == 9) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_rule->{'ex'} == 9) { } 1 4 5
elsif ($_account_number->{'a'} != 0) { } 3 1 4
205 1 _init('u', '309634', $_sort_code);
206 }
207 elsif ($_account_number->{a} != 0) {
208 3 ▶ if ($_account_number->{g} != 9) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_account_number->{'g'} != 9) { } 2 1 3
elsif ($_account_number->{'g'} == 9) { } 1 0 1
209 2 _init('u','001253', $_rule);
210 2 _init('a','6,4,8,7,10,9,3,1', $_rule);
211 }
212 elsif ($_account_number->{g} == 9) {
213 1 _init('u','000000', $_rule);
214 1 _init('a','0,0,8,7,10,9,3,1', $_rule);
215 }
216 }
217 }
218 elsif ($_rule->{ex} == 10) {
219 5 my $_ab = sprintf("%s%s", $_account_number->{a}, $_account_number->{b});
220 5 ▶ if ((($_ab eq "09") or ($_ab eq "99")) && ($_account_number->{g} == 9)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ab eq "09" || $_ab eq 99 and $_account_number->{"g"} == 9) 3 2 5
Condition83%5/6
$_ab eq "09" || $_ab eq 99 and $_account_number->{"g"} == 9
!ll&&!rl&&r
203
$_ab eq "09" or $_ab eq 99
l!l&&r!l&&!r
212
MC/DC66%2/3
$_ab eq "09" || $_ab eq 99 and $_account_number->{"g"} == 9
$_ab eq "09" $_ab eq 99 $_account_number->{"g"} == 9
Truth table60%3/5
A or B and C
A= $_ab eq "09"B= $_ab eq 99C= $_account_number->{"g"} == 9
ABCresult
00X0
1X00
0100
1X11
0111
221 3 _init('u', '000000', $_rule);
222 3 _init('a', '00', $_rule);
223 }
224 }
225 elsif ($_rule->{ex} == 3) {
226 0 $self->{last_ex} = 3;
227 0 ▶ next if ($_account_number->{c} =~ /^[6|9]$/);
Branch: 1 branch
BranchTrueFalseTotal
if $_account_number->{"c"} =~ /^[6|9]$/ 0 0 0
228 }
229 elsif ($_rule->{ex} == 5) {
230 _init('u', $self->{sort_code}->{$sc}, $_sort_code)
231 10 ▶ if (exists $self->{sort_code}->{$sc});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"sort_code"}{$sc} 2 8 10
232 }
233  
234 43 my $_status;
235 43 ▶ if ($_rule->{mod} =~ /MOD(\d+)/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_rule->{'mod'} =~ /MOD(\d+)/i) { } 35 8 43
elsif ($_rule->{'mod'} =~ /DBLAL/i) { } 8 0 8
236 35 $_status = $self->_standard_check($_sort_code, $_account_number, $_rule);
237 }
238 elsif ($_rule->{mod} =~ /DBLAL/i) {
239 8 $_status = $self->_double_alternate_check($_sort_code, $_account_number, $_rule);
240 }
241  
242 43 ▶ if (defined $_status) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_status) 43 0 43
243 43 $self->{last_ex} = $_status->{ex};
244 43 ▶ $self->{last_check} = ($_status->{res} eq 'PASS')?(1):(0);;
Branch: 1 branch
BranchTrueFalseTotal
$_status->{'res'} eq 'PASS' ? : 32 11 43
245 43 push @{$self->{trace}}, $_status;
246 }
247  
248 43 my $_result = $self->_check_result();
249 43 ▶ return $_result if defined $_result;
Branch: 1 branch
BranchTrueFalseTotal
if defined $_result 34 9 43
250 }
251  
252 return $self->{last_check}
253 1 ▶ if ((defined $self->{last_ex}) && ($self->{last_ex} =~ /^6$/) && ($self->{multi_rule}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^6$/ and $self->{"multi_rule"} 1 0 1
Condition33%2/6
defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^6$/ and $self->{"multi_rule"}
!ll&&!rl&&r
001
defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^6$/
!ll&&!rl&&r
001
MC/DC0%0/3
defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^6$/ and $self->{"multi_rule"}
defined $self->{"last_ex"} $self->{"last_ex"} =~ /^6$/ $self->{"multi_rule"}
Truth table25%1/4
A and B and C
A= defined $self->{"last_ex"}B= $self->{"last_ex"} =~ /^6$/C= $self->{"multi_rule"}
ABCresult
0XX0
10X0
1100
1111
254  
255 0 return;
256 }
257  
258 =head2 get_trace()
259  
260 Returns the trace information about each rule that applied to the given sort code
261 and account number.
262  
263 use strict; use warnings;
264 use Data::Dumper;
265 use BankAccount::Validator::UK;
266  
267 my $account = BankAccount::Validator::UK->new;
268 print "[87-14-27][09123496] is valid.\n"
269 if $account->is_valid('871427', '09123496');
270  
271 print "Trace information:\n" . Dumper($account->get_trace);
272  
273 =cut
274  
275 sub get_trace {
276 1 ▶ my ($self) = @_;
Subroutine get_trace: called CC=2 SCAR=7.1
Pod documented
277  
278 1 ▶ return $self->{trace} if scalar(@{$self->{trace}});
Branch: 1 branch
BranchTrueFalseTotal
if scalar @{$self->{"trace"};} 1 0 1
279 }
280  
281 #
282 #
283 # PRIVATE METHODS
284  
285 sub _standard_check {
286 35 ▶ my ($self, $_sort_code, $_account_number, $_rule) = @_;
Subroutine _standard_check: called CC=23 SCAR=32.5
287  
288 35 my $total = 0;
289 35 ▶ $total += 27 if ($_rule->{ex} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $_rule->{"ex"} == 1 0 35 35
290  
291 35 ▶ if ($_rule->{mod} =~ /MOD(\d+)/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_rule->{"mod"} =~ /MOD(\d+)/i) 35 0 35
292 35 foreach (keys %{$_sort_code}) {
293 print "KEY: [$_] SC: [$_sort_code->{$_}] WEIGHTING: [$_rule->{$_}]\n"
294 210 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 210 210
295 210 $total += $_sort_code->{$_} * $_rule->{$_};
296 }
297  
298 35 foreach (keys %{$_account_number}) {
299 print "KEY: [$_] AN: [$_account_number->{$_}] WEIGHTING: [$_rule->{$_}]\n"
300 280 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 280 280
301 280 $total += $_account_number->{$_} * $_rule->{$_};
302 }
303  
304 35 my $remainder = $total % $1;
305 35 ▶ if ($_rule->{ex} == 4) {
Branch: 3 branches
BranchTrueFalseTotal
if ($_rule->{'ex'} == 4) { } 1 34 35
elsif ($_rule->{'ex'} == 5 and $1 == 11) { } 6 28 34
elsif ($remainder == 0) { } 21 7 28
306 1 my $_gh = sprintf("%d%d", $_account_number->{g}, $_account_number->{h});
307 1 ▶ if ($remainder == $_gh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remainder == $_gh) 1 0 1
308 return {'ex' => $_rule->{ex},
309 'mod' => $_rule->{mod},
310 1 'rem' => $remainder,
311 'tot' => $total,
312 'res' => 'PASS'};
313 }
314 }
315 ▶ elsif (($_rule->{ex} == 5) && ($1 == 11)) {
Condition66%2/3
$_rule->{"ex"} == 5 and $1 == 11
!ll&&!rl&&r
2806
MC/DC50%1/2
$_rule->{"ex"} == 5 and $1 == 11
$_rule->{"ex"} == 5 $1 == 11
Truth table66%2/3
A and B
A= $_rule->{"ex"} == 5B= $1 == 11
ABresult
0X0
100
111
316 6 ▶ if ($remainder == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($remainder == 0) { } 2 4 6
elsif ($remainder == 1) { } 1 3 4
317 2 ▶ if ($_account_number->{g} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_account_number->{'g'} == 0) { } 2 0 2
318 return {'ex' => $_rule->{ex},
319 'mod' => $_rule->{mod},
320 2 'rem' => $remainder,
321 'tot' => $total,
322 'res' => 'PASS'};
323 }
324 else {
325 return {'ex' => $_rule->{ex},
326 'mod' => $_rule->{mod},
327 0 'rem' => $remainder,
328 'tot' => $total,
329 'res' => 'FAIL'};
330 }
331 }
332 elsif ($remainder == 1) {
333 return {'ex' => $_rule->{ex},
334 'mod' => $_rule->{mod},
335 1 'rem' => $remainder,
336 'tot' => $total,
337 'res' => 'FAIL'};
338 }
339 else {
340 3 $remainder = 11 - $remainder;
341 3 ▶ if ($_account_number->{g} == $remainder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_account_number->{'g'} == $remainder) { } 2 1 3
342 return {'ex' => $_rule->{ex},
343 'mod' => $_rule->{mod},
344 2 'rem' => $remainder,
345 'tot' => $total,
346 'res' => 'PASS'};
347 }
348 else {
349 return {'ex' => $_rule->{ex},
350 'mod' => $_rule->{mod},
351 1 'rem' => $remainder,
352 'tot' => $total,
353 'res' => 'FAIL'};
354 }
355 }
356 }
357 elsif ($remainder == 0) {
358 return {'ex' => $_rule->{ex},
359 'mod' => $_rule->{mod},
360 21 'rem' => $remainder,
361 'tot' => $total,
362 'res' => 'PASS'};
363 }
364 else {
365 7 ▶ if ($_rule->{ex} == 14) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_rule->{'ex'} == 14) { } 1 6 7
366 1 ▶ if ($_account_number->{h} =~ /^[0|1|9]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_account_number->{'h'} =~ /^[0|1|9]$/) { } 1 0 1
367 1 my $an = substr($self->{an}, 0, 7);
368 1 $an = sprintf("%s%s", '0', $an);
369 1 _init('a', $an, $_account_number);
370  
371 1 $total = 0;
372 1 foreach (keys %{$_sort_code}) {
373 print "KEY: [$_] SC: [$_sort_code->{$_}] WEIGHTING: [$_rule->{$_}]\n"
374 6 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 6 6
375 6 $total += $_sort_code->{$_} * $_rule->{$_};
376 }
377  
378 1 foreach (keys %{$_account_number}) {
379 print "KEY: [$_] AN: [$_account_number->{$_}] WEIGHTING: [$_rule->{$_}]\n"
380 8 ▶ if $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"debug"} 0 8 8
381 8 $total += $_account_number->{$_} * $_rule->{$_};
382 }
383  
384 1 $remainder = $total % 11;
385 1 ▶ if ($remainder == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remainder == 0) { } 1 0 1
386 return {'ex' => $_rule->{ex},
387 'mod' => $_rule->{mod},
388 1 'rem' => $remainder,
389 'tot' => $total,
390 'res' => 'PASS'};
391 }
392 else {
393 return {'ex' => $_rule->{ex},
394 'mod' => $_rule->{mod},
395 0 'rem' => $remainder,
396 'tot' => $total,
397 'res' => 'FAIL'};
398 }
399 }
400 else {
401 return {'ex' => $_rule->{ex},
402 'mod' => $_rule->{mod},
403 0 'rem' => $remainder,
404 'tot' => $total,
405 'res' => 'FAIL'};
406 }
407 }
408 else {
409 return {'ex' => $_rule->{ex},
410 'mod' => $_rule->{mod},
411 6 'rem' => $remainder,
412 'tot' => $total,
413 'res' => 'FAIL'};
414 }
415 }
416 }
417  
418 0 return;
419 }
420  
421 sub _double_alternate_check {
422 8 ▶ my ($self, $_sort_code, $_account_number, $_rule) = @_;
Subroutine _double_alternate_check: called CC=11 SCAR=24.0
423  
424 8 my $total = 0;
425 8 ▶ $total += 27 if ($_rule->{ex} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $_rule->{"ex"} == 1 2 6 8
426  
427 8 foreach (keys %{$_sort_code}) {
428 48 $total += _dbal_total($_sort_code->{$_} * $_rule->{$_});
429 }
430  
431 8 foreach (keys %{$_account_number}) {
432 64 $total += _dbal_total($_account_number->{$_} * $_rule->{$_});
433 }
434  
435 8 my $remainder = $total % 10;
436 8 ▶ if ($_rule->{ex} == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($_rule->{'ex'} == 1) { } 2 6 8
elsif ($_rule->{'ex'} == 5) { } 4 2 6
elsif ($remainder == 0) { } 1 1 2
437 2 ▶ if ($remainder == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remainder == 0) { } 1 1 2
438 return {'ex' => $_rule->{ex},
439 'mod' => $_rule->{mod},
440 1 'rem' => $remainder,
441 'tot' => $total,
442 'res' => 'PASS'};
443 }
444 else {
445 return {'ex' => $_rule->{ex},
446 'mod' => $_rule->{mod},
447 1 'rem' => $remainder,
448 'tot' => $total,
449 'res' => 'FAIL'};
450 }
451 }
452 elsif ($_rule->{ex} == 5) {
453 4 ▶ if ($remainder == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remainder == 0) { } 1 3 4
454 1 ▶ if ($_account_number->{h} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_account_number->{"h"} == 0) 1 0 1
455 return {'ex' => $_rule->{ex},
456 'mod' => $_rule->{mod},
457 1 'rem' => $remainder,
458 'tot' => $total,
459 'res' => 'PASS'};
460 }
461 }
462 else {
463 3 $remainder = 10 - $remainder;
464 3 ▶ if ($_account_number->{h} == $remainder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_account_number->{'h'} == $remainder) { } 2 1 3
465 return {'ex' => $_rule->{ex},
466 'mod' => $_rule->{mod},
467 2 'rem' => $remainder,
468 'tot' => $total,
469 'res' => 'PASS'};
470 }
471 else {
472 return {'ex' => $_rule->{ex},
473 'mod' => $_rule->{mod},
474 1 'rem' => $remainder,
475 'tot' => $total,
476 'res' => 'FAIL'};
477 }
478 }
479 }
480 elsif ($remainder == 0) {
481 return {'ex' => $_rule->{ex},
482 'mod' => $_rule->{mod},
483 1 'rem' => $remainder,
484 'tot' => $total,
485 'res' => 'PASS'};
486 }
487 else {
488 return {'ex' => $_rule->{ex},
489 'mod' => $_rule->{mod},
490 1 'rem' => $remainder,
491 'tot' => $total,
492 'res' => 'FAIL'};
493 }
494 }
495  
496 sub _init {
497 90 ▶ my ($index, $data, $init) = @_;
Subroutine _init: called CC=2 SCAR=6.9
498  
499 90 ▶ if ($data =~ /\,/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ /\,/) { } 3 87 90
500 3 map { $init->{$index++} = $_; } split /\,/,$data;
501 }
502 else {
503 87 map { $init->{$index++} = $_; } split //,$data;
504 }
505  
506 90 return $init;
507 }
508  
509 sub _check_result {
510 43 ▶ my ($self) = @_;
Subroutine _check_result: called CC=16 SCAR=28.2
511  
512 43 ▶ if ($self->{multi_rule}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'multi_rule'}) { } 33 10 43
513 33 ▶ if (((defined $self->{last_ex})
Branch: 4 branches
BranchTrueFalseTotal
if (defined $self->{'last_ex'} and $self->{'last_ex'} =~ /^2|10|12$/ and $self->{'last_check'} == 1 or defined $self->{'last_ex'} and $self->{'last_ex'} =~ /^9|11|13$/ and $self->{'last_check'} == 1 and $self->{'attempt'} == 2) { } 12 21 33
elsif (defined $self->{'last_ex'} and $self->{'last_ex'} =~ /^5|6$/ and $self->{'last_check'} == 0) { } 5 16 21
elsif (defined $self->{'last_ex'} and $self->{'last_ex'} == 0 and $self->{'last_check'} == 1) { } 3 13 16
elsif ($self->{'attempt'} == 2) { } 4 9 13
Condition77%14/18
defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^2|10|12$/ and $self->{"last_check"} == 1 or defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^9|11|13$/ and $self->{"last_check"} == 1 and $self->{"attempt"} == 2
l!l&&r!l&&!r
9321
defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^2|10|12$/ and $self->{"last_check"} == 1
!ll&&!rl&&r
2139
defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^2|10|12$/
!ll&&!rl&&r
02112
defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^9|11|13$/ and $self->{"last_check"} == 1 and $self->{"attempt"} == 2
!ll&&!rl&&r
2103
defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^9|11|13$/ and $self->{"last_check"} == 1
!ll&&!rl&&r
2103
defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^9|11|13$/
!ll&&!rl&&r
0213
MC/DC42%3/7
defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^2|10|12$/ and $self->{"last_check"} == 1 or defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^9|11|13$/ and $self->{"last_check"} == 1 and $self->{"attempt"} == 2
defined $self->{"last_ex"} $self->{"last_ex"} =~ /^2|10|12$/ $self->{"last_check"} == 1 defined $self->{"last_ex"} $self->{"last_ex"} =~ /^9|11|13$/ $self->{"last_check"} == 1 $self->{"attempt"} == 2
Truth table25%4/16
A and B and C or D and E and F and G
A= defined $self->{"last_ex"}B= $self->{"last_ex"} =~ /^2|10|12$/C= $self->{"last_check"} == 1D= defined $self->{"last_ex"}E= $self->{"last_ex"} =~ /^9|11|13$/F= $self->{"last_check"} == 1G= $self->{"attempt"} == 2
ABCDEFGresult
111XXXX1
0XX11111
10X11111
11011111
0XX0XXX0
0XX10XX0
0XX110X0
0XX11100
10X0XXX0
10X10XX0
10X110X0
10X11100
1100XXX0
11010XX0
110110X0
11011100
514 && ($self->{last_ex} =~ /^2|10|12$/)
515 && ($self->{last_check} == 1))
516 ||
517 ((defined $self->{last_ex})
518 && ($self->{last_ex} =~ /^9|11|13$/)
519 && ($self->{last_check} == 1)
520 && ($self->{attempt} == 2))) {
521 12 return 1;
522 }
523 ▶ elsif ((defined $self->{last_ex})
Condition83%5/6
defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^5|6$/ and $self->{"last_check"} == 0
!ll&&!rl&&r
6105
defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^5|6$/
!ll&&!rl&&r
0615
MC/DC66%2/3
defined $self->{"last_ex"} and $self->{"last_ex"} =~ /^5|6$/ and $self->{"last_check"} == 0
defined $self->{"last_ex"} $self->{"last_ex"} =~ /^5|6$/ $self->{"last_check"} == 0
Truth table75%3/4
A and B and C
A= defined $self->{"last_ex"}B= $self->{"last_ex"} =~ /^5|6$/C= $self->{"last_check"} == 0
ABCresult
0XX0
10X0
1100
1111
524 && ($self->{last_ex} =~ /^5|6$/)
525 && ($self->{last_check} == 0)) {
526 5 return 0;
527 }
528 ▶ elsif ((defined $self->{last_ex})
Condition66%4/6
defined $self->{"last_ex"} and $self->{"last_ex"} == 0 and $self->{"last_check"} == 1
!ll&&!rl&&r
1303
defined $self->{"last_ex"} and $self->{"last_ex"} == 0
!ll&&!rl&&r
0133
MC/DC33%1/3
defined $self->{"last_ex"} and $self->{"last_ex"} == 0 and $self->{"last_check"} == 1
defined $self->{"last_ex"} $self->{"last_ex"} == 0 $self->{"last_check"} == 1
Truth table50%2/4
A and B and C
A= defined $self->{"last_ex"}B= $self->{"last_ex"} == 0C= $self->{"last_check"} == 1
ABCresult
0XX0
10X0
1100
1111
529 && ($self->{last_ex} == 0)
530 && ($self->{last_check} == 1)) {
531 3 return 1;
532 }
533 elsif ($self->{attempt} == 2) {
534 4 return $self->{last_check};
535 }
536 }
537 else {
538 10 return $self->{last_check};
539 }
540  
541 9 return;
542 }
543  
544 sub _get_rules {
545 35 ▶ my ($sc) = @_;
Subroutine _get_rules: called CC=6 SCAR=18.2
546  
547 35 ▶ return unless (defined($sc) && ($sc =~ /^\d+$/));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sc and $sc =~ /^\d+$/ 0 35 35
Condition33%1/3
defined $sc and $sc =~ /^\d+$/
!ll&&!rl&&r
0035
MC/DC0%0/2
defined $sc and $sc =~ /^\d+$/
defined $sc $sc =~ /^\d+$/
Truth table33%1/3
A and B
A= defined $scB= $sc =~ /^\d+$/
ABresult
0X0
100
111
548  
549 35 my $rules;
550 35 foreach (@{BankAccount::Validator::UK::Rule::get_rules()}) {
551 39550 ▶ push @{$rules}, $_ if ($sc >= $_->{start} && $sc <= $_->{end});
Branch: 1 branch
BranchTrueFalseTotal
if $sc >= $_->{"start"} and $sc <= $_->{"end"} 60 39490 39550
Condition100%3/3
$sc >= $_->{"start"} and $sc <= $_->{"end"}
!ll&&!rl&&r
178282166260
MC/DC100%2/2
$sc >= $_->{"start"} and $sc <= $_->{"end"}
$sc >= $_->{"start"} $sc <= $_->{"end"}
Truth table100%3/3
A and B
A= $sc >= $_->{"start"}B= $sc <= $_->{"end"}
ABresult
0X0
100
111
552 }
553  
554 35 return $rules;
555 }
556  
557 sub _dbal_total {
558 112 ▶ my ($_total) = @_;
Subroutine _dbal_total: called CC=2 SCAR=6.9
559  
560 112 ▶ if ($_total > 9) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_total > 9) { } 33 79 112
561 33 my ($left, $right) = split //, $_total;
562 33 return ($left + $right);
563 }
564 else {
565 79 return $_total;
566 }
567 }
568  
569 sub _prepare {
570 39 ▶ my ($sc, $an) = @_;
Subroutine _prepare: called CC=8 SCAR=27.7
571  
572 39 $sc =~ s/[\-\s]+//g;
573 39 $an =~ s/\s+//g;
574  
575 39 ▶ die("ERROR: Invalid bank sort code [$sc].\n") unless ($sc =~ /^\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $sc =~ /^\d+$/ 1 38 39
576 38 ▶ die("ERROR: Invalid bank account number [$an].\n") unless ($an =~ /^\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $an =~ /^\d+$/ 1 37 38
577  
578 37 ▶ if (length($an) == 10) {
Branch: 4 branches
BranchTrueFalseTotal
if (length $an == 10) { } 0 37 37
elsif (length $an == 9) { } 0 37 37
elsif (length $an == 7) { } 0 37 37
elsif (length $an == 6) { } 0 37 37
579 0 ▶ if ($an =~ /^(\d+)\-(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($an =~ /^(\d+)\-(\d+)/) { } 0 0 0
580 0 $an = $2;
581 }
582 else {
583 0 $an = substr($an, 0, 8);
584 }
585 }
586 elsif (length($an) == 9) {
587 0 my $_a = substr($an, 0, 1);
588 0 $an = substr($an, 1, 8);
589 0 $sc = substr($sc, 0, 5);
590 0 $sc .= $_a;
591 }
592 elsif (length($an) == 7) {
593 0 $an = '0'.$an;
594 }
595 elsif (length($an) == 6) {
596 0 $an = '00'.$an;
597 }
598  
599 37 return ($sc, $an);
600 }
601  
602 =head1 AUTHOR
603  
604 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
605  
606 =head1 REPOSITORY
607  
608 L<https://github.com/manwar/BankAccount-Validator-UK>
609  
610 =head1 BUGS
611  
612 Please report any bugs or feature requests to C<bug-bankaccount-validator-uk at
613 rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=BankAccount-Validator-UK>.
614 I will be notified, and then you'll automatically be notified of progress on your
615 bug as I make changes.
616  
617 =head1 SUPPORT
618  
619 You can find documentation for this module with the perldoc command.
620  
621 perldoc BankAccount::Validator::UK
622  
623 You can also look for information at:
624  
625 =over 4
626  
627 =item * RT: CPAN's request tracker (report bugs here)
628  
629 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=BankAccount-Validator-UK>
630  
631 =item * CPAN Ratings
632  
633 L<http://cpanratings.perl.org/d/BankAccount-Validator-UK>
634  
635 =item * MetaCPAN
636  
637 L<https://metacpan.org/dist/BankAccount-Validator-UK>
638  
639 =back
640  
641 =head1 LICENSE AND COPYRIGHT
642  
643 Copyright (C) 2012 - 2021 Mohammad S Anwar.
644  
645 This program is free software; you can redistribute it and / or modify it under
646 the terms of the the Artistic License (2.0). You may obtain a copy of the full
647 license at:
648  
649 L<http://www.perlfoundation.org/artistic_license_2_0>
650  
651 Any use, modification, and distribution of the Standard or Modified Versions is
652 governed by this Artistic License.By using, modifying or distributing the Package,
653 you accept this license. Do not use, modify, or distribute the Package, if you do
654 not accept this license.
655  
656 If your Modified Version has been derived from a Modified Version made by someone
657 other than you,you are nevertheless required to ensure that your Modified Version
658 complies with the requirements of this license.
659  
660 This license does not grant you the right to use any trademark, service mark,
661 tradename, or logo of the Copyright Holder.
662  
663 This license includes the non-exclusive, worldwide, free-of-charge patent license
664 to make, have made, use, offer to sell, sell, import and otherwise transfer the
665 Package with respect to any patent claims licensable by the Copyright Holder that
666 are necessarily infringed by the Package. If you institute patent litigation
667 (including a cross-claim or counterclaim) against any party alleging that the
668 Package constitutes direct or contributory patent infringement,then this Artistic
669 License to you shall terminate on the date that such litigation is filed.
670  
671 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
672 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
673 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
674 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
675 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
676 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
677 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
678  
679 =cut
680  
681 3 1; # End of BankAccount::Validator::UK
↑ Summary UK/Rule.pm »