blib/lib/Algorithm/LCSS.pm

filter: Statementstmt 100% 75 / 75 Branchbran 100% 26 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod 100% 3 / 3 totaltotal 100% 119 / 119 CC 14 SCAR 11.2
CC
14
Cov
100%
LCSS
7.0
CSS
3.0
__ANON__
2.0
CRAP 3.1
↑ Summary
1 package Algorithm::LCSS;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Algorithm::Diff qw(traverse_sequences);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 require Exporter;
8 1 ▶use vars qw( @ISA @EXPORT_OK $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 our @ISA = qw(Exporter);
10 1 @EXPORT_OK = qw( LCSS CSS CSS_Sorted );
11 1 $VERSION = '0.01';
12  
13 4 ▶sub _tokenize { [split //, $_[0]] }
Subroutine _tokenize: called CC=1 SCAR=0.0
14  
15 4 ▶sub CSS {
Subroutine CSS: called CC=3 SCAR=11.0
Pod documented
16 4 ▶ my $is_array = ref $_[0] eq 'ARRAY' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 2 2 4
17 4 my ( $seq1, $seq2, @match, $from_match );
18 4 my $i = 0;
19 4 ▶ if ( $is_array ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_array) { } 2 2 4
20 2 $seq1 = $_[0];
21 2 $seq2 = $_[1];
22 traverse_sequences( $seq1, $seq2, {
23 26 ▶ MATCH => sub { push @{$match[$i]}, $seq1->[$_[0]]; $from_match = 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
24 26 ▶ DISCARD_A => sub { do{$i++; $from_match = 0} if $from_match },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($from_match) 2 24 26
25 26 ▶ DISCARD_B => sub { do{$i++; $from_match = 0} if $from_match },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($from_match) 4 22 26
26 2 });
27 }
28 else {
29 2 $seq1 = _tokenize($_[0]);
30 2 $seq2 = _tokenize($_[1]);
31 traverse_sequences( $seq1, $seq2, {
32 26 ▶ MATCH => sub { $match[$i] .= $seq1->[$_[0]]; $from_match = 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
33 26 ▶ DISCARD_A => sub { do{$i++; $from_match = 0} if $from_match },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($from_match) 2 24 26
34 26 ▶ DISCARD_B => sub { do{$i++; $from_match = 0} if $from_match },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($from_match) 4 22 26
35 2 });
36 }
37 4 return \@match;
38 }
39  
40 2 ▶sub CSS_Sorted {
Subroutine CSS_Sorted: called CC=2 SCAR=6.9
Pod documented
41 2 my $match = CSS(@_);
42 2 ▶ if ( ref $_[0] eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 1 1 2
43 1 @$match = map{$_->[0]}sort{$b->[1]<=>$a->[1]}map{[$_,scalar(@$_)]}@$match
44 }
45 else {
46 1 @$match = map{$_->[0]}sort{$b->[1]<=>$a->[1]}map{[$_,length($_)]}@$match
47 }
48 2 return $match;
49 }
50  
51 2 ▶sub LCSS {
Subroutine LCSS: called CC=7 SCAR=19.5
Pod documented
52 2 ▶ my $is_array = ref $_[0] eq 'ARRAY' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 1 1 2
53 2 my $css = CSS(@_);
54 2 my $index;
55 2 my $length = 0;
56 2 ▶ if ( $is_array ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_array) { } 1 1 2
57 1 ▶ for( my $i = 0; $i < @$css; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$css) 3 1 4
58 3 ▶ next unless @{$css->[$i]}>$length;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$css->[$i];} > $length 1 2 3
59 2 $index = $i;
60 2 $length = @{$css->[$i]};
61 }
62 }
63 else {
64 1 ▶ for( my $i = 0; $i < @$css; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$css) 3 1 4
65 3 ▶ next unless length($css->[$i])>$length;
Branch: 1 branch
BranchTrueFalseTotal
unless length $css->[$i] > $length 1 2 3
66 2 $index = $i;
67 2 $length = length($css->[$i]);
68 }
69 }
70 2 return $css->[$index];
71 }
72  
73 1 1;
74 __END__
↑ Summary