blib/lib/Algorithm/HyperLogLog.pm

filter: Statementstmt 96.0% 49 / 51 Branchbran 61.1% 11 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 100% 3 / 3 totaltotal 87.5% 70 / 80 CC 5 SCAR 8.1
CC
5
Cov
87%
new_from_file
4.2
dump_to_file
2.0
__ANON__
1.3
CRAP 2.2
« blib/lib/Algorithm/HyperLogLog/PP.pm ↑ Summary builder/MyBuilder.pm »
1 package Algorithm::HyperLogLog;
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 our $VERSION = '0.24';
8  
9 7 our $PERL_ONLY;
10 7 ▶if ( !defined $PERL_ONLY ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Algorithm::HyperLogLog::PERL_ONLY) 5 2 7
11 5 ▶ $PERL_ONLY = $ENV{PERL_HLL_PUREPERL} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'PERL_HLL_PUREPERL'} ? : 0 5 5
12 }
13  
14 7 ▶if ( !exists $INC{'Algorithm/HyperLogLog/PP.pm'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $INC{"Algorithm/HyperLogLog/PP.pm"}) 7 0 7
15 7 ▶ if ( !$PERL_ONLY ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Algorithm::HyperLogLog::PERL_ONLY) 5 2 7
16 5 require XSLoader;
17 5 $PERL_ONLY = !eval { XSLoader::load( __PACKAGE__, $VERSION ); };
18 }
19 7 ▶ if ($PERL_ONLY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Algorithm::HyperLogLog::PERL_ONLY) 7 0 7
20 7 require 'Algorithm/HyperLogLog/PP.pm';
21 }
22 }
23  
24 2 ▶sub new_from_file {
Subroutine new_from_file: called CC=4 SCAR=14.3
Pod documented
25 2 my ( $class, $filename ) = @_;
26 2 ▶ open my $fh, '<', $filename or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $filename or die $! 2 0 2
27 0 ▶ my $on_error = sub { close $fh; croak "Invalid dump file($filename)"; };
Subroutine __ANON__: not called CC=1 SCAR=2.6
28  
29 2 binmode $fh;
30 2 my ( @dumpdata, $buf, $readed );
31  
32 # Read register size data
33 2 $readed = read( $fh, $buf, 1 );
34 2 ▶ $on_error->() if $readed != 1;
Branch: 1 branch
BranchTrueFalseTotal
if $readed != 1 0 2 2
35 2 my $k = unpack 'C', $buf;
36  
37 # Read register content data
38 2 my $m = 2**$k;
39 2 $readed = read $fh, $buf, $m;
40 2 ▶ $on_error->() if $readed != $m;
Branch: 1 branch
BranchTrueFalseTotal
if $readed != $m 0 2 2
41 2 close $fh;
42 2 @dumpdata = unpack 'C*', $buf;
43 2 my $self = $class->_new_from_dump( $k, \@dumpdata );
44 2 return $self;
45 }
46  
47 2 ▶sub dump_to_file {
Subroutine dump_to_file: called CC=2 SCAR=6.9
Pod documented
48 2 my ( $self, $filename ) = @_;
49 2 my $k = log( $self->register_size ) / log(2); # Calculate log2(register_size)
50 2 my $dumpdata = $self->_dump_register();
51 2 ▶ open my $fh, '>', $filename or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $filename or die $! 2 0 2
52 2 binmode $fh;
53 2 my $buf = pack 'C', $k;
54 2 print $fh $buf;
55 2 $buf = pack 'C*', @$dumpdata;
56 2 print $fh $buf;
57 2 close $fh;
58 }
59  
60 4 ▶sub XS {
Subroutine XS: called CC=1 SCAR=0.0
Pod documented
61 4 !$PERL_ONLY;
62 }
63  
64 7 1;
65 __END__
« blib/lib/Algorithm/HyperLogLog/PP.pm ↑ Summary builder/MyBuilder.pm »