| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||
| 3 | package Digest::MultiHash; | ||||||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||
| 6 | 2 | extends our @ISA, qw(Digest::base); | |||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||
| 8 | 2 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | 2 | ▶ | use Digest; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 11 | 2 | ▶ | use Digest::MoreFallbacks; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 12 | 2 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||
| 14 | 2 | ▶ | use namespace::clean -except => [qw(meta)]; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||
| 16 | 2 | has width => ( | |||||||||||||||||||||||
| 17 | isa => "Int", | ||||||||||||||||||||||||
| 18 | is => "rw", | ||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||
| 21 | has hashes => ( | ||||||||||||||||||||||||
| 22 | isa => "ArrayRef", | ||||||||||||||||||||||||
| 23 | is => "ro", | ||||||||||||||||||||||||
| 24 | required => 1, | ||||||||||||||||||||||||
| 25 | 4 | ▶ | default => sub { [qw(SHA-1)] }, | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 26 | 2 | ); | |||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||
| 28 | 2 | has _digest_objects => ( | |||||||||||||||||||||||
| 29 | isa => "ArrayRef", | ||||||||||||||||||||||||
| 30 | is => "ro", | ||||||||||||||||||||||||
| 31 | lazy_build => 1, | ||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||
| 34 | 9 | ▶ | sub BUILD { | ||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||
| 35 | 9 | shift->_digest_objects; # force building | |||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||
| 38 | 14 | ▶ | sub _call { | ||||||||||||||||||||||
|
Subroutine
_call: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 39 | 14 | my ( $self, $method, @args ) = @_; | |||||||||||||||||||||||
| 40 | 14 | map { $_->$method( @args ) } @{ $self->_digest_objects }; | |||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||
| 43 | 9 | ▶ | sub _build__digest_objects { | ||||||||||||||||||||||
|
Subroutine
_build__digest_objects: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||
| 44 | 9 | my $self = shift; | |||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||
| 46 | my @digests = map { | ||||||||||||||||||||||||
| 47 | 8 | ▶ | blessed($_) | ||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
ref $_ || ''
MC/DC0%0/1
ref $_ || ''
ref $_
Truth table50%1/2
A
A= ref $_
| |||||||||||||||||||||||||
| 48 | ? $_ | ||||||||||||||||||||||||
| 49 | : Digest->new( | ||||||||||||||||||||||||
| 50 | ((ref($_)||'') eq "ARRAY") | ||||||||||||||||||||||||
| 51 | ? @$_ | ||||||||||||||||||||||||
| 52 | : $_ | ||||||||||||||||||||||||
| 53 | ) | ||||||||||||||||||||||||
| 54 | 9 | } @{ $self->hashes }; | |||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||
| 56 | 9 | ▶ | die "No digest module specified" unless @digests; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||
| 58 | 8 | return \@digests; | |||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||
| 61 | # MooseX::Clone | ||||||||||||||||||||||||
| 62 | 0 | ▶ | sub clone { | ||||||||||||||||||||||
|
Subroutine
clone: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||
| 65 | 0 | $self->new( | |||||||||||||||||||||||
| 66 | width => $self->width, | ||||||||||||||||||||||||
| 67 | hashes => $self->hashes, | ||||||||||||||||||||||||
| 68 | _digest_objects => [ $self->_call("clone") ], | ||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||
| 72 | 7 | ▶ | sub add { | ||||||||||||||||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||
| 73 | 7 | my ( $self, @args ) = @_; | |||||||||||||||||||||||
| 74 | 7 | $self->_call("add", @args); | |||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||
| 77 | 7 | ▶ | sub digest { | ||||||||||||||||||||||
|
Subroutine
digest: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||
| 78 | 7 | my $self = shift; | |||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||
| 80 | 7 | my @digests = $self->_call("digest"); | |||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||
| 82 | 7 | ▶ | my $width = $self->width || length($digests[0]); | ||||||||||||||||||||||
|
Condition33%1/3
$self->width || length $digests[0]
MC/DC0%0/2
$self->width || length $digests[0]
$self->width
length $digests[0]
Truth table33%1/3
A || B
A= $self->widthB= length $digests[0]
| |||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||
| 84 | 7 | my $concat = join "", @digests; | |||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||
| 86 | 7 | ▶ | die "Chosen hashes are insufficient for desired width" if length($concat) < $width; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||
| 88 | 6 | my ( $buf, @pieces ) = unpack "(a$width)*", $concat; | |||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||
| 90 | 6 | $buf ^= $_ for @pieces; | |||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||
| 92 | 6 | return $buf; | |||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||
| 95 | 2 | __PACKAGE__; | |||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||
| 97 | __END__ | ||||||||||||||||||||||||