blib/lib/Bit/Compare.pm

filter: Statementstmt 100% 32 / 32 Branchbran 83.3% 10 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 89.2% 50 / 56 CC 9 SCAR 14.5
CC
9
Cov
91%
bit
6.0
bitcompare
4.1
BEGIN
1.0
CRAP 4.3
↑ Summary
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Bit::Compare;
4 {
5 2 $Bit::Compare::VERSION = '0.001';
6 }
7 #ABSTRACT: Compare two "bit strings", returning differing bits
8  
9 2 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 exports => [ qw/bitcompare bit/ ],
11 groups => {
12 default => [ qw/bitcompare/ ],
13 },
14 2 };
15  
16  
17 3 ▶sub bitcompare {
Subroutine bitcompare: called CC=4 SCAR=14.1
Pod documented
18 3 ▶ if (@_ == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3) 1 2 3
19 1 shift; # remove class/package to support old calling forms
20 }
21 3 my ($s1, $s2) = @_;
22 3 $s1 = bit($s1);
23 3 $s2 = bit($s2);
24 3 ▶ return unless ($s1 and $s2);
Branch: 1 branch
BranchTrueFalseTotal
unless $s1 and $s2 0 3 3
Condition33%1/3
$s1 and $s2
!ll&&!rl&&r
003
MC/DC0%0/2
$s1 and $s2
$s1 $s2
Truth table33%1/3
A and B
A= $s1B= $s2
ABresult
0X0
100
111
25 3 my $v = "" . join("", unpack("c*", $s1 ^ $s2));
26 3 $v =~ s/0//g;
27  
28 3 return length($v);
29 }
30  
31  
32 23 ▶sub bit {
Subroutine bit: called CC=6 SCAR=17.9
Pod documented
33 23 my ($s) = @_;
34 23 ▶ return unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 23 23
35 23 my @a;
36 23 foreach (split(/(.{2})/, $s)) {
37 216 ▶ next unless length("$_") > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless length "$_" > 0 100 116 216
38 116 my $v = hex($_);
39 116 my $b = unpack("B*", pack("C",$v));
40 116 ▶ if (length("$_") == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length "$_" == 1) 16 100 116
41 16 $b = substr($b, -4);
42 }
43 116 push(@a, split(//, $b));
44 }
45 23 ▶ return (wantarray ? @a : join("", @a));
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 16 7 23
46 }
47  
48 2 1;
49  
50 __END__
↑ Summary