File Coverage

blib/lib/Digest.pm
Criterion Covered Total %
statement 35 35 100.0
branch 9 10 90.0
condition 4 6 66.6
subroutine 5 5 100.0
pod 1 1 100.0
total 54 57 94.7


line stmt bran cond sub pod time code
1             package Digest;
2              
3 3     3   123030 use strict;
  3         21  
  3         77  
4 3     3   14 use warnings;
  3         3  
  3         651  
5              
6             our $VERSION = "1.20";
7              
8             our %MMAP = (
9             "SHA-1" => [ [ "Digest::SHA", 1 ], "Digest::SHA1", [ "Digest::SHA2", 1 ] ],
10             "SHA-224" => [ [ "Digest::SHA", 224 ] ],
11             "SHA-256" => [ [ "Digest::SHA", 256 ], [ "Digest::SHA2", 256 ] ],
12             "SHA-384" => [ [ "Digest::SHA", 384 ], [ "Digest::SHA2", 384 ] ],
13             "SHA-512" => [ [ "Digest::SHA", 512 ], [ "Digest::SHA2", 512 ] ],
14             "SHA3-224" => [ [ "Digest::SHA3", 224 ] ],
15             "SHA3-256" => [ [ "Digest::SHA3", 256 ] ],
16             "SHA3-384" => [ [ "Digest::SHA3", 384 ] ],
17             "SHA3-512" => [ [ "Digest::SHA3", 512 ] ],
18             "HMAC-MD5" => "Digest::HMAC_MD5",
19             "HMAC-SHA-1" => "Digest::HMAC_SHA1",
20             "CRC-16" => [ [ "Digest::CRC", type => "crc16" ] ],
21             "CRC-32" => [ [ "Digest::CRC", type => "crc32" ] ],
22             "CRC-CCITT" => [ [ "Digest::CRC", type => "crcccitt" ] ],
23             "RIPEMD-160" => "Crypt::RIPEMD160",
24             );
25              
26             sub new {
27 7     7 1 638 shift; # class ignored
28 7         11 my $algorithm = shift;
29 7   66     23 my $impl = $MMAP{$algorithm} || do {
30             $algorithm =~ s/\W+//g;
31             "Digest::$algorithm";
32             };
33 7 100       20 $impl = [$impl] unless ref($impl);
34 7         11 local $@; # don't clobber it for our caller
35 7         9 my $err;
36 7         14 for (@$impl) {
37 9         12 my $class = $_;
38 9         12 my @args;
39 9 100       22 ( $class, @args ) = @$class if ref($class);
40 3     3   19 no strict 'refs';
  3         3  
  3         645  
41 9 100       9 unless ( exists ${"$class\::"}{"VERSION"} ) {
  9         57  
42 7         14 my $pm_file = $class . ".pm";
43 7         23 $pm_file =~ s{::}{/}g;
44 7         11 eval {
45 7         33 local @INC = @INC;
46 7 50       21 pop @INC if $INC[-1] eq '.';
47 7         1186 require $pm_file
48             };
49 7 100       210 if ($@) {
50 3   66     17 $err ||= $@;
51 3         8 next;
52             }
53             }
54 6         23 return $class->new( @args, @_ );
55             }
56 1         5 die $err;
57             }
58              
59             our $AUTOLOAD;
60              
61             sub AUTOLOAD {
62 1     1   1214 my $class = shift;
63 1         15 my $algorithm = substr( $AUTOLOAD, rindex( $AUTOLOAD, '::' ) + 2 );
64 1         8 $class->new( $algorithm, @_ );
65             }
66              
67             1;
68              
69             __END__