File Coverage

blib/lib/BankAccount/Validator/UK/Rule.pm
Criterion Covered Total %
statement 54 54 100.0
branch 5 6 83.3
condition 1 3 33.3
subroutine 8 8 100.0
pod 2 2 100.0
total 70 73 95.8


line stmt bran cond sub pod time code
1             package BankAccount::Validator::UK::Rule;
2              
3             $BankAccount::Validator::UK::Rule::VERSION = '0.67';
4             $BankAccount::Validator::UK::Rule::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             BankAccount::Validator::UK::Rule - Rules for validating UK bank account.
9              
10             =head1 VERSION
11              
12             Version 0.67
13              
14             =cut
15              
16 3     3   60 use 5.006;
  3         16  
17 3     3   25 use strict; use warnings;
  3     3   8  
  3         116  
  3         19  
  3         7  
  3         184  
18 3     3   1840 use autodie;
  3         65650  
  3         19  
19 3     3   31038 use File::ShareDir ':ALL';
  3         122801  
  3         3665  
20              
21             =head1 DESCRIPTION
22              
23             B
24              
25             =head1 METHODS
26              
27             =head2 get_sort_codes()
28              
29             It is used by the module L internally. It returns the
30             substituting sort code if found, as provided by VOCALINK in the document dated
31             13th June'2005. The document is called scsubtab.txt.
32              
33             =cut
34              
35             sub get_sort_codes {
36              
37 36     36 1 86 my $sort_codes = {};
38 36         236 my $file_name = dist_file('BankAccount-Validator-UK', 'scsubtab.txt');
39              
40 36         9239 open(my $SOURCE, "<", $file_name);
41 36         13398 while (my $row = <$SOURCE>) {
42 756         1390 chomp $row;
43 756         2441 my ($left, $right) = split /\s/, $row, 2;
44 756         1596 $left =~ s/^\s+//g;
45 756         1369 $left =~ s/\s+$//g;
46 756         1385 $right =~ s/^\s+//g;
47 756         1219 $right =~ s/\s+$//g;
48              
49 756 50 33     3396 if (($left =~ /^\d+$/) && ($right =~ /^\d+$/)) {
50 756         3258 $sort_codes->{$left} = $right;
51             }
52             }
53 36         209 close($SOURCE);
54              
55 36         5687 return $sort_codes;
56             }
57              
58             =head2 get_rules()
59              
60             It is used by the module L internally.It returns every
61             possible rules cover by the document, as provided by VOCALINK dated 24th Dec 2021
62             and is called valacdos.txt.
63              
64             =cut
65              
66             sub get_rules {
67              
68 35     35 1 57 my $rules;
69 35         94 foreach (@{_raw_data()}) {
  35         97  
70 40285         181784 my @values = split ' ';
71 40285         67434 my $value_of = {};
72 40285         61827 my $index = 0;
73 40285         75458 foreach my $k (qw(start end mod u v w x y z a b c d e f g h)) {
74 684845         1274801 $values[$index] =~ s/^\s+//g;
75 684845         1162488 $values[$index] =~ s/\s+$//g;
76 684845 100       1148126 if ($index == 2) {
77 40285         117879 $value_of->{$k} = $values[$index];
78             }
79             else {
80 644560         1414382 $value_of->{$k} = $values[$index] + 0;
81             }
82 684845         1113230 $index++;
83             }
84              
85 40285 100       85490 if (!$values[$index]) {
86 18865         36161 $value_of->{'ex'} = 0;
87             }
88             else {
89 21420         45584 $value_of->{'ex'} = $values[$index] + 0;
90             }
91              
92 40285         172736 push @$rules, $value_of;
93             }
94              
95 35         6753 return $rules;
96             }
97              
98             sub _raw_data {
99              
100 35     35   65 my $raw_data = [];
101 35         177 my $file_name = dist_file('BankAccount-Validator-UK', 'valacdos.txt');
102              
103 35         6494 open(my $SOURCE, "<", $file_name);
104 35         4589 while (my $row = <$SOURCE>) {
105 40285         58544 chomp $row;
106 40285         110030 push @$raw_data, $row;
107             }
108 35         216 close($SOURCE);
109              
110 35         3098 return $raw_data;
111             }
112              
113             =head1 AUTHOR
114              
115             Mohammad Sajid Anwar, C<< >>
116              
117             =head1 REPOSITORY
118              
119             L
120              
121             =head1 BUGS
122              
123             Please report any bugs or feature requests through the web interface at L.
124             I will be notified, and then you'll automatically be notified of progress on your
125             bug as I make changes.
126              
127             =head1 SUPPORT
128              
129             You can find documentation for this module with the perldoc command.
130              
131             perldoc BankAccount::Validator::UK::Rule
132              
133             You can also look for information at:
134              
135             =over 4
136              
137             =item * BUG Report
138              
139             L
140              
141             =item * AnnoCPAN: Annotated CPAN documentation
142              
143             L
144              
145             =item * CPAN Ratings
146              
147             L
148              
149             =item * Search MetaCPAN
150              
151             L
152              
153             =back
154              
155             =head1 LICENSE AND COPYRIGHT
156              
157             Copyright (C) 2012 - 2025 Mohammad Sajid Anwar.
158              
159             This program is free software; you can redistribute it and / or modify it under
160             the terms of the the Artistic License (2.0). You may obtain a copy of the full
161             license at:
162              
163             L
164              
165             Any use, modification, and distribution of the Standard or Modified Versions is
166             governed by this Artistic License.By using, modifying or distributing the Package,
167             you accept this license. Do not use, modify, or distribute the Package, if you do
168             not accept this license.
169              
170             If your Modified Version has been derived from a Modified Version made by someone
171             other than you,you are nevertheless required to ensure that your Modified Version
172             complies with the requirements of this license.
173              
174             This license does not grant you the right to use any trademark, service mark,
175             tradename, or logo of the Copyright Holder.
176              
177             This license includes the non-exclusive, worldwide, free-of-charge patent license
178             to make, have made, use, offer to sell, sell, import and otherwise transfer the
179             Package with respect to any patent claims licensable by the Copyright Holder that
180             are necessarily infringed by the Package. If you institute patent litigation
181             (including a cross-claim or counterclaim) against any party alleging that the
182             Package constitutes direct or contributory patent infringement,then this Artistic
183             License to you shall terminate on the date that such litigation is filed.
184              
185             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
186             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
187             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
188             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
189             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
190             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
191             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
192              
193             =cut
194              
195             1; # End of BankAccount::Validator::UK::Rule