KiokuDB/Role/WithDigest.pm

filter: Statementstmt 72.9% 35 / 48 Branchbran 7.1% 1 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod n/a totaltotal 63.0% 46 / 73 CC 9 SCAR 27.9
CC
9
Cov
58%
_extract_digest_input_strings
41.4
_build_digest_strings
3.1
BEGIN
1.0
CRAP 16.2
« KiokuDB/Backend/Serialize/JSPON/Collapser.pm ↑ Summary KiokuDB/Util.pm »
1 package KiokuDB::Role::WithDigest;
2 3 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Digest::SHA qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use MooseX::Clone::Meta::Attribute::Trait::NoClone;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use namespace::clean -except => 'meta';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 has digest => (
13 traits => [qw(NoClone)],
14 isa => "Str",
15 is => "ro",
16 lazy_build => 1,
17 );
18  
19 3 requires 'digest_parts';
20  
21 sub _build_digest {
22 120 ▶ my $self = shift;
Subroutine _build_digest: called CC=1 SCAR=0.0
23 120 $self->_compute_digest( $self->_build_digest_strings );
24 }
25  
26 sub _compute_digest {
27 120 ▶ my ( $self, @strings ) = @_;
Subroutine _compute_digest: called CC=1 SCAR=0.0
28  
29 3 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 120 sha1_hex(join ":", ref($self), @strings);
31 }
32  
33 sub _build_digest_strings {
34 120 ▶ my $self = shift;
Subroutine _build_digest_strings: called CC=3 SCAR=11.2
35  
36 120 my @parts = $self->digest_parts;
37  
38 120 my @strings;
39  
40 120 foreach my $part ( $self->digest_parts ) {
41 240 ▶ if ( ref $part ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $part) { } 0 240 240
42 0 push @strings, $self->_extract_digest_input_strings($part);
43 } else {
44 240 push @strings, $part;
45 }
46 }
47  
48 120 return @strings;
49 }
50  
51 sub _extract_digest_input_strings {
52 0 ▶ my ( $self, $part ) = @_;
Subroutine _extract_digest_input_strings: not called CC=7 SCAR=37.2
53  
54 0 ▶ return $part unless ref $part;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $part 0 0 0
55
56 3 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
57  
58 0 ▶ if ( blessed($part) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (builtin::blessed($part)) { } 0 0 0
elsif (ref $part eq 'ARRAY') { } 0 0 0
elsif (ref $part eq 'HASH') { } 0 0 0
59 0 ▶ if ( $part->can("kiokudb_object_id") ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($part->can('kiokudb_object_id')) { } 0 0 0
elsif ($part->can('digest')) { } 0 0 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), ']');
68 } elsif ( ref $part eq 'HASH' ) {
69 0 return join("", '{', join(",", map { $_, ":", $self->_extract_digest_input_strings($part->{$_}) } sort keys %$part), '}');
70 } else {
71 0 croak "Can't digest $part (not a simple ref type)";
72 }
73 }
74  
75 3 __PACKAGE__
76  
77 __END__
« KiokuDB/Backend/Serialize/JSPON/Collapser.pm ↑ Summary KiokuDB/Util.pm »