blib/lib/Text/EditTranscript.pm

filter: Statementstmt 100% 61 / 61 Branchbran 83.3% 30 / 36 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 90.5% 105 / 116 CC 21 SCAR 23.0
CC
21
Cov
93%
Traceback
12.9
EditTranscript
10.0
BEGIN
1.0
CRAP 10.0
↑ Summary
1 package Text::EditTranscript;
2  
3 1 ▶use 5.008006;
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  
7 1 require Exporter;
8  
9 1 our @ISA = qw(Exporter);
10  
11 # Items to export into callers namespace by default. Note: do not export
12 # names by default without a very good reason. Use EXPORT_OK instead.
13 # Do not simply export all your public functions/methods/constants.
14  
15 # This allows declaration use Text::EditTranscript ':all';
16 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
17 # will save memory.
18 1 our %EXPORT_TAGS = ( 'all' => [ qw(
19
20 ) ] );
21  
22 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
23  
24 1 our @EXPORT = qw(
25 EditTranscript
26 );
27  
28 1 our $VERSION = '0.07';
29  
30  
31 4 ▶sub EditTranscript {
Subroutine EditTranscript: called CC=10 SCAR=23.0
Pod undocumented
32 4 my $str = shift;
33 4 my $str2 = shift;
34  
35 4 my $dist;
36 my $transcript;
37 4 ▶ for (my $i = 0; $i <= length($str); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= length $str) 260 4 264
38 260 $dist->[$i]->[0] = $i;
39 260 $transcript->[$i]->[0] = "D";
40 }
41 4 ▶ for (my $i = 0; $i <= length($str2); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= length $str2) 260 4 264
42 260 $dist->[0]->[$i] = $i;
43 260 $transcript->[0]->[$i] = "I";
44 }
45  
46  
47 4 my $cost;
48  
49 4 ▶ for (my $i = 1; $i <= length($str); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= length $str) 256 4 260
50 256 ▶ for (my $j = 1; $j <= length($str2); $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= length $str2) 61036 256 61292
51 61036 ▶ if (substr($str,$i-1,1) eq substr($str2,$j-1,1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($str, $i - 1, 1) eq substr($str2, $j - 1, 1)) { } 5172 55864 61036
52 5172 $cost = 0;
53 }
54 else {
55 55864 $cost = 1;
56 }
57 61036 $dist->[$i]->[$j] = Min($dist->[$i-1]->[$j] + 1,
58 $dist->[$i]->[$j-1] + 1,
59 $dist->[$i-1]->[$j-1] + $cost);
60 61036 ▶ if ($dist->[$i]->[$j] eq $dist->[$i]->[$j-1] + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist->[$i][$j] eq $dist->[$i][$j - 1] + 1) 30391 30645 61036
61 30391 $transcript->[$i]->[$j] = "I";
62 }
63 61036 ▶ if ($dist->[$i]->[$j] eq $dist->[$i-1]->[$j]+1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist->[$i][$j] eq $$dist[$i - 1][$j] + 1) 30370 30666 61036
64 30370 $transcript->[$i]->[$j] = "D";
65 }
66 61036 ▶ if ($dist->[$i]->[$j] eq $dist->[$i-1]->[$j-1] + $cost) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist->[$i][$j] eq $$dist[$i - 1][$j - 1] + $cost) 5646 55390 61036
67 5646 ▶ if ($cost eq 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cost eq 0) { } 5172 474 5646
68 5172 $transcript->[$i]->[$j] = "-";
69 }
70 else {
71 474 $transcript->[$i]->[$j] = "S";
72 }
73 }
74 }
75 }
76  
77 4 my $st = Traceback($transcript,length($str),length($str2));
78 4 $st = scalar reverse $st;
79 4 return $st;
80  
81 }
82  
83 4 ▶sub Traceback {
Subroutine Traceback: called CC=12 SCAR=25.6
Pod undocumented
84 4 my $transcript = shift;
85 4 my $i = shift;
86 4 my $j = shift;
87  
88 4 my $string;
89  
90 4 ▶ while ($i > 0 || $j > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0 or $j > 0) 257 4 261
Condition66%2/3
$i > 0 or $j > 0
l!l&&r!l&&!r
25704
MC/DC50%1/2
$i > 0 or $j > 0
$i > 0 $j > 0
Truth table66%2/3
A or B
A= $i > 0B= $j > 0
ABresult
1X1
011
000
91 257 ▶ if (defined $transcript->[$i]->[$j]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $transcript->[$i][$j]) 257 0 257
92 257 $string .= $transcript->[$i]->[$j];
93 }
94  
95 257 ▶ last if (!defined $transcript->[$i]->[$j]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $transcript->[$i][$j] 0 257 257
96 # to keep us from getting caught in loops
97 257 ▶ if ($transcript->[$i]->[$j] eq "S" || $transcript->[$i]->[$j] eq "-") {
Branch: 2 branches
BranchTrueFalseTotal
if ($transcript->[$i][$j] eq 'S' or $transcript->[$i][$j] eq '-') { } 255 2 257
elsif ($transcript->[$i][$j] eq 'I') { } 1 1 2
Condition100%3/3
$transcript->[$i][$j] eq "S" or $transcript->[$i][$j] eq "-"
l!l&&r!l&&!r
22532
MC/DC100%2/2
$transcript->[$i][$j] eq "S" or $transcript->[$i][$j] eq "-"
$transcript->[$i][$j] eq "S" $transcript->[$i][$j] eq "-"
Truth table100%3/3
A or B
A= $transcript->[$i][$j] eq "S"B= $transcript->[$i][$j] eq "-"
ABresult
1X1
011
000
98 255 ▶ $i-- if ($i > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $i > 0 255 0 255
99 255 ▶ $j-- if ($j > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $j > 0 255 0 255
100 }
101 elsif ($transcript->[$i]->[$j] eq "I") {
102 1 ▶ $j-- if ($j > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $j > 0 1 0 1
103 }
104 else {
105 1 ▶ $i-- if ($i > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $i > 0 1 0 1
106 }
107 }
108  
109 4 return $string;
110 }
111  
112  
113 61036 ▶sub Min {
Subroutine Min: called CC=1 SCAR=0.0
Pod undocumented
114 61036 my @list = @_;
115  
116 61036 @list = sort {$a <=> $b} @list;
117  
118 61036 return shift @list;
119 }
120  
121  
122 1 1;
123 __END__
↑ Summary