File Coverage

blib/lib/Crypt/Checksum/Adler32.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 3 3 100.0
total 32 32 100.0


line stmt bran cond sub pod time code
1             package Crypt::Checksum::Adler32;
2              
3 2     2   93139 use strict;
  2         3  
  2         57  
4 2     2   9 use warnings;
  2         2  
  2         123  
5             our $VERSION = '0.089';
6              
7 2     2   9 use base qw(Crypt::Checksum Exporter);
  2         3  
  2         819  
8             our %EXPORT_TAGS = ( all => [qw( adler32_data adler32_data_hex adler32_data_int adler32_file adler32_file_hex adler32_file_int )] );
9             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
10             our @EXPORT = qw();
11              
12 2     2   9 use Carp;
  2         2  
  2         119  
13             $Carp::Internal{(__PACKAGE__)}++;
14 2     2   9 use CryptX;
  2         2  
  2         328  
15              
16 1     1 1 219699 sub adler32_file { local $SIG{__DIE__} = \&CryptX::_croak; Crypt::Checksum::Adler32->new->addfile(@_)->digest }
  1         16  
17 4     4 1 17 sub adler32_file_hex { local $SIG{__DIE__} = \&CryptX::_croak; Crypt::Checksum::Adler32->new->addfile(@_)->hexdigest }
  4         30  
18 1     1 1 5 sub adler32_file_int { local $SIG{__DIE__} = \&CryptX::_croak; Crypt::Checksum::Adler32->new->addfile(@_)->intdigest }
  1         9  
19              
20             1;
21              
22             =pod
23              
24             =head1 NAME
25              
26             Crypt::Checksum::Adler32 - Compute Adler32 checksum
27              
28             =head1 SYNOPSIS
29              
30             ### Functional interface:
31             use Crypt::Checksum::Adler32 ':all';
32              
33             # calculate Adler32 checksum from string/buffer
34             my $data = 'data string';
35             my $checksum_raw = adler32_data($data);
36             my $checksum_hex = adler32_data_hex($data);
37             my $checksum_int = adler32_data_int($data);
38             # or from file
39             my $checksum_file_raw = adler32_file('filename.dat');
40             my $checksum_file_hex = adler32_file_hex('filename.dat');
41             my $checksum_file_int = adler32_file_int('filename.dat');
42             # or from filehandle
43             my $filehandle = ...; # existing binary-mode filehandle
44             my $checksum_fh_raw = adler32_file($filehandle);
45             my $checksum_fh_hex = adler32_file_hex($filehandle);
46             my $checksum_fh_int = adler32_file_int($filehandle);
47              
48             ### OO interface:
49             use Crypt::Checksum::Adler32;
50              
51             my $d = Crypt::Checksum::Adler32->new;
52             $d->add('any data');
53             $d->add('another data');
54             my $checksum_raw = $d->digest; # raw 4 bytes
55             my $checksum_hex = $d->hexdigest; # hexadecimal form
56             my $checksum_int = $d->intdigest; # 32-bit unsigned integer
57              
58             # or checksum a file instead
59             my $checksum_file_raw = Crypt::Checksum::Adler32->new->addfile('filename.dat')->digest;
60              
61             =head1 DESCRIPTION
62              
63             Computes Adler-32 checksums.
64              
65             I
66              
67             =head1 EXPORT
68              
69             Nothing is exported by default.
70              
71             You can export selected functions:
72              
73             use Crypt::Checksum::Adler32 qw(adler32_data adler32_data_hex adler32_data_int adler32_file adler32_file_hex adler32_file_int);
74              
75             Or all of them at once:
76              
77             use Crypt::Checksum::Adler32 ':all';
78              
79             =head1 FUNCTIONS
80              
81             =head2 adler32_data
82              
83             Returns the checksum as raw octets.
84              
85             my $checksum_raw = adler32_data('data string');
86             #or
87             my $checksum_raw = adler32_data('any data', 'more data', 'even more data');
88              
89             =head2 adler32_data_hex
90              
91             Returns checksum as a hexadecimal string.
92              
93             my $checksum_hex = adler32_data_hex('data string');
94             #or
95             my $checksum_hex = adler32_data_hex('any data', 'more data', 'even more data');
96              
97             =head2 adler32_data_int
98              
99             Returns checksum as unsigned 32-bit integer.
100              
101             my $checksum_int = adler32_data_int('data string');
102             #or
103             my $checksum_int = adler32_data_int('any data', 'more data', 'even more data');
104              
105             Each C function converts its data arguments to bytes using
106             Perl's usual scalar stringification. Defined scalars, including numbers and
107             string-overloaded objects, are accepted. C is treated as an empty
108             string and may emit Perl's usual "uninitialized value" warning.
109              
110             =head2 adler32_file
111              
112             Returns the checksum as raw octets.
113              
114             my $checksum_raw = adler32_file('filename.dat');
115             #or
116             my $filehandle = ...; # existing binary-mode filehandle
117             my $checksum_raw = adler32_file($filehandle);
118              
119             =head2 adler32_file_hex
120              
121             Returns checksum as a hexadecimal string.
122              
123             my $checksum_hex = adler32_file_hex('filename.dat');
124             #or
125             my $filehandle = ...; # existing binary-mode filehandle
126             my $checksum_hex = adler32_file_hex($filehandle);
127              
128             =head2 adler32_file_int
129              
130             Returns checksum as unsigned 32-bit integer.
131              
132             my $checksum_int = adler32_file_int('filename.dat');
133             #or
134             my $filehandle = ...; # existing binary-mode filehandle
135             my $checksum_int = adler32_file_int($filehandle);
136              
137             =head1 METHODS
138              
139             =head2 new
140              
141             Constructor, returns a reference to the checksum object.
142              
143             my $d = Crypt::Checksum::Adler32->new;
144              
145             =head2 clone
146              
147             Creates a copy of the checksum object state and returns a reference to the copy.
148              
149             $d->clone();
150              
151             =head2 reset
152              
153             Reinitialize the checksum object state and returns a reference to the checksum object.
154              
155             $d->reset();
156              
157             =head2 add
158              
159             All arguments are appended to the message we calculate checksum for.
160             The return value is the checksum object itself.
161              
162             Each argument is converted to bytes using Perl's usual scalar stringification.
163             Defined scalars, including numbers and string-overloaded objects, are accepted.
164             C is treated as an empty string and may emit Perl's usual
165             "uninitialized value" warning.
166              
167             $d->add('any data');
168             #or
169             $d->add('any data', 'more data', 'even more data');
170              
171             =head2 addfile
172              
173             The content of the file (or filehandle) is appended to the message we calculate checksum for.
174             The return value is the checksum object itself.
175              
176             $d->addfile('filename.dat');
177             #or
178             my $filehandle = ...; # existing binary-mode filehandle
179             $d->addfile($filehandle);
180              
181             B The filehandle must be in binary mode before you pass it to C.
182              
183             =head2 digest
184              
185             Returns the binary checksum (raw bytes).
186             This method does not alter the object state, so you can call it
187             repeatedly and continue with C or C afterwards.
188              
189             my $result_raw = $d->digest();
190              
191             =head2 hexdigest
192              
193             Returns the checksum encoded as a hexadecimal string.
194             Like C, this method does not alter the object state.
195              
196             my $result_hex = $d->hexdigest();
197              
198             =head2 intdigest
199              
200             Returns the checksum encoded as unsigned 32-bit integer.
201             Like C, this method does not alter the object state.
202              
203             my $result_int = $d->intdigest();
204              
205             =head1 SEE ALSO
206              
207             =over
208              
209             =item * L
210              
211             =item * L
212              
213             =back
214              
215             =cut