lib/Digest/xxHash.pm

filter: Statementstmt 100% 62 / 62 Branchbran 87.5% 7 / 8 Conditioncond 75.0% 3 / 4 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 16 / 16 Podpod 100% 8 / 8 totaltotal 97.0% 97 / 100 CC 8 SCAR 7.6
CC
8
Cov
97%
new
5.0
DESTROY
2.0
_init
2.0
CRAP 2.1
↑ Summary ext/perl_math_int64/perl_math_int64.c »
1 package Digest::xxHash;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base qw[Exporter];
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 our $VERSION = '3.00';
10 1 XSLoader::load __PACKAGE__, $VERSION;
11 }
12 1 our @EXPORT_OK = qw[
13 xxhash32 xxhash32_hex
14 xxhash64 xxhash64_hex
15 xxh3_64 xxh3_64_hex
16 xxh3_128 xxh3_128_hex
17 xxh3_generate_secret
18 ];
19 3 ▶sub xxh3_generate_secret { xxh3_generate_secret_from_seed(@_) }
Subroutine xxh3_generate_secret: called CC=1 SCAR=0.0
Pod documented
20 1 my %TYPE_CODES = ( xxh32 => 0, xxh64 => 1, xxh3_64 => 2, xxh3_128 => 3 );
21  
22 44 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
23 44 my ( $class, %args ) = @_;
24 44 ▶ my $type = delete $args{type} // 'xxh32';
Condition50%1/2
delete $args{"type"} // "xxh32"
l!l
440
MC/DC0%0/1
delete $args{"type"} // "xxh32"
delete $args{"type"}
Truth table50%1/2
A
A= delete $args{"type"}
Aresult
11
00
25 44 ▶ my $seed = delete $args{seed} // 0;
Condition100%2/2
delete $args{"seed"} // 0
l!l
404
MC/DC100%1/1
delete $args{"seed"} // 0
delete $args{"seed"}
Truth table100%2/2
A
A= delete $args{"seed"}
Aresult
11
00
26 44 my $secret = delete $args{secret};
27 44 ▶ if (%args) {
Branch: 1 branch
BranchTrueFalseTotal
if (%args) 1 43 44
28 1 require Carp;
29 1 Carp::croak( 'Unknown arguments: ' . join( ', ', sort keys %args ) );
30 }
31 43 my $type_code = $TYPE_CODES{$type};
32 43 ▶ unless ( defined $type_code ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $type_code) 1 42 43
33 1 require Carp;
34 1 Carp::croak("Unknown hash type: $type");
35 }
36 42 my $self = bless { type => $type, type_code => $type_code, seed => $seed, secret => $secret }, $class;
37 42 $self->_init;
38 42 return $self;
39 }
40  
41 46 ▶sub _init {
Subroutine _init: called CC=2 SCAR=6.9
42 46 my ($self) = @_;
43 46 $self->{ctx} = _xxxh_create( $self->{type_code} );
44 46 ▶ if ( defined $self->{secret} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'secret'}) { } 2 44 46
45 2 _xxxh_reset_withSecret( $self->{ctx}, $self->{type_code}, $self->{secret} );
46 }
47 else {
48 44 _xxxh_reset( $self->{ctx}, $self->{type_code}, $self->{seed} );
49 }
50 }
51  
52 396 ▶sub add {
Subroutine add: called CC=2 SCAR=6.9
Pod documented
53 396 my ( $self, @etc ) = @_;
54 396 my $ctx = $self->{ctx};
55 396 my $tc = $self->{type_code};
56 396 _xxxh_update( $ctx, $_, $tc ) for @etc;
57 396 return $self;
58 }
59 1 ▶sub digest { return _xxxh_digest( $_[0]->{ctx}, $_[0]->{type_code} ) }
Subroutine digest: called CC=1 SCAR=0.0
Pod documented
60 54 ▶sub hexdigest { return _xxxh_hex( $_[0]->{ctx}, $_[0]->{type_code} ) }
Subroutine hexdigest: called CC=1 SCAR=0.0
Pod documented
61  
62 1 ▶sub b64digest {
Subroutine b64digest: called CC=1 SCAR=0.0
Pod documented
63 1 require MIME::Base64;
64 1 return MIME::Base64::encode_base64( $_[0]->digest, '' );
65 }
66  
67 2 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
68 2 my ($self) = @_;
69 2 my $clone = bless {%$self}, ref($self);
70 2 my $tc = $clone->{type_code};
71 2 $clone->{ctx} = _xxxh_create($tc);
72 2 _xxxh_copy( $clone->{ctx}, $self->{ctx}, $tc );
73 2 return $clone;
74 }
75  
76 4 ▶sub reset {
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
77 4 my ($self) = @_;
78 4 $self->_init;
79 4 return $self;
80 }
81  
82 44 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.0
83 44 my ($self) = @_;
84 44 ▶ return unless defined $self->{ctx};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"ctx"} 0 44 44
85 44 _xxxh_free( $self->{ctx}, $self->{type_code} );
86 44 delete $self->{ctx};
87 }
88 1 1;
↑ Summary ext/perl_math_int64/perl_math_int64.c »