| 1 | package Acrux::Digest::M11R; | ||||||||||||||||||||||||||||
| 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::M11R - interface for modulus 11 (recursive) check digit calculation | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | use Acrux::Digest::M11R; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | my $m11r = Acrux::Digest::M11R->new(); | ||||||||||||||||||||||||||||
| 16 | my $digest = $m11r->digest( "123456789" ); # 5 | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | This is Digest backend module that provides calculate the modulus 11 (recursive) check digit | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 METHODS | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | This class inherits all methods from L<Acrux::Digest> and implements the following new ones | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head2 digest | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | my $digest = $m11r->digest( "123456789" ); # 5 | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | Returns M11R checkdigit by specified digits-string | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 HISTORY | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | See C<Changes> file | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head1 TO DO | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | See C<TODO> file | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | L<Acrux::Digest>, L<Algorithm::CheckDigits::M11_015>, B<check_okpo()> | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Copyright (C) 1998-2026 D&D Corporation | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | This program is distributed under the terms of the Artistic License Version 2.0 | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | See the C<LICENSE> file or L<https://opensource.org/license/artistic-2-0> for details | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | ▶ | use parent qw/Acrux::Digest/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 3 | ▶ | sub digest { | ||||||||||||||||||||||||||
|
Subroutine
digest: called CC=8 SCAR=21.1
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | # See also: Algorithm::CheckDigits::M11_015 and check_okpo() | ||||||||||||||||||||||||||||
| 66 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 67 | 3 | my $data = shift; | |||||||||||||||||||||||||||
| 68 | 3 | ▶ | $self->data($data) if defined $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 3 | my $test = $self->data; | |||||||||||||||||||||||||||
| 70 | 3 | ▶ | croak "Incorrect input digit-string" if !defined($test) || $test =~ m/[^0-9]/g; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $test or $test =~ /[^0-9]/g
MC/DC0%0/2
not defined $test or $test =~ /[^0-9]/g
not defined $test
$test =~ /[^0-9]/g
Truth table33%1/3
not(A) or B
A= not defined $testB= $test =~ /[^0-9]/g
| |||||||||||||||||||||||||||||
| 71 | 3 | my $len = length($test); | |||||||||||||||||||||||||||
| 72 | 3 | ▶ | my $iters = ($len + (($len & 1) ? 1 : 0)) / 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 3 | my @digits = split(//, $test); # Get all digits from input string of chars | |||||||||||||||||||||||||||
| 74 | #printf "Test=%s; len=%d; iters=%d\n", $test, $len, $iters; | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 3 | my $w_lim = 10; # Maximum for round-robin(10) weight list: 1,2,3,4,5,6,7,8,9,10,1,2,3,4,5... | |||||||||||||||||||||||||||
| 77 | 3 | my $step = 2; # Step for weight list offset calculation for next iteration | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Calculation sum for one weight list by ofset | ||||||||||||||||||||||||||||
| 80 | 5 | ▶ | my $calc = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 81 | 5 | ▶ | my $off = shift || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 0
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 82 | 5 | my $s = 0; | |||||||||||||||||||||||||||
| 83 | 5 | ▶ | for (my $i = 0; $i < $len; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 37 | my $w = (($i + $off) % $w_lim) + 1; | |||||||||||||||||||||||||||
| 85 | 37 | $s += ($w * $digits[$i]); | |||||||||||||||||||||||||||
| 86 | #printf " > i=%d; d=%d; w=%d; sum=%d\n", $i, $digits[$i], $w, $s; | ||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 5 | return $s % 11; | |||||||||||||||||||||||||||
| 89 | 3 | }; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # Main cycle | ||||||||||||||||||||||||||||
| 92 | 3 | my $sum = 0; | |||||||||||||||||||||||||||
| 93 | 3 | ▶ | for (my $j = 0; $j < $iters; $j++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 5 | my $offset = $j*$step; | |||||||||||||||||||||||||||
| 95 | 5 | $sum = $calc->($offset); | |||||||||||||||||||||||||||
| 96 | #printf " >> j=%d; offset=%d; sum=%d\n", $j, $offset, $sum; | ||||||||||||||||||||||||||||
| 97 | 5 | ▶ | last if $sum < 10; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 3 | ▶ | $sum = 0 if $sum >= 10; # 0 if incorrect again | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | #printf " >>> sum=%d\n", $sum; | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 3 | return $sum; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 1 | 1; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||||||||||