blib/lib/Text/Trie.pm

filter: Statementstmt 100% 44 / 44 Branchbran 69.2% 18 / 26 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 3 / 3 Podpod 100% 2 / 2 totaltotal 85.8% 73 / 85 CC 19 SCAR 23.9
CC
19
Cov
87%
walkTrie
13.7
Trie
8.0
BEGIN
1.0
CRAP 10.9
↑ Summary
1 package Text::Trie;
2  
3 1 ▶use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 require 5.000;
5 1 require Exporter;
6  
7 1 @ISA = qw(Exporter);
8 1 @EXPORT_OK = qw(Trie walkTrie);
9  
10 1 ▶$step = 1 unless defined $step; # Length of unit. All the arguments should
Branch: 1 branch
BranchTrueFalseTotal
unless defined $step 1 0 1
11 # have length that is multiple of this.
12 # Length of any cell in trie will be multiple
13 # too.
14  
15 8 ▶sub Trie {
Subroutine Trie: called CC=8 SCAR=20.8
Pod documented
16 8 my @list = @_;
17 8 ▶ return shift if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 8 8
18 8 my %first;
19 my @ans;
20 8 foreach (@list) {
21 24 $c = substr $_, 0, $step;
22 24 ▶ $first{$c} = [] unless defined $first{$c};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $first{$c} 17 7 24
23 24 push @{$first{$c}}, $_;
24 }
25 8 foreach (keys %first) {
26 # Find common substring
27 17 my $substr = $first{$_}->[0];
28 17 ▶ (push @ans, $substr), next if @{$first{$_}} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @{$first{$_};} == 1 12 5 17
29 5 $l = length($substr) / $step * $step;
30 5 foreach (@{$first{$_}}) {
31 12 ▶ $l -= $step while substr($_, 0, $l) ne substr($substr, 0, $l);
Branch: 1 branch
BranchTrueFalseTotal
substr($_, 0, $l) ne substr($substr, 0, $l) and do { $l -= $step } 6 12 18
32 }
33 5 $substr = substr $substr, 0, $l;
34 # Return value
35 5 @list = map {substr $_, $l} @{$first{$_}};
36 5 push @ans, [$substr, Trie(@list)];
37 }
38 8 @ans;
39 }
40  
41 8 ▶sub walkTrie {
Subroutine walkTrie: called CC=12 SCAR=26.2
Pod documented
42 8 my ($singlesub,$headsub,$notsinglesub,$sepsub,$opensub,$closesub,@trie) = @_;
43 8 my $num = 0;
44 8 foreach (@trie) {
45 17 ▶ &$sepsub($_) if $num++ and defined $sepsub;
Branch: 1 branch
BranchTrueFalseTotal
if $num++ and defined $sepsub 9 8 17
Condition66%2/3
$num++ and defined $sepsub
!ll&&!rl&&r
809
MC/DC50%1/2
$num++ and defined $sepsub
$num++ defined $sepsub
Truth table66%2/3
A and B
A= $num++B= defined $sepsub
ABresult
0X0
100
111
46 17 ▶ if (defined ref $_ and ref $_ eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined ref $_ and ref $_ eq 'ARRAY') { } 5 12 17
Condition66%2/3
defined ref $_ and ref $_ eq "ARRAY"
!ll&&!rl&&r
0125
MC/DC50%1/2
defined ref $_ and ref $_ eq "ARRAY"
defined ref $_ ref $_ eq "ARRAY"
Truth table66%2/3
A and B
A= defined ref $_B= ref $_ eq "ARRAY"
ABresult
0X0
100
111
47 5 ▶ &$opensub($_) if defined $opensub;
Branch: 1 branch
BranchTrueFalseTotal
if defined $opensub 5 0 5
48 5 ▶ &$headsub(@$_[0]) if defined $headsub;
Branch: 1 branch
BranchTrueFalseTotal
if defined $headsub 5 0 5
49 5 ▶ if ($#$_ > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->$#* > 1) 5 0 5
50 5 ▶ &$notsinglesub($_) if defined $notsinglesub;
Branch: 1 branch
BranchTrueFalseTotal
if defined $notsinglesub 5 0 5
51 walkTrie($singlesub, $headsub, $notsinglesub, $sepsub, $opensub,
52 5 $closesub, @{$_}[1 .. $#$_]);
53 }
54 5 ▶ &$closesub($_) if defined $closesub;
Branch: 1 branch
BranchTrueFalseTotal
if defined $closesub 5 0 5
55 } else {
56 12 ▶ &$singlesub($_) if defined $singlesub;
Branch: 1 branch
BranchTrueFalseTotal
if defined $singlesub 12 0 12
57 }
58 }
59 }
60  
61 1 1;
62 __END__
↑ Summary