line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package KiokuDB::Role::WithDigest; |
2
|
3
|
|
|
3
|
|
1310
|
use Moose::Role; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
20
|
|
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
11141
|
use Carp qw(croak); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
175
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
2853
|
use Digest::SHA qw(sha1_hex); |
|
3
|
|
|
|
|
10149
|
|
|
3
|
|
|
|
|
252
|
|
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
1099
|
use MooseX::Clone::Meta::Attribute::Trait::NoClone; |
|
3
|
|
|
|
|
23282
|
|
|
3
|
|
|
|
|
110
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
18
|
use namespace::clean -except => 'meta'; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
19
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has digest => ( |
13
|
|
|
|
|
|
|
traits => [qw(NoClone)], |
14
|
|
|
|
|
|
|
isa => "Str", |
15
|
|
|
|
|
|
|
is => "ro", |
16
|
|
|
|
|
|
|
lazy_build => 1, |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
requires 'digest_parts'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _build_digest { |
22
|
136
|
|
|
136
|
|
280
|
my $self = shift; |
23
|
136
|
|
|
|
|
331
|
$self->_compute_digest( $self->_build_digest_strings ); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _compute_digest { |
27
|
136
|
|
|
136
|
|
248
|
my ( $self, @strings ) = @_; |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
3
|
|
903
|
no warnings 'uninitialized'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
482
|
|
30
|
136
|
|
|
|
|
5288
|
sha1_hex(join ":", ref($self), @strings); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _build_digest_strings { |
34
|
136
|
|
|
136
|
|
159
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
136
|
|
|
|
|
498
|
my @parts = $self->digest_parts; |
37
|
|
|
|
|
|
|
|
38
|
136
|
|
|
|
|
241
|
my @strings; |
39
|
|
|
|
|
|
|
|
40
|
136
|
|
|
|
|
413
|
foreach my $part ( $self->digest_parts ) { |
41
|
272
|
50
|
|
|
|
425
|
if ( ref $part ) { |
42
|
0
|
|
|
|
|
0
|
push @strings, $self->_extract_digest_input_strings($part); |
43
|
|
|
|
|
|
|
} else { |
44
|
272
|
|
|
|
|
550
|
push @strings, $part; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
136
|
|
|
|
|
528
|
return @strings; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _extract_digest_input_strings { |
52
|
0
|
|
|
0
|
|
|
my ( $self, $part ) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
return $part unless ref $part; |
55
|
|
|
|
|
|
|
|
56
|
3
|
|
|
3
|
|
24
|
no warnings 'uninitialized'; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
555
|
|
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if ( blessed($part) ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if ( $part->can("kiokudb_object_id") ) { |
|
|
0
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return $part->kiokudb_object_id; |
61
|
|
|
|
|
|
|
} elsif ( $part->can("digest") ) { |
62
|
0
|
|
|
|
|
|
return $part->digest; |
63
|
|
|
|
|
|
|
} else { |
64
|
0
|
|
|
|
|
|
croak "Can't digest $part (no digest or ID method)"; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} elsif ( ref $part eq 'ARRAY' ) { |
67
|
0
|
|
|
|
|
|
return join("", '[', join(",", map { $self->_extract_digest_input_strings($_) } @$part), ']'); |
|
0
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} elsif ( ref $part eq 'HASH' ) { |
69
|
0
|
|
|
|
|
|
return join("", '{', join(",", map { $_, ":", $self->_extract_digest_input_strings($part->{$_}) } sort keys %$part), '}'); |
|
0
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} else { |
71
|
0
|
|
|
|
|
|
croak "Can't digest $part (not a simple ref type)"; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
__PACKAGE__ |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |