Same/Match.pm

filter: Statementstmt 93.4% 71 / 76 Branchbran 62.5% 10 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 95.0% 19 / 20 Podpod 100% 15 / 15 totaltotal 87.8% 116 / 132 CC 11 SCAR 8.7
CC
11
Cov
86%
_update_stats
6.0
set_min1
2.1
set_min2
2.1
CRAP 2.4
« Same/FileChunkedSource.pm ↑ Summary
1 =head1 NAME
2  
3 Text::Same::Match
4  
5 =head1 DESCRIPTION
6  
7 Objects of this class represent a match between a group of chunks
8 (generally lines) in one source (eg a file) and a group of chunks in
9 another. The "chunks" could potentially be paragraphs or sentences.
10  
11 =head1 SYNOPSIS
12  
13 my @pairs = ($chunk_pair1, $chunk_pair2, ...);
14 my $match = new Text::Same::Match(@pairs);
15  
16 =head1 METHODS
17  
18 See below. Methods private to this module are prefixed by an
19 underscore.
20  
21 =cut
22  
23 package Text::Same::Match;
24  
25 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 4 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 4 $VERSION = '0.07';
31  
32 =head2 new
33  
34 Title : new
35 Usage : $match = new Text::Same::Match(@pairs)
36 Function: Creates a new Match object from an array of ChunkPair objects
37 Returns : A Text::Same::Match object
38 Args : an array of ChunkPair objects
39  
40 =cut
41  
42 sub new
43 107 ▶{
Subroutine new: called CC=2 SCAR=7.0
Pod documented
44 107 my $arg = shift;
45 107 ▶ my $class = ref($arg) || $arg;
Condition33%1/3
ref $arg || $arg
l!l&&r!l&&!r
01070
MC/DC0%0/2
ref $arg || $arg
ref $arg $arg
Truth table33%1/3
A || B
A= ref $argB= $arg
ABresult
1X1
011
000
46  
47 107 my $self = {@_};
48  
49 107 $self->{min1} = 999999999999;
50 107 $self->{max1} = -1;
51 107 $self->{min2} = 999999999999;
52 107 $self->{max2} = -1;
53  
54 107 bless $self, $class;
55 107 $self->_update_stats(@{$self->{pairs}});
56  
57 107 return $self;
58 }
59  
60  
61 =head2 add
62  
63 Title : add
64 Usage : $match->add(@chunk_pairs);
65 Function: add ChunkPair objects to this objects - no checks are made that
66 the new ChunkPairs are ajacent to the current pairs
67 Returns : $self
68 Args : an array of ChunkPair objects
69  
70 =cut
71  
72 sub add
73 206 ▶{
Subroutine add: called CC=1 SCAR=0.0
Pod documented
74 206 my $self = shift;
75 206 $self->_update_stats(@_);
76 206 push @{$self->{pairs}}, @_;
77 206 $self;
78 }
79  
80 =head2 source1
81  
82 Title : source1
83 Usage : my $chunked_source = $match->source1;
84 Function: get the ChunkedSource for the source 1
85 Returns : a ChunkedSource reference
86 Args : none
87  
88 =cut
89  
90 sub source1
91 140 ▶{
Subroutine source1: called CC=1 SCAR=0.0
Pod documented
92 140 my $self = shift;
93 140 return $self->{source1};
94 }
95  
96 =head2 source2
97  
98 Title : source2
99 Usage : my $chunked_source = $match->source2;
100 Function: get the ChunkedSource for the source 2
101 Returns : a ChunkedSource reference
102 Args : none
103  
104 =cut
105  
106 sub source2
107 140 ▶{
Subroutine source2: called CC=1 SCAR=0.0
Pod documented
108 140 my $self = shift;
109 140 return $self->{source2};
110 }
111  
112 sub _update_stats
113 313 ▶{
Subroutine _update_stats: called CC=6 SCAR=18.0
114 313 my $self = shift;
115 313 my @new_pairs = @_;
116  
117 313 for my $chunk_pair (@new_pairs) {
118 313 my $chunk_index1 = $chunk_pair->chunk_index1;
119 313 my $chunk_index2 = $chunk_pair->chunk_index2;
120  
121 313 ▶ if ($chunk_index1 < $self->{min1}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk_index1 < $self->{"min1"}) 107 206 313
122 107 $self->{min1} = $chunk_index1;
123 }
124 313 ▶ if ($chunk_index1 > $self->{max1}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk_index1 > $self->{"max1"}) 313 0 313
125 313 $self->{max1} = $chunk_index1;
126 }
127 313 ▶ if ($chunk_index2 < $self->{min2}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk_index2 < $self->{"min2"}) 107 206 313
128 107 $self->{min2} = $chunk_index2;
129 }
130 313 ▶ if ($chunk_index2 > $self->{max2}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunk_index2 > $self->{"max2"}) 313 0 313
131 313 $self->{max2} = $chunk_index2;
132 }
133 }
134 }
135  
136  
137 =head2 min1
138  
139 Title : min1
140 Usage : $match->min1;
141 Function: return the minimum index of the chunks in the first (ie. left) of
142 the ChunkedSources held in this Match
143 Args : None
144  
145 =cut
146  
147 sub min1
148 319 ▶{
Subroutine min1: called CC=1 SCAR=0.0
Pod documented
149 319 return $_[0]->{min1};
150 }
151  
152 =head2 max1
153  
154 Title : max1
155 Usage : $match->max1;
156 Function: return the maximum index of the chunks in the first (ie. left) of
157 the ChunkedSources held in this Match
158 Args : None
159  
160 =cut
161  
162 sub max1
163 650 ▶{
Subroutine max1: called CC=1 SCAR=0.0
Pod documented
164 650 return $_[0]->{max1};
165 }
166  
167 =head2 min2
168  
169 Title : min2
170 Usage : $match->min2;
171 Function: return the minimum index of the chunks in the second (ie. right) of
172 the ChunkedSources held in this Match
173 Args : None
174  
175 =cut
176  
177 sub min2
178 319 ▶{
Subroutine min2: called CC=1 SCAR=0.0
Pod documented
179 319 return $_[0]->{min2};
180 }
181  
182 =head2 max2
183  
184 Title : max2
185 Usage : $match->max2;
186 Function: return the maximum index of the chunks in the second (ie. right) of
187 the ChunkedSources held in this Match
188 Args : None
189  
190 =cut
191  
192 sub max2
193 653 ▶{
Subroutine max2: called CC=1 SCAR=0.0
Pod documented
194 653 return $_[0]->{max2};
195 }
196  
197 =head2 set_min1
198  
199 Title : set_min1
200 Usage : $match->set_min1;
201 Function: Set the minimum index of the chunks in the first (ie. left) of
202 the ChunkedSources held in this Match
203  
204 =cut
205  
206 sub set_min1
207 107 ▶{
Subroutine set_min1: called CC=2 SCAR=7.4
Pod documented
208 107 my $self = shift;
209 107 my $new_val = shift;
210 107 ▶ if ($new_val > $self->{max1}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_val > $self->{"max1"}) 0 107 107
211 0 die "min greater than max\n";
212 }
213 107 $self->{min1} = $new_val;
214 }
215  
216 =head2 set_min2
217  
218 Title : set_min2
219 Usage : $match->set_min2;
220 Function: Set the minimum index of the chunks in the second (ie. right) of
221 the ChunkedSources held in this Match
222  
223 =cut
224  
225 sub set_min2
226 107 ▶{
Subroutine set_min2: called CC=2 SCAR=7.4
Pod documented
227 107 my $self = shift;
228 107 my $new_val = shift;
229 107 ▶ if ($new_val > $self->{max2}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_val > $self->{"max2"}) 0 107 107
230 0 die "min greater than max\n";
231 }
232 107 $self->{min2} = $new_val;
233 }
234  
235 =head2 set_max1
236  
237 Title : set_max1
238 Usage : $match->set_max1;
239 Function: Set the maximum index of the chunks in the first (ie. left) of
240 the ChunkedSources held in this Match
241  
242 =cut
243  
244 sub set_max1
245 107 ▶{
Subroutine set_max1: called CC=2 SCAR=7.4
Pod documented
246 107 my $self = shift;
247 107 my $new_val = shift;
248 107 ▶ if ($new_val < $self->{min1}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_val < $self->{"min1"}) 0 107 107
249 0 die "min greater than max\n";
250 }
251 107 $self->{max1} = $new_val;
252 }
253  
254 =head2 set_max2
255  
256 Title : set_max2
257 Usage : $match->set_max2;
258 Function: Set the maximum index of the chunks in the second (ie. right) of
259 the ChunkedSources held in this Match
260  
261 =cut
262  
263 sub set_max2
264 107 ▶{
Subroutine set_max2: called CC=2 SCAR=7.4
Pod documented
265 107 my $self = shift;
266 107 my $new_val = shift;
267 107 ▶ if ($new_val < $self->{min2}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_val < $self->{"min2"}) 0 107 107
268 0 die "min greater than max\n";
269 }
270 107 $self->{max2} = $new_val;
271 }
272  
273 =head2 pairs
274  
275 Title : pairs
276 Usage : my @pairs = $match->pairs;
277 Function: return all the ChunkPair objects that have been add()ed to this Match
278 Returns : a List of ChunkPair objects
279 Args : none
280  
281 =cut
282  
283 sub pairs
284 0 ▶{
Subroutine pairs: not called CC=1 SCAR=6.9
Pod documented
285 0 return $_[0]->{pairs};
286 }
287  
288 =head2 score
289  
290 Title : score
291 Usage : $acc = $seq->score;
292 Function: The score of this Match - longer match gives a higher score
293 Returns : int - currently returns the total number of lines this match
294 covers in both files
295 Args : None
296  
297 =cut
298  
299 sub score
300 2 ▶{
Subroutine score: called CC=1 SCAR=0.0
Pod documented
301 2 my $self = shift;
302 2 return $self->{max1} - $self->{min1} + $self->{max2} - $self->{min2} + 2;
303 }
304  
305  
306 =head2 as_string
307  
308 Title : as_string
309 Usage : my $str = $match->as_string
310 Function: return a string representation of this Match
311 Args : none
312  
313 =cut
314  
315 sub as_string
316 35 ▶{
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
317 35 my $self = shift;
318  
319 35 return $self->min1 . ".." . $self->max1 . "==" . $self->min2 . ".." . $self->max2;
320 }
321  
322 =head1 AUTHOR
323  
324 Kim Rutherford <kmr+same@xenu.org.uk>
325  
326 =head1 COPYRIGHT & LICENSE
327  
328 Copyright 2005,2006 Kim Rutherford. All rights reserved.
329  
330 This program is free software; you can redistribute it and/or modify it
331 under the same terms as Perl itself.
332  
333 =head1 DISCLAIMER
334  
335 This module is provided "as is" without warranty of any kind. It
336 may redistributed under the same conditions as Perl itself.
337  
338 =cut
339  
340 4 1;
« Same/FileChunkedSource.pm ↑ Summary