blib/lib/Mail/Pyzor/SHA.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 49 CC 5 SCAR 26.9
CC
5
Cov
0%
_sha_module
30.0
sha1
2.0
sha1_hex
2.0
CRAP 14.7
1 package Mail::Pyzor::SHA;
2  
3 # Copyright 2018 cPanel, LLC.
4 # All rights reserved.
5 # http://cpanel.net
6 #
7 # This is free software; you can redistribute it and/or modify it under the
8 # same terms as Perl itself. See L<perlartistic>.
9  
10 use strict;
11 use warnings;
12  
13 use constant _ORDER => ( 'Digest::SHA1', 'Digest::SHA' );
14  
15 my $_sha_module;
16  
17 sub _sha_module {
18 if ( !$_sha_module ) {
19  
20 # First check if one of the modules is loaded.
21 if ( my @loaded = grep { $_->can('sha1') } _ORDER ) {
22 $_sha_module = $loaded[0];
23 }
24 else {
25 local $@;
26  
27 my @modules = _ORDER();
28  
29 while ( my $module = shift @modules ) {
30 my $path = "$module.pm";
31 $path =~ s<::></>g;
32  
33 if ( eval { require $path; 1 } ) {
34 $_sha_module = $module;
35 last;
36 }
37 elsif ( !@modules ) {
38 die;
39 }
40 }
41 }
42 }
43  
44 return $_sha_module;
45 }
46  
47 sub sha1 {
48 return _sha_module()->can('sha1')->(@_);
49 }
50  
51 sub sha1_hex {
52 return _sha_module()->can('sha1_hex')->(@_);
53 }
54  
55 1;