Acrux/Digest/Damm.pm

filter: Statementstmt 100% 27 / 27 Branchbran 75.0% 3 / 4 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 93.3% 42 / 45 CC 5 SCAR 10.4
CC
5
Cov
94%
digest
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.8
« Acrux/Digest/M11R.pm ↑ Summary Acrux/Const.pm »
1 package Acrux::Digest::Damm;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 =encoding utf-8
6  
7 =head1 NAME
8  
9 Acrux::Digest::Damm - interface for Damm check digit calculation
10  
11 =head1 SYNOPSIS
12  
13 use Acrux::Digest::Damm;
14  
15 my $damm = Acrux::Digest::Damm->new();
16 my $d = $damm->checkdigit( "123456789" ); # 4
17 $damm->checkdigit( "123456789$d" ); # 0 - correct
18  
19 =head1 DESCRIPTION
20  
21 This is a Digest backend module that provides calculation
22 of the Damm check digit
23  
24 =head1 METHODS
25  
26 This class inherits all methods from L<Acrux::Digest> and implements the following new ones
27  
28 =head2 checkdigit
29  
30 See L</digest>
31  
32 =head2 digest
33  
34 my $damm = Acrux::Digest::Damm->new();
35 my $digest = $damm->digest( "123456789" ); # 4
36 $damm->digest( "123456789$digest" ); # 0 - correct
37 my $digest = $damm->digest( "987654321" ); # 5
38 $damm->digest( "987654321$digest" ); # 0 - correct
39  
40 Returns Damm checkdigit by specified digits-string
41  
42 See also L<https://en.wikipedia.org/wiki/Damm_algorithm>
43  
44 =head1 HISTORY
45  
46 See C<Changes> file
47  
48 =head1 TO DO
49  
50 See C<TODO> file
51  
52 =head1 SEE ALSO
53  
54 L<Acrux::Digest>, L<https://en.wikipedia.org/wiki/Damm_algorithm>
55  
56 =head1 AUTHOR
57  
58 Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt>
59  
60 =head1 COPYRIGHT
61  
62 Copyright (C) 1998-2026 D&D Corporation
63  
64 =head1 LICENSE
65  
66 This program is distributed under the terms of the Artistic License Version 2.0
67  
68 See the C<LICENSE> file or L<https://opensource.org/license/artistic-2-0> for details
69  
70 =cut
71  
72 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 1 ▶use parent qw/Acrux::Digest/;
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 1 ▶use constant DAMM_MAP => [
Subroutine BEGIN: called CC=1 SCAR=0.0
77 [0,3,1,7,5,9,8,6,4,2],
78 [7,0,9,2,1,5,4,8,6,3],
79 [4,2,0,6,8,7,1,3,5,9],
80 [1,7,5,0,9,8,3,4,2,6],
81 [6,1,2,3,0,4,5,9,7,8],
82 [3,6,7,4,2,0,9,5,8,1],
83 [5,8,6,9,7,2,0,1,3,4],
84 [8,9,4,5,3,6,2,0,1,7],
85 [9,4,3,8,6,1,7,2,0,5],
86 [2,5,8,1,4,3,6,7,9,0],
87 1 ];
88  
89 7 ▶sub digest {
Subroutine digest: called CC=5 SCAR=16.2
Pod documented
90 7 my $self = shift;
91 7 my $data = shift;
92 7 ▶ $self->data($data) if defined $data;
Branch: 1 branch
BranchTrueFalseTotal
if defined $data 0 7 7
93 7 my $test = $self->data;
94 7 ▶ croak "Incorrect input digit-string" if !defined($test) || $test =~ m/[^0-9]/g;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $test or $test =~ /[^0-9]/g 1 6 7
Condition66%2/3
not defined $test or $test =~ /[^0-9]/g
l!l&&r!l&&!r
016
MC/DC50%1/2
not defined $test or $test =~ /[^0-9]/g
not defined $test $test =~ /[^0-9]/g
Truth table66%2/3
not(A) or B
A= not defined $testB= $test =~ /[^0-9]/g
ABresult
1X1
011
000
95  
96 6 my @digits = split(//, $test); # Get all digits from input string of chars
97 6 my $sum = 0;
98 6 foreach my $d (@digits) {
99 39 $sum = DAMM_MAP->[$sum][$d];
100 }
101  
102 6 return $sum;
103 }
104 7 ▶sub checkdigit { goto &digest }
Subroutine checkdigit: called CC=1 SCAR=0.0
Pod documented
105  
106 1 1;
107  
108 __END__
« Acrux/Digest/M11R.pm ↑ Summary Acrux/Const.pm »