DataMatrix/Reed.pm

filter: Statementstmt 100% 29 / 29 Branchbran 58.3% 7 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 3 / 3 totaltotal 90.0% 45 / 50 CC 10 SCAR 18.4
CC
10
Cov
88%
encode
9.6
mult
2.0
BEGIN
1.0
CRAP 6.3
« DataMatrix/CharDataFiller.pm ↑ Summary DataMatrix.pm »
1 package Barcode::DataMatrix::Reed;
2  
3 =head1 Barcode::DataMatrix::Reed
4  
5 This is just a renamed version of Algorithm::DataMatrix::Reed
6 by Mons Anderson
7 from http://code.google.com/p/perl-ex/
8  
9 For a rough explanation of the structure of this code, see
10 L<https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders#Reed.E2.80.93Solomon_codes>.
11 Note that the link is not the basis of the implementation (this is unknown),
12 however it helps explain how Reed-Solomon encoding is implemented and hence
13 how the code below works.
14  
15 =cut
16  
17 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 =head2 DEBUG
22  
23 Control whether or not debugging output is printed.
24  
25 =cut
26  
27 48 ▶sub DEBUG { 0 }
Subroutine DEBUG: called CC=1 SCAR=0.0
Pod documented
28  
29 =head2 mult (x, y)
30  
31 Multiply two Galois field element values and return the result.
32  
33 =cut
34  
35 sub mult {
36 57966 ▶ my ($x, $y) = @_;
Subroutine mult: called CC=2 SCAR=6.9
Pod documented
37 57966 ▶ return 0 unless $x * $y;
Branch: 1 branch
BranchTrueFalseTotal
unless $x * $y 252 57714 57966
38 57714 return $Barcode::DataMatrix::Constants::GFI[($Barcode::DataMatrix::Constants::GFL[$x] + $Barcode::DataMatrix::Constants::GFL[$y]) % 255];
39 }
40  
41 =head2 encode (ai, j)
42  
43 Encode the message array and return it.
44  
45 =cut
46  
47 sub encode {
48 16 ▶ my ($ai,$j) = @_;
Subroutine encode: called CC=9 SCAR=22.7
Pod documented
49 16 my $i = @$ai;
50 16 for (0..$#$ai) {
51 1226 ▶ ( $ai->[$_] & 0xFF ) != $ai->[$_] and warn("number $ai->[$_] at index $_ is not a byte size"), $ai->[$_] = $ai->[$_] & 0xFF;
Branch: 1 branch
BranchTrueFalseTotal
($ai->[$_] & 255) != $ai->[$_] and warn("number $ai->[$_] at index $_ is not a byte size"), $ai->[$_] = $ai->[$_] & 255 0 1226 1226
52 }
53 16 ▶ warn "CalcReed: ai [@$ai], $j\n" if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if DEBUG() 0 16 16
54  
55 16 ▶ my $p = exists $Barcode::DataMatrix::Constants::POLY{$j} ? $Barcode::DataMatrix::Constants::POLY{$j} : $Barcode::DataMatrix::Constants::POLY{68};
Branch: 1 branch
BranchTrueFalseTotal
exists $Barcode::DataMatrix::Constants::POLY{$j} ? : 16 0 16
56 16 ▶ warn "CalcReed: poly [@$p]\n" if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if DEBUG() 0 16 16
57  
58 16 @$ai[ $i .. $i + $j - 1 ] = (0) x $j;
59 16 for my $l(0 .. $i - 1) {
60 1226 my $word0 = ($ai->[$i] ^ $ai->[$l]);
61 1226 for my $i1 (0 .. $j - 2) {
62 56740 $ai->[$i + $i1] = ( $ai->[$i + $i1 + 1] ^ mult($word0, $p->[$i1]) );
63 }
64 1226 $ai->[$i+$j-1] = mult($word0, $p->[$j - 1]);
65 }
66 16 ▶ warn "CalcReed: result [@$ai]\n" if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if DEBUG() 0 16 16
67 16 return $ai;
68 }
69  
70 2 1;
« DataMatrix/CharDataFiller.pm ↑ Summary DataMatrix.pm »