| 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
| |||||||||||||||||||||
| 25 | 6 | $args{data} = $_[0]; | |||||||||||||||||||
| 26 | } else { | ||||||||||||||||||||
| 27 | 4 | %args = @_; | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 10 | ▶ | $args{digest} //= 'MD5'; | ||||||||||||||||||
|
Condition100%2/2
$args{"digest"} //= "MD5"
MC/DC100%1/1
$args{"digest"} //= "MD5"
$args{"digest"}
Truth table100%2/2
A
A= $args{"digest"}
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 10 | ▶ | $args{format} //= 'hexdigest'; | ||||||||||||||||||
|
Condition100%2/2
$args{"format"} //= "hexdigest"
MC/DC100%1/1
$args{"format"} //= "hexdigest"
$args{"format"}
Truth table100%2/2
A
A= $args{"format"}
| |||||||||||||||||||||
| 33 | 10 | ▶ | unless ( $args{format} =~ m/^(?:hex|b64u?)digest$/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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]);
}
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]);
}
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 47 | 10 | ▶ | my $prefix = $args{prefix} ? ( $args{digest} . ':' ) : ''; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||