blib/lib/Digest/Adler32.pm

filter: Statementstmt 84.3% 27 / 32 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 4 totaltotal 75.0% 33 / 44 CC 4 SCAR 7.2
CC
4
Cov
82%
add
3.0
new
2.2
clone
2.0
CRAP 2.0
↑ Summary
1 package Digest::Adler32;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 $VERSION = '0.03';
6  
7 1 require Digest::base;
8 1 @ISA=qw(Digest::base);
9  
10 sub new
11 1 ▶{
Subroutine new: called CC=2 SCAR=7.9
Pod undocumented
12 1 my $class = shift;
13 1 ▶ if (ref $class) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) 0 1 1
14 0 $$class = 1; # reset
15 0 return $class;
16 }
17 1 my $adler_state = 1;
18 1 return bless \$adler_state, $class;
19 }
20  
21 0 ▶sub clone {
Subroutine clone: not called CC=1 SCAR=6.9
Pod undocumented
22 0 my $self = shift;
23 0 my $adler_state = $$self;
24 0 return bless \$adler_state, ref($self);
25 }
26  
27 # Based on RFC 1950 section 9
28  
29 7 ▶sub add {
Subroutine add: called CC=3 SCAR=11.0
Pod undocumented
30 7 my $self = shift;
31 7 my $s1 = $$self & 0x0000FFFF;
32 7 my $s2 = ($$self >> 16) & 0x0000FFFF;
33 7 for my $buf (@_) {
34 7 for my $c (unpack("C*", $buf)) {
35 54 $s1 = ($s1 + $c ) % 65521;
36 54 $s2 = ($s2 + $s1) % 65521;
37 }
38 }
39 7 $$self = ($s2 << 16) + $s1;
40 7 return $self;
41 }
42  
43 10 ▶sub digest {
Subroutine digest: called CC=1 SCAR=0.0
Pod undocumented
44 10 my $self = shift;
45 10 my $digest = pack("N", $$self);
46 10 $$self = 1; # reset
47 10 return $digest;
48 }
49  
50 1 1;
51  
52 =head1 NAME
53  
54 Digest::Adler32 - The Adler-32 checksum
55  
56 =head1 SYNOPSIS
57  
58 use Digest::Adler32;
59 $a32 = Digest::Adler32->new;
60  
61 # add stuff
62 $a32->add($some_data);
63 $a32->addfile(*STDIN);
64  
65 # get digest
66 print "Adler32: ", $a32->hexdigest, "\n";
67  
68  
69 =head1 DESCRIPTION
70  
71 The C<Digest::Adler32> module implements the Adler-32 checksum as
72 specified in RFC 1950. The interface provided by this module is
73 specified in L<Digest>, but no functional interface is provided.
74  
75 A binary digest will be 4 bytes long. A hex digest will be 8
76 characters long. A base64 digest will be 6 characters long.
77  
78 =head1 SEE ALSO
79  
80 L<Digest>, L<Digest::MD5>
81  
82 =head1 COPYRIGHT
83  
84 This library is free software; you can redistribute it and/or
85 modify it under the same terms as Perl itself.
86  
87 Copyright 1996 L. Peter Deutsch and Jean-Loup Gailly
88 Copyright 2001,2003 Gisle Aas
89  
90 =cut
↑ Summary