line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Bubblegum Wrapper around Hashing Algorithms |
2
|
|
|
|
|
|
|
package Bubblegum::Wrapper::Digest; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
439
|
use 5.10.0; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
5
|
1
|
|
|
1
|
|
358
|
use Bubblegum::Class; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Digest::MD5 (); |
7
|
|
|
|
|
|
|
use Digest::SHA (); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Bubblegum::Exception; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
extends 'Bubblegum::Object::Instance'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.40'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub BUILD { |
16
|
|
|
|
|
|
|
my $self = shift; |
17
|
|
|
|
|
|
|
$self->data->typeof('str') |
18
|
|
|
|
|
|
|
or Bubblegum::Exception->throw( |
19
|
|
|
|
|
|
|
verbose => 1, |
20
|
|
|
|
|
|
|
message => ref($self)->format( |
21
|
|
|
|
|
|
|
'Wrapper package "%s" requires string data' |
22
|
|
|
|
|
|
|
), |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub encode { |
27
|
|
|
|
|
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
my $type = shift // 'md5_hex'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $encoder; |
31
|
|
|
|
|
|
|
my $md5 = [qw(md5 md5_hex)]; |
32
|
|
|
|
|
|
|
my $sha = [qw(sha1_base64 sha1 sha1_hex)]; |
33
|
|
|
|
|
|
|
my $hmc = [qw(hmac_sha1 hmac_sha1_hex)]; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$encoder = 'Digest::MD5' if $md5->one eq $type; |
36
|
|
|
|
|
|
|
$encoder = 'Digest::SHA' if $sha->one eq $type; |
37
|
|
|
|
|
|
|
$encoder = 'Digest::SHA' if $hmc->one eq $type; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return undef unless $encoder; |
40
|
|
|
|
|
|
|
return $encoder->can($type)->($self->data); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |