blib/lib/Object/Signature/Portable.pm

filter: Statementstmt 94.7% 36 / 38 Branchbran 75.0% 6 / 8 Conditioncond 71.4% 5 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 87.8% 58 / 66 CC 8 SCAR 16.0
CC
8
Cov
89%
signature
8.4
BEGIN
1.0
BEGIN
1.0
CRAP 5.0
↑ Summary
1 package Object::Signature::Portable;
2  
3 # ABSTRACT: generate portable fingerprints of objects
4  
5 1 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Crypt::Digest;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Exporter 5.57 qw/ import /;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # RECOMMEND PREREQ: Crypt::Digest 0.062
14  
15 1 our $VERSION = 'v1.2.2';
16  
17 1 our @EXPORT = qw/ signature /;
18 1 our @EXPORT_OK = @EXPORT;
19  
20  
21 10 ▶sub signature {
Subroutine signature: called CC=8 SCAR=21.3
Pod documented
22 10 my %args;
23  
24 10 ▶ if ( scalar(@_) <= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ <= 1) { } 6 4 10
25 6 $args{data} = $_[0];
26 } else {
27 4 %args = @_;
28 }
29  
30 10 ▶ $args{digest} //= 'MD5';
Condition100%2/2
$args{"digest"} //= "MD5"
l!l
46
MC/DC100%1/1
$args{"digest"} //= "MD5"
$args{"digest"}
Truth table100%2/2
A
A= $args{"digest"}
Aresult
11
00
31  
32 10 ▶ $args{format} //= 'hexdigest';
Condition100%2/2
$args{"format"} //= "hexdigest"
l!l
19
MC/DC100%1/1
$args{"format"} //= "hexdigest"
$args{"format"}
Truth table100%2/2
A
A= $args{"format"}
Aresult
11
00
33 10 ▶ unless ( $args{format} =~ m/^(?:hex|b64u?)digest$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"format"} =~ /^(?:hex|b64u?)digest$/u) 0 10 10
34 0 croak sprintf( 'Invalid digest format: %s', $args{format} );
35 }
36  
37 10 ▶ $args{serializer} //= sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
38 10 return JSON->new->canonical(1)->allow_nonref(1)->utf8(1)->pretty(0)
39 ->indent(0)->space_before(0)->space_after(0)->allow_blessed(1)
40 ->convert_blessed(1)->encode( $_[0] );
41 10 ▶ };
Condition33%1/3
$args{"serializer"} //= sub { return &JSON()->new->canonical(1)->allow_nonref(1)->utf8(1)->pretty(0)->indent(0)->space_before(0)->space_after(0)->allow_blessed(1)->convert_blessed(1)->encode($_[0]); }
l!l&&r!l&&!r
0100
MC/DC0%0/2
$args{"serializer"} //= sub { return &JSON()->new->canonical(1)->allow_nonref(1)->utf8(1)->pretty(0)->indent(0)->space_before(0)->space_after(0)->allow_blessed(1)->convert_blessed(1)->encode($_[0]); }
$args{"serializer"} sub { return &JSON()->new->canonical(1)->allow_nonref(1)->utf8(1)->pretty(0)->indent(0)->space_before(0)->space_after(0)->allow_blessed(1)->convert_blessed(1)->encode($_[0]); }
Truth table33%1/3
A //= B
A= $args{"serializer"}B= sub { return &JSON()->new->canonical(1)->allow_nonref(1)->utf8(1)->pretty(0)->indent(0)->space_before(0)->space_after(0)->allow_blessed(1)->convert_blessed(1)->encode($_[0]); }
ABresult
1X1
011
000
42  
43 10 my $digest = Crypt::Digest->new( $args{digest} );
44 10 $digest->add( &{ $args{serializer} }( $args{data} ) );
45  
46 10 ▶ if ( my $method = $digest->can( $args{format} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $method = $digest->can($args{'format'})) { } 10 0 10
47 10 ▶ my $prefix = $args{prefix} ? ( $args{digest} . ':' ) : '';
Branch: 1 branch
BranchTrueFalseTotal
$args{'prefix'} ? : 1 9 10
48 10 return $prefix . $digest->$method;
49 } else {
50 croak sprintf( 'Unexpected error with digest format: %s',
51 0 $args{format} );
52 }
53 }
54  
55  
56 1 1;
57  
58 __END__
↑ Summary