File Coverage

blib/lib/Digest.pm
Criterion Covered Total %
statement 33 33 100.0
branch 8 8 100.0
condition 4 6 66.6
subroutine 5 5 100.0
pod 1 1 100.0
total 51 53 96.2


line stmt bran cond sub pod time code
1             package Digest;
2              
3 3     3   142674 use strict;
  3         22  
  3         92  
4 3     3   14 use warnings;
  3         6  
  3         777  
5              
6             our $VERSION = "1.18";
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 743 shift; # class ignored
28 7         14 my $algorithm = shift;
29 7   66     27 my $impl = $MMAP{$algorithm} || do {
30             $algorithm =~ s/\W+//g;
31             "Digest::$algorithm";
32             };
33 7 100       24 $impl = [$impl] unless ref($impl);
34 7         11 local $@; # don't clobber it for our caller
35 7         12 my $err;
36 7         19 for (@$impl) {
37 9         14 my $class = $_;
38 9         13 my @args;
39 9 100       24 ( $class, @args ) = @$class if ref($class);
40 3     3   22 no strict 'refs';
  3         6  
  3         723  
41 9 100       12 unless ( exists ${"$class\::"}{"VERSION"} ) {
  9         56  
42 7         14 my $pm_file = $class . ".pm";
43 7         26 $pm_file =~ s{::}{/}g;
44 7         13 eval { require $pm_file };
  7         1329  
45 7 100       256 if ($@) {
46 3   66     26 $err ||= $@;
47 3         13 next;
48             }
49             }
50 6         30 return $class->new( @args, @_ );
51             }
52 1         6 die $err;
53             }
54              
55             our $AUTOLOAD;
56              
57             sub AUTOLOAD {
58 1     1   1400 my $class = shift;
59 1         6 my $algorithm = substr( $AUTOLOAD, rindex( $AUTOLOAD, '::' ) + 2 );
60 1         4 $class->new( $algorithm, @_ );
61             }
62              
63             1;
64              
65             __END__