File Coverage

blib/lib/String/LRC.pm
Criterion Covered Total %
statement 11 11 100.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 2 2 100.0
pod 0 1 0.0
total 15 19 78.9


line stmt bran cond sub pod time code
1             ############################################################
2             #
3             # Perl Extension for LRC computations
4             # Author...: Ralph Padron (whoelse@elitedigital.net)
5             # Revised..: 01-May-2002
6             #
7             # The Longitudinal Redundancy Check (LRC) is a one byte character,
8             # commonly used as a field in data transmission over analog systems.
9             #
10             # Most commonly, in STX-ETX bounded strings sent in financial protocols.
11             #
12             # Following some previous experience with such protocols, I wrote
13             # an LRC function in perl and later decided to re-write in C
14             # for efficiency. The result is this module String::LRC
15             #
16             # NOTE:
17             # Included sv_type comparison and lrcinit in v1.01
18             # following the idea by Soenke J. Peters and others
19             # that someone perhaps can use the LRC of a file.
20             #
21             #
22             ############################################################
23              
24             package String::LRC;
25              
26             require Exporter;
27             require DynaLoader;
28              
29             @String::LRC::ISA = qw(Exporter DynaLoader);
30             $String::LRC::VERSION = 1.01;
31             @String::LRC::EXPORT = qw(lrc); # Export lrc() by default
32             # Export the default and the old LRC function I had as a simple perl subroutine
33             # from v1.00 of this package
34             @String::LRC::EXPORT_OK = qw(lrc getPerlLRC);
35              
36             sub getPerlLRC
37             {
38 4     4 0 38 my $buffer = shift(@_);
39 4         17 my @str = split(//,$buffer);
40 4         7 my $len = 0;
41 4 50 33     17 $len = length($buffer) if (defined $buffer && $buffer ne "");
42 1     1   683 no warnings; # for XOR on non-numeric (sometimes shows for me)
  1         2  
  1         111  
43 4         4 my $check;
44 4         10 for (my $i = 0; $i < $len ; $i++) {
45 35         64 $check = $check ^ $str[$i];
46             }
47 4         12 return $check;
48             }
49              
50             bootstrap String::LRC;
51              
52              
53             1;