line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hash::MD5; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=pod |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Hash::MD5 - MD5 checksum for choosen hashref |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.07 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
17
|
|
|
|
|
|
|
|
18
|
3
|
|
|
3
|
|
55925
|
use utf8; |
|
3
|
|
|
|
|
59
|
|
|
3
|
|
|
|
|
24
|
|
19
|
3
|
|
|
3
|
|
199
|
use 5.10.0; |
|
3
|
|
|
|
|
14
|
|
20
|
3
|
|
|
3
|
|
159
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
108
|
|
21
|
3
|
|
|
3
|
|
20
|
use warnings FATAL => 'all'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
267
|
|
22
|
3
|
|
|
3
|
|
20
|
use Digest::MD5 qw(md5_hex); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
241
|
|
23
|
3
|
|
|
3
|
|
18
|
use Scalar::Util 'refaddr'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
315
|
|
24
|
3
|
|
|
3
|
|
18
|
use vars qw($VERSION @EXPORT_OK); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
2351
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
require Exporter; |
27
|
|
|
|
|
|
|
*import = \&Exporter::import; |
28
|
|
|
|
|
|
|
@EXPORT_OK = qw(sum_hash sum_array); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
############################################################################### |
31
|
|
|
|
|
|
|
############## GLOBAL VAR ###################### |
32
|
|
|
|
|
|
|
############################################################################### |
33
|
|
|
|
|
|
|
my $using_addresses = {}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
############################################################################### |
36
|
|
|
|
|
|
|
############## PRIVATE SUBS ###################### |
37
|
|
|
|
|
|
|
############################################################################### |
38
|
|
|
|
|
|
|
sub _sort_keys { |
39
|
22
|
|
|
22
|
|
26
|
my ($hashref) = @_; |
40
|
22
|
|
|
|
|
37
|
my $serial = scalar( keys %$hashref ); |
41
|
22
|
|
|
|
|
27
|
my $ret = ''; |
42
|
22
|
|
|
|
|
58
|
foreach ( sort { $a cmp $b } keys %$hashref ) { |
|
23
|
|
|
|
|
50
|
|
43
|
43
|
100
|
|
|
|
110
|
if ( ref $hashref->{$_} eq 'HASH' ) { |
|
|
100
|
|
|
|
|
|
44
|
3
|
100
|
|
|
|
28
|
return $ret . $serial if ( $using_addresses->{ refaddr($hashref) } ); |
45
|
1
|
|
|
|
|
5
|
$using_addresses->{ refaddr($hashref) } = 1; |
46
|
1
|
50
|
|
|
|
9
|
$ret = $ret . unpack( 'H*', $_ ) . _sort_keys( ( defined $hashref->{$_} ? $hashref->{$_} : 'undef' ) ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif ( ref $hashref->{$_} eq 'ARRAY' ) { |
49
|
2
|
50
|
|
|
|
11
|
$ret = $ret . unpack( 'H*', $_ ) . _sort_array( ( defined $hashref->{$_} ? $hashref->{$_} : 'undef' ) ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
38
|
50
|
|
|
|
72
|
my $var = ( defined $hashref->{$_} ) ? $hashref->{$_} : 'undef'; |
53
|
38
|
|
|
|
|
49
|
$serial = $serial . length($var); |
54
|
38
|
|
|
|
|
64
|
utf8::encode($_); |
55
|
38
|
|
|
|
|
54
|
utf8::encode($var); |
56
|
38
|
|
|
|
|
139
|
$ret = $ret . unpack( 'H*', length($_) . $_ ) . unpack( 'H*', $var ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
20
|
|
|
|
|
104
|
return $ret . $serial; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _sort_array { |
64
|
22
|
|
|
22
|
|
25
|
my ($arrayref) = @_; |
65
|
22
|
|
|
|
|
26
|
my $serial = scalar(@$arrayref); |
66
|
22
|
|
|
|
|
26
|
my $ret = ''; |
67
|
22
|
|
|
|
|
36
|
foreach (@$arrayref) { |
68
|
58
|
100
|
|
|
|
120
|
if ( ref $_ eq 'HASH' ) { $ret = $ret . _sort_keys($_); } |
|
3
|
100
|
|
|
|
6
|
|
69
|
2
|
|
|
|
|
13
|
elsif ( ref $_ eq 'ARRAY' ) { $ret = $ret . _sort_array($_); } |
70
|
|
|
|
|
|
|
else { |
71
|
53
|
|
|
|
|
69
|
$serial = $serial . length($_); |
72
|
53
|
|
|
|
|
77
|
utf8::encode($_); |
73
|
53
|
|
|
|
|
118
|
$ret = $ret . unpack( 'H*', $_ ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
22
|
|
|
|
|
89
|
return $ret . $serial; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 SYNOPSIS |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
use Hash::MD5 qw(sum_hash); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
... |
84
|
|
|
|
|
|
|
my $hashref = {some => 'hashref'}; |
85
|
|
|
|
|
|
|
print sum_hash( $hashref ), $/; |
86
|
|
|
|
|
|
|
... |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
use Hash::MD5 qw(sum_array); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
... |
93
|
|
|
|
|
|
|
my $arrayref = ['some', 'arrayref']; |
94
|
|
|
|
|
|
|
print sum_array( $arrayref ), $/; |
95
|
|
|
|
|
|
|
... |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 sum_hash |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub sum_hash { |
104
|
18
|
|
|
18
|
1
|
2001
|
my ($arg) = @_; |
105
|
18
|
|
|
|
|
30
|
return md5_hex( _sort_keys($arg) ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head2 sum_array |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub sum_array { |
113
|
18
|
|
|
18
|
1
|
2008
|
my ($arg) = @_; |
114
|
18
|
|
|
|
|
30
|
return md5_hex( _sort_array($arg) ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; # End of Hash::MD5 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
__END__ |