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   140019 use strict;
  3         21  
  3         87  
4 3     3   15 use warnings;
  3         5  
  3         800  
5              
6             our $VERSION = "1.19";
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 777 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       26 $impl = [$impl] unless ref($impl);
34 7         14 local $@; # don't clobber it for our caller
35 7         11 my $err;
36 7         17 for (@$impl) {
37 9         13 my $class = $_;
38 9         15 my @args;
39 9 100       22 ( $class, @args ) = @$class if ref($class);
40 3     3   29 no strict 'refs';
  3         5  
  3         776  
41 9 100       14 unless ( exists ${"$class\::"}{"VERSION"} ) {
  9         46  
42 7         28 my $pm_file = $class . ".pm";
43 7         30 $pm_file =~ s{::}{/}g;
44 7         15 eval {
45 7         33 local @INC = @INC;
46 7 50       26 pop @INC if $INC[-1] eq '.';
47 7         1047 require $pm_file
48             };
49 7 100       244 if ($@) {
50 3   66     19 $err ||= $@;
51 3         9 next;
52             }
53             }
54 6         30 return $class->new( @args, @_ );
55             }
56 1         5 die $err;
57             }
58              
59             our $AUTOLOAD;
60              
61             sub AUTOLOAD {
62 1     1   1284 my $class = shift;
63 1         15 my $algorithm = substr( $AUTOLOAD, rindex( $AUTOLOAD, '::' ) + 2 );
64 1         7 $class->new( $algorithm, @_ );
65             }
66              
67             1;
68              
69             __END__