File Coverage

lib/Mail/Pyzor/SHA.pm
Criterion Covered Total %
statement 25 27 92.5
branch 6 8 75.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 37 43 86.0


line stmt bran cond sub pod time code
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             # Apache 2.0 license.
9              
10 4     4   2742 use strict;
  4         7  
  4         122  
11 4     4   21 use warnings;
  4         8  
  4         145  
12              
13 4     4   22 use constant _ORDER => ( 'Digest::SHA1', 'Digest::SHA' );
  4         7  
  4         1273  
14              
15             my $_sha_module;
16              
17             sub _sha_module {
18 6 100   6   14 if ( !$_sha_module ) {
19              
20             # First check if one of the modules is loaded.
21 1 50       4 if ( my @loaded = grep { $_->can('sha1') } _ORDER ) {
  2         15  
22 0         0 $_sha_module = $loaded[0];
23             }
24             else {
25 1         2 local $@;
26              
27 1         3 my @modules = _ORDER();
28              
29 1         4 while ( my $module = shift @modules ) {
30 2         7 my $path = "$module.pm";
31 2         8 $path =~ s<::>g;
32              
33 2 100       5 if ( eval { require $path; 1 } ) {
  2 50       698  
  1         3390  
34 1         6 $_sha_module = $module;
35 1         3 last;
36             }
37             elsif ( !@modules ) {
38 0         0 die;
39             }
40             }
41             }
42             }
43              
44 6         63 return $_sha_module;
45             }
46              
47             sub sha1 {
48 2     2 0 6 return _sha_module()->can('sha1')->(@_);
49             }
50              
51             sub sha1_hex {
52 4     4 0 8 return _sha_module()->can('sha1_hex')->(@_);
53             }
54              
55             1;