Acrux/Digest/FNV32a.pm

filter: Statementstmt 100% 26 / 26 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 97.2% 35 / 36 CC 3 SCAR 5.6
CC
3
Cov
96%
digest
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.8
« Acme/Crux/Plugin.pm ↑ Summary Acrux.pm »
1 package Acrux::Digest::FNV32a;
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::FNV32a - FNV32a Digest calculation for short strings
10  
11 =head1 SYNOPSIS
12  
13 use Acrux::Digest::FNV32a;
14  
15 my $fnv32a = Acrux::Digest::FNV32a->new();
16 my $digest = $fnv32a->digest( "123456789" ); # 0xbb86b11c
17 my $hexdigest = $fnv32a->digest( "123456789" ); # bb86b11c
18  
19 =head1 DESCRIPTION
20  
21 This is Digest backend module that provides calculate FNV32a Digest for short strings
22  
23 =head1 METHODS
24  
25 This class inherits all methods from L<Acrux::Digest> and implements the following new ones
26  
27 =head2 digest
28  
29 my $digest = $fnv32a->digest( "123456789" ); # 0xbb86b11c
30  
31 Returns FNV32a Digest
32  
33 =head2 hexdigest
34  
35 my $hexdigest = $fnv32a->digest( "123456789" ); # bb86b11c
36  
37 Returns FNV32a Digest in hex form
38  
39 =head1 HISTORY
40  
41 See C<Changes> file
42  
43 =head1 TO DO
44  
45 See C<TODO> file
46  
47 =head1 SEE ALSO
48  
49 L<Acrux::Digest>, L<Digest::FNV::PurePerl>,
50 L<https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function>,
51 L<http://isthe.com/chongo/tech/comp/fnv/>
52  
53 =head1 AUTHOR
54  
55 Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt>
56  
57 =head1 COPYRIGHT
58  
59 Copyright (C) 1998-2026 D&D Corporation
60  
61 =head1 LICENSE
62  
63 This program is distributed under the terms of the Artistic License Version 2.0
64  
65 See the C<LICENSE> file or L<https://opensource.org/license/artistic-2-0> for details
66  
67 =cut
68  
69 1 ▶use parent qw/Acrux::Digest/;
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 4 ▶sub digest {
Subroutine digest: called CC=3 SCAR=11.0
Pod documented
72 4 my $self = shift;
73 4 my $data = shift;
74 4 ▶ $self->data($data) if defined $data;
Branch: 1 branch
BranchTrueFalseTotal
if defined $data 0 4 4
75 4 my $string = $self->data;
76 4 my $hval = 0x811c9dc5;
77  
78 4 if ((1<<32) == 4294967296) {
79 4 foreach my $c (unpack('C*', $string)) {
80 46 $hval ^= $c;
81 46 $hval += ((($hval << 1)) + (($hval << 4)) + (($hval << 7)) + (($hval << 8)) + (($hval << 24)));
82 46 $hval = $hval & 0xffffffff;
83 }
84 } else {
85 1 ▶ use bigint;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 foreach my $c (unpack('C*', $string)) {
87 $hval ^= $c;
88 $hval += ((($hval << 1)) + (($hval << 4)) + (($hval << 7)) + (($hval << 8)) + (($hval << 24)));
89 $hval = $hval & 0xffffffff;
90 }
91 }
92 4 return $hval;
93 }
94 1 ▶sub hexdigest {
Subroutine hexdigest: called CC=1 SCAR=0.0
Pod documented
95 1 my $self = shift;
96 1 return sprintf("%x", $self->digest(@_));
97 }
98  
99 1 1;
100  
101 __END__
« Acme/Crux/Plugin.pm ↑ Summary Acrux.pm »