File Coverage

blib/lib/Digest/DJB32/PP.pm
Criterion Covered Total %
statement 11 20 55.0
branch n/a
condition n/a
subroutine 4 5 80.0
pod 1 1 100.0
total 16 26 61.5


line stmt bran cond sub pod time code
1             package Digest::DJB32::PP;
2              
3 1     1   20959 use 5.006;
  1         4  
4 1     1   5 use strict;
  1         2  
  1         21  
5 1     1   5 use warnings;
  1         6  
  1         29  
6 1     1   5 use Exporter qw< import >;
  1         1  
  1         177  
7              
8             our @EXPORT= qw< djb >;
9              
10              
11             =head1 NAME
12              
13             Digest::DJB32::PP - Pure Perl version of Digest::DJB32
14              
15             =head1 VERSION
16              
17             Version 1.00
18              
19             =cut
20              
21             our $VERSION = '1.00';
22              
23              
24             =head1 SYNOPSIS
25              
26             use Digest::DJB32::PP
27            
28             my $hash = djb("abc123");
29              
30             =head1 DESCRIPTION
31              
32             Digest::DJB32:PP is a pure Perl implementation of D. J. Bernstein's hash which returns a 32-bit unsigned value for any variable-length input string.
33              
34             =head1 EXPORT
35              
36             Export by default C function.
37              
38             =head1 FUNCTIONS
39              
40             =head2 djb
41              
42             Return the hash of the given argument.
43              
44             B
45              
46             my $hash = djb("abc123");
47              
48             =cut
49              
50             sub djb {
51 0     0 1   my @bytes = unpack("C*", shift);
52             #print STDERR "*** bytes = @bytes\n";
53 0           my $ValLow = 5381;
54 0           my $ValHight = 0;
55            
56 0           foreach my $i (@bytes) {
57 0           $ValLow = ($ValLow << 5) + $ValLow + $i;
58 0           $ValHight = ($ValHight << 5) + $ValHight + ($ValLow >> 16);
59 0           $ValLow &= 0x0000ffff;
60 0           $ValHight &= 0x0000ffff;
61             }
62             #$Val = ((($Val << 5) + $Val + $_) & 0x03ffffff) for @bytes
63 0           return $ValLow | $ValHight<<16;
64             }
65              
66             =head1 AUTHOR
67              
68             Richard THIBERT, C<< >>
69              
70             =head1 BUGS
71              
72             Please report any bugs or feature requests to C, or through
73             the web interface at L. I will be notified, and then you'll
74             automatically be notified of progress on your bug as I make changes.
75              
76              
77              
78              
79             =head1 SUPPORT
80              
81             You can find documentation for this module with the perldoc command.
82              
83             perldoc Digest::DJB32::PP
84              
85              
86             You can also look for information at:
87              
88             =over 4
89              
90             =item * RT: CPAN's request tracker (report bugs here)
91              
92             L
93              
94             =item * AnnoCPAN: Annotated CPAN documentation
95              
96             L
97              
98             =item * CPAN Ratings
99              
100             L
101              
102             =item * Search CPAN
103              
104             L
105              
106             =back
107              
108              
109             =head1 ACKNOWLEDGEMENTS
110              
111              
112             =head1 LICENSE AND COPYRIGHT
113              
114             Copyright 2015 Richard THIBERT.
115              
116             This program is free software; you can redistribute it and/or modify it
117             under the terms of the the Artistic License (2.0). You may obtain a
118             copy of the full license at:
119              
120             L
121              
122             Any use, modification, and distribution of the Standard or Modified
123             Versions is governed by this Artistic License. By using, modifying or
124             distributing the Package, you accept this license. Do not use, modify,
125             or distribute the Package, if you do not accept this license.
126              
127             If your Modified Version has been derived from a Modified Version made
128             by someone other than you, you are nevertheless required to ensure that
129             your Modified Version complies with the requirements of this license.
130              
131             This license does not grant you the right to use any trademark, service
132             mark, tradename, or logo of the Copyright Holder.
133              
134             This license includes the non-exclusive, worldwide, free-of-charge
135             patent license to make, have made, use, offer to sell, sell, import and
136             otherwise transfer the Package with respect to any patent claims
137             licensable by the Copyright Holder that are necessarily infringed by the
138             Package. If you institute patent litigation (including a cross-claim or
139             counterclaim) against any party alleging that the Package constitutes
140             direct or contributory patent infringement, then this Artistic License
141             to you shall terminate on the date that such litigation is filed.
142              
143             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
144             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
145             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
146             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
147             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
148             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
149             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
150             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
151              
152              
153             =cut
154              
155             1; # End of Digest::DJB32::PP