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             # <@LICENSE>
8             # Licensed to the Apache Software Foundation (ASF) under one or more
9             # contributor license agreements. See the NOTICE file distributed with
10             # this work for additional information regarding copyright ownership.
11             # The ASF licenses this file to you under the Apache License, Version 2.0
12             # (the "License"); you may not use this file except in compliance with
13             # the License. You may obtain a copy of the License at:
14             #
15             # http://www.apache.org/licenses/LICENSE-2.0
16             #
17             # Unless required by applicable law or agreed to in writing, software
18             # distributed under the License is distributed on an "AS IS" BASIS,
19             # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20             # See the License for the specific language governing permissions and
21             # limitations under the License.
22             #
23             #
24              
25 4     4   1882 use strict;
  4         6  
  4         104  
26 4     4   17 use warnings;
  4         7  
  4         118  
27              
28 4     4   19 use constant _ORDER => ( 'Digest::SHA1', 'Digest::SHA' );
  4         6  
  4         1202  
29              
30             our $VERSION = '0.06_01'; # TRIAL
31             $VERSION =~ tr/_//d;
32              
33             my $_sha_module;
34              
35             sub _sha_module {
36 6 100   6   12 if ( !$_sha_module ) {
37              
38             # First check if one of the modules is loaded.
39 1 50       3 if ( my @loaded = grep { $_->can('sha1') } _ORDER ) {
  2         13  
40 0         0 $_sha_module = $loaded[0];
41             }
42             else {
43 1         2 local $@;
44              
45 1         3 my @modules = _ORDER();
46              
47 1         3 while ( my $module = shift @modules ) {
48 2         6 my $path = "$module.pm";
49 2         9 $path =~ s<::>g;
50              
51 2 100       4 if ( eval { require $path; 1 } ) {
  2 50       673  
  1         2650  
52 1         3 $_sha_module = $module;
53 1         3 last;
54             }
55             elsif ( !@modules ) {
56 0         0 die;
57             }
58             }
59             }
60             }
61              
62 6         56 return $_sha_module;
63             }
64              
65             sub sha1 {
66 2     2 0 6 return _sha_module()->can('sha1')->(@_);
67             }
68              
69             sub sha1_hex {
70 4     4 0 7 return _sha_module()->can('sha1_hex')->(@_);
71             }
72              
73             1;