blib/lib/Algorithm/CheckDigits.pm

filter: Statementstmt 69.7% 46 / 66 Branchbran 35.0% 7 / 20 Conditioncond 50.0% 4 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 61.5% 8 / 13 Podpod 100% 5 / 5 totaltotal 60.3% 70 / 116 CC 17 SCAR 22.5
CC
17
Cov
61%
method_descriptions
30.0
method_list
12.0
plug_in
7.1
CRAP 9.5
« blib/script/checkdigits.pl ↑ Summary blib/lib/Algorithm/CheckDigits/MXX_001.pm »
1 # vim: ts=4 sw=4 tw=78 et si:
2 package Algorithm::CheckDigits;
3  
4 21 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 21 ▶use vars qw($AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 21 require Exporter;
11  
12 21 our @ISA = qw(Exporter);
13  
14 # Items to export into callers namespace by default. Note: do not export
15 # names by default without a very good reason. Use EXPORT_OK instead.
16 # Do not simply export all your public functions/methods/constants.
17  
18 # This allows declaration use CheckDigits ':all';
19 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
20 # will save memory.
21 21 our %EXPORT_TAGS = (
22 'all' => [
23 qw(
24 CheckDigits method_descriptions method_list print_methods
25 ) ] );
26  
27 21 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
28  
29 21 our @EXPORT = qw( CheckDigits );
30  
31 21 ▶use version; our $VERSION = qv('v1.3.6');
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 21 my %methods = (
34 'upc' => [ 'Algorithm::CheckDigits::MBase_001',
35 'Universal Product Code, UPC (US, CA)' ],
36 'blutbeutel' => [ 'Algorithm::CheckDigits::MBase_002',
37 'Eurocode, blood bags' ],
38 'bzue_de' => [ 'Algorithm::CheckDigits::MBase_002',
39 'Beleglose Zahlscheinüberweisung, BZÜ (DE)' ],
40 'ustid_de' => [ 'Algorithm::CheckDigits::MBase_002',
41 'Umsatzsteuer-Identifikationsnummer (DE)' ],
42 'sici' => [ 'Algorithm::CheckDigits::MBase_003',
43 'Value Added Tax number, VAT (DE)' ],
44 'euronote' => [ 'Algorithm::CheckDigits::M09_001',
45 'Euro bank notes, EUR' ],
46 'amex' => [ 'Algorithm::CheckDigits::M10_001',
47 'American Express credit cards' ],
48 'bahncard' => [ 'Algorithm::CheckDigits::M10_001',
49 'DB Bahncard (DE)' ],
50 'cusip' => [ 'Algorithm::CheckDigits::M10_001',
51 'Committee on Uniform Security Identification Procedures, CUSIP (US)' ],
52 'diners' => [ 'Algorithm::CheckDigits::M10_001',
53 q(Diner's club credit cards) ],
54 'discover' => [ 'Algorithm::CheckDigits::M10_001',
55 'Discover credit cards' ],
56 'enroute' => [ 'Algorithm::CheckDigits::M10_001',
57 'EnRoute credit cards' ],
58 'eurocard' => [ 'Algorithm::CheckDigits::M10_001',
59 'Eurocard credit cards' ],
60 'happydigits' => [ 'Algorithm::CheckDigits::M10_001',
61 'Happy Digits (DE)' ],
62 'jcb' => [ 'Algorithm::CheckDigits::M10_001',
63 'JCB credit cards' ],
64 'klubkarstadt' => [ 'Algorithm::CheckDigits::M10_001',
65 'Klub Karstadt (DE)' ],
66 'mastercard' => [ 'Algorithm::CheckDigits::M10_001',
67 'Mastercard credit cards' ],
68 'miles&more' => [ 'Algorithm::CheckDigits::M10_001',
69 'Miles & More, Lufthansa (DE)' ],
70 'visa' => [ 'Algorithm::CheckDigits::M10_001',
71 'VISA credit cards' ],
72 'isin' => [ 'Algorithm::CheckDigits::M10_001',
73 'International Securities Identifikation Number, ISIN' ],
74 'imei' => [ 'Algorithm::CheckDigits::M10_001',
75 'International Mobile Station Equipment Identity, IMEI' ],
76 'imeisv' => [ 'Algorithm::CheckDigits::M10_001',
77 'International Mobile Station Equipment Identity and Software Version Number' ],
78 'siren' => [ 'Algorithm::CheckDigits::M10_002',
79 'SIREN (FR)' ],
80 'siret' => [ 'Algorithm::CheckDigits::M10_002',
81 'SIRET (FR)' ],
82 'ismn' => [ 'Algorithm::CheckDigits::M10_003',
83 'International Standard Music Number, ISMN' ],
84 'ean' => [ 'Algorithm::CheckDigits::M10_004',
85 'European Article Number, EAN' ],
86 'iln' => [ 'Algorithm::CheckDigits::M10_004',
87 'Global Location Number, GLN' ],
88 'nve' => [ 'Algorithm::CheckDigits::M10_004',
89 'Nummer der Versandeinheit, NVE, SSCC' ],
90 '2aus5' => [ 'Algorithm::CheckDigits::M10_004',
91 '2 aus 5, 2 of 5, 2/5' ],
92 'isbn13' => [ 'Algorithm::CheckDigits::M10_004',
93 'International Standard Book Number, ISBN13' ],
94 'identcode_dp' => [ 'Algorithm::CheckDigits::M10_005',
95 'Identcode Deutsche Post AG (DE)' ],
96 'leitcode_dp' => [ 'Algorithm::CheckDigits::M10_005',
97 'Leitcode Deutsche Post AG (DE)' ],
98 'rentenversicherung' => [ 'Algorithm::CheckDigits::M10_006',
99 'Rentenversicherungsnummer, VSNR (DE)' ],
100 'sedol' => [ 'Algorithm::CheckDigits::M10_008',
101 'Stock Exchange Daily Official List, SEDOL (GB)' ],
102 'betriebsnummer' => [ 'Algorithm::CheckDigits::M10_009',
103 'Betriebsnummer (DE)' ],
104 'postcheckkonti' => [ 'Algorithm::CheckDigits::M10_010',
105 'Postscheckkonti (CH)' ],
106 'ups' => [ 'Algorithm::CheckDigits::M10_011',
107 'United Parcel Service, UPS' ],
108 'isbn' => [ 'Algorithm::CheckDigits::M11_001',
109 'International Standard Book Number, ISBN10' ],
110 'issn' => [ 'Algorithm::CheckDigits::M11_001',
111 'International Standard Serial Number, ISSN' ],
112 'ustid_pt' => [ 'Algorithm::CheckDigits::M11_001',
113 'Umsatzsteuer-Identifikationsnummer (PT)' ],
114 'vatrn_pt' => [ 'Algorithm::CheckDigits::M11_001',
115 'Value Added Tax number, VAT (PT)' ],
116 'hkid' => [ 'Algorithm::CheckDigits::M11_001',
117 'Hong Kong Identity Card, HKID (HK)' ],
118 'wagonnr_br' => [ 'Algorithm::CheckDigits::M11_001',
119 'Codificação dos vagões (BR)' ],
120 'nhs_gb' => [ 'Algorithm::CheckDigits::M11_001',
121 'National Health Service, NHS (GB)' ],
122 'vat_sl' => [ 'Algorithm::CheckDigits::M11_001',
123 'Value Added Tax number, VAT (SL)' ],
124 'pzn' => [ 'Algorithm::CheckDigits::M11_002',
125 'Pharmazentralnummer (DE)' ],
126 'pkz' => [ 'Algorithm::CheckDigits::M11_003',
127 'Personenkennzahl der DDR' ],
128 'cpf' => [ 'Algorithm::CheckDigits::M11_004',
129 'Cadastro de Pessoas Físicas, CPF (BR)' ],
130 'titulo_eleitor' => [ 'Algorithm::CheckDigits::M11_004',
131 'Título Eleitoral (BR)' ],
132 'ccc_es' => [ 'Algorithm::CheckDigits::M11_006',
133 'Código de Cuenta Corriente, CCC (ES)' ],
134 'ustid_fi' => [ 'Algorithm::CheckDigits::M11_007',
135 'Umsatzsteuer-Identifikationsnummer (FI)' ],
136 'vatrn_fi' => [ 'Algorithm::CheckDigits::M11_007',
137 'Value Added Tax number, VAT (FI)' ],
138 'ustid_dk' => [ 'Algorithm::CheckDigits::M11_008',
139 'Umsatzsteuer-Identifikationsnummer (DK)' ],
140 'vatrn_dk' => [ 'Algorithm::CheckDigits::M11_008',
141 'Value Added Tax number, VAT (DK)' ],
142 'nric_sg' => [ 'Algorithm::CheckDigits::M11_009',
143 'National Registration Identity Card, NRIC (SG)' ],
144 'ahv_ch' => [ 'Algorithm::CheckDigits::M11_010',
145 'Alters- und Hinterlassenenversicherungsnummer, AHV (CH)' ],
146 'ustid_nl' => [ 'Algorithm::CheckDigits::M11_011',
147 'Umsatzsteuer-Identifikationsnummer (NL)' ],
148 'vatrn_nl' => [ 'Algorithm::CheckDigits::M11_011',
149 'Value Added Tax number, VAT (NL)' ],
150 'bwpk_de' => [ 'Algorithm::CheckDigits::M11_012',
151 'Personenkennummer der Bundeswehr (DE)' ],
152 'ustid_gr' => [ 'Algorithm::CheckDigits::M11_013',
153 'Umsatzsteuer-Identifikationsnummer (GR)' ],
154 'vatrn_gr' => [ 'Algorithm::CheckDigits::M11_013',
155 'Value Added Tax number, VAT (GR)' ],
156 'esr5_ch' => [ 'Algorithm::CheckDigits::M11_015',
157 'Einzahlungsschein mit Referenz, ESR5 (CH)' ],
158 'ustid_pl' => [ 'Algorithm::CheckDigits::M11_016',
159 'Umsatzsteuer-Identifikationsnummer (PL)' ],
160 'vatrn_pl' => [ 'Algorithm::CheckDigits::M11_016',
161 'Value Added Tax number, VAT (PL)' ],
162 'nip' => [ 'Algorithm::CheckDigits::M11_016',
163 'numer identyfikacji podatkowej, NIP' ],
164 'ecno' => [ 'Algorithm::CheckDigits::M11_017',
165 'European Commission number, EC-No (for chemicals)' ],
166 'einecs' => [ 'Algorithm::CheckDigits::M11_017',
167 'European Inventory of Existing Commercial Chemical Substances, EINECS' ],
168 'elincs' => [ 'Algorithm::CheckDigits::M11_017',
169 'European List of Notified Chemical Substances, ELINCS' ],
170 'isan' => [ 'Algorithm::CheckDigits::M16_001',
171 'International Standard Audiovisual Number, ISAN' ],
172 'dni_es' => [ 'Algorithm::CheckDigits::M23_001',
173 'Documento nacional de identidad (ES)' ],
174 'ustid_ie' => [ 'Algorithm::CheckDigits::M23_002',
175 'Umsatzsteuer-Identifikationsnummer (IE)' ],
176 'vatrn_ie' => [ 'Algorithm::CheckDigits::M23_002',
177 'Value Added Tax number, VAT (IE)' ],
178 'tin_ie' => [ 'Algorithm::CheckDigits::M23_002',
179 'Tax Identification Number (IE)' ],
180 'code_39' => [ 'Algorithm::CheckDigits::M43_001',
181 'Code39, 3 of 9' ],
182 'ustid_lu' => [ 'Algorithm::CheckDigits::M89_001',
183 'Umsatzsteuer-Identifikationsnummer (LU)' ],
184 'vatrn_lu' => [ 'Algorithm::CheckDigits::M89_001',
185 'Value Added Tax number, VAT (LU)' ],
186 'ustid_be' => [ 'Algorithm::CheckDigits::M97_001',
187 'Umsatzsteuer-Identifikationsnummer (BE)' ],
188 'vatrn_be' => [ 'Algorithm::CheckDigits::M97_001',
189 'Value Added Tax number, VAT (BE)' ],
190 'iban' => [ 'Algorithm::CheckDigits::M97_002',
191 'International Bank Account Number (IBAN)' ],
192 'pa_de' => [ 'Algorithm::CheckDigits::MXX_001',
193 'Personalausweis (DE)' ],
194 'aba_rn' => [ 'Algorithm::CheckDigits::MXX_001',
195 'American Bankers Association routing number (ABA RN)' ],
196 'cas' => [ 'Algorithm::CheckDigits::MXX_002',
197 'Chemical abstract service, CAS' ],
198 'dem' => [ 'Algorithm::CheckDigits::MXX_003',
199 'Deutsche Mark Banknoten, DEM' ],
200 'ustid_at' => [ 'Algorithm::CheckDigits::MXX_004',
201 'Umsatzsteuer-Identifikationsnummer (AT)' ],
202 'vatrn_at' => [ 'Algorithm::CheckDigits::MXX_004',
203 'Value Added Tax number, VAT (AT)' ],
204 'esr9_ch' => [ 'Algorithm::CheckDigits::MXX_005',
205 'Einzahlungsschein mit Referenz, ESR9 (CH)' ],
206 'verhoeff' => [ 'Algorithm::CheckDigits::MXX_006',
207 'Verhoeff scheme' ],
208 );
209  
210 113 ▶sub CheckDigits {
Subroutine CheckDigits: called CC=3 SCAR=11.4
Pod documented
211 113 ▶ my $method = shift || '';
Condition50%1/2
shift() || ''
l!l
1130
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
212  
213 113 ▶ if ( my $pkg = $methods{ lc($method) } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pkg = $methods{lc $method}) { } 113 0 113
214 113 my $module = $pkg->[0];
215 113 my $file = $pkg->[0];
216 113 $file =~ s{::}{/}g;
217 113 require "$file.pm";
218 113 return new $module($method);
219 }
220 else {
221 0 die "Don't know checkdigit algorithm for '$method'!";
222 }
223 } # CheckDigits()
224  
225 0 ▶sub method_list {
Subroutine method_list: not called CC=3 SCAR=24.8
Pod documented
226 0 my @methods = ();
227 0 foreach my $method ( sort keys %methods ) {
228 0 push @methods, $method;
229 }
230 0 ▶ return wantarray ? @methods : \@methods;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
231 } # method_list()
232  
233 0 ▶sub method_descriptions {
Subroutine method_descriptions: not called CC=5 SCAR=34.0
Pod documented
234 0 my @meths = @_;
235 0 ▶ if ($meths[0] eq 'Algorithm::CheckDigits') {
Branch: 1 branch
BranchTrueFalseTotal
if ($meths[0] eq "Algorithm::CheckDigits") 0 0 0
236 # it was called Algorithm::CheckDigits->method_descriptions
237 0 shift @meths;
238 }
239 0 ▶ if (0 == scalar @meths) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 == scalar @meths) 0 0 0
240 0 @meths = keys %methods;
241 }
242 0 ▶ my %descr = map { $_ => ($methods{$_}) ? $methods{$_}->[1]
Branch: 1 branch
BranchTrueFalseTotal
$methods{$_} ? : 0 0 0
243 : 'unknown' } @meths;
244 0 ▶ return wantarray ? %descr : \%descr;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
245 } # method_descriptions()
246  
247 9 ▶sub plug_in {
Subroutine plug_in: called CC=7 SCAR=19.6
Pod documented
248 9 ▶ if ('Algorithm::CheckDigits' eq $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Algorithm::CheckDigits" eq $_[0]) 3 6 9
249 3 shift;
250 }
251 9 ▶ my $module = shift ||
Condition50%1/2
shift() || die(q[you need to specify a module except 'Algorithm::CheckDigits'])
l!l
90
MC/DC0%0/1
shift() || die(q[you need to specify a module except 'Algorithm::CheckDigits'])
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
252 die "you need to specify a module except 'Algorithm::CheckDigits'";
253 9 ▶ my $descr = shift || "algorithm of module $module";
Condition50%1/2
shift() || "algorithm of module $module"
l!l
90
MC/DC0%0/1
shift() || "algorithm of module $module"
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
254 9 ▶ my $key = lc shift || 'plalg';
Condition50%1/2
lc shift() || 'plalg'
l!l
90
MC/DC0%0/1
lc shift() || 'plalg'
lc shift()
Truth table50%1/2
A
A= lc shift()
Aresult
11
00
255 9 ▶ if (exists $methods{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $methods{$key}) 2 7 9
256 2 $key .= ',1';
257 }
258 9 ▶ while (exists $methods{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $methods{$key}) 1 9 10
259 1 $key =~ s/(\d+)$/my $y = $1; ++$y/e;
260 }
261 9 $methods{$key} = [ $module, $descr ];
262 9 return $key;
263 } # plug_in()
264  
265 0 ▶sub print_methods {
Subroutine print_methods: not called CC=2 SCAR=17.9
Pod documented
266 0 foreach my $method ( sort keys %methods ) {
267 0 print "$method => $methods{$method}\n";
268 }
269 } # print_methods()
270  
271 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=2 SCAR=17.9
272 0 my $self = shift;
273 0 my $attr = $AUTOLOAD;
274 0 ▶ unless ( $attr =~ /^Algorithm::CheckDigits::[A-Za-z_0-9]*$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attr =~ /^Algorithm::CheckDigits::[A-Za-z_0-9]*$/) 0 0 0
275 0 croak "$attr is not defined";
276 }
277 0 return '';
278 } # AUTOLOAD()
279  
280 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
281 }
282  
283 # Preloaded methods go here.
284  
285 21 1;
286 __END__
« blib/script/checkdigits.pl ↑ Summary blib/lib/Algorithm/CheckDigits/MXX_001.pm »