Same/ChunkPair.pm

filter: Statementstmt 87.1% 27 / 31 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.0% 9 / 10 Podpod 100% 6 / 6 totaltotal 75.4% 46 / 61 CC 5 SCAR 11.9
CC
5
Cov
76%
new
7.2
as_string
2.0
BEGIN
1.0
CRAP 3.3
« Same/MatchMap.pm ↑ Summary Same/Util.pm »
1 =head1 NAME
2  
3 Text::Same::ChunkPair
4  
5 =head1 DESCRIPTION
6  
7 A class representing a pair of chunk indexes (generally line numbers)
8  
9 =head1 SYNOPSIS
10  
11 my $pair = new Text::Same::ChunkPair($chunk_index1, $chunk_index2);
12  
13 =head1 METHODS
14  
15 See below. Methods private to this module are prefixed by an
16 underscore.
17  
18 =cut
19  
20 package Text::Same::ChunkPair;
21  
22 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 4 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 $VERSION = '0.07';
28  
29 =head2 new
30  
31 Title : new
32 Usage : $pair = new Text::Same::ChunkPair($chunk_index1, $chunk_index2);
33 Function: Creates a new ChunkPair object from two chunk indexes
34 Returns : A Text::Same::ChunkPair object
35 Args : two chunk indexes
36  
37 =cut
38  
39 sub new
40 313 ▶{
Subroutine new: called CC=5 SCAR=19.7
Pod documented
41 313 my $self = shift;
42 313 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
03130
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
43  
44 313 ▶ if (scalar(@_) != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ != 2) 0 313 313
45 0 die "ChunkPair constructor needs 2 integer arguments\n";
46 }
47  
48 313 ▶ if (!defined $_[0] || !defined $_[1]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[0] and defined $_[1]) 0 313 313
Condition33%1/3
defined $_[0] and defined $_[1]
!ll&&!rl&&r
00313
MC/DC0%0/2
defined $_[0] and defined $_[1]
defined $_[0] defined $_[1]
Truth table33%1/3
A and B
A= defined $_[0]B= defined $_[1]
ABresult
0X0
100
111
49 0 croak "undefined value passed to ChunkPair->new\n";
50 }
51  
52 313 my $packed_pair = make_packed_pair(@_);
53  
54 313 return bless \$packed_pair, $class;
55 }
56  
57 =head2 chunk_index1
58  
59 Title : chunk_index1
60 Usage : my $chunk_index = $pair->chunk_index1;
61 Function: return the first chunk_index of this ChunkPair
62 Args : none
63  
64 =cut
65  
66 sub chunk_index1
67 313 ▶{
Subroutine chunk_index1: called CC=1 SCAR=0.0
Pod documented
68 313 my $self = shift;
69 313 return (unpack 'II', $$self)[0];
70 }
71  
72 =head2 chunk_index2
73  
74 Title : chunk_index2
75 Usage : my $chunk_index = $pair->chunk_index2;
76 Function: return the second chunk_index of this ChunkPair
77 Args : none
78  
79 =cut
80  
81 sub chunk_index2
82 313 ▶{
Subroutine chunk_index2: called CC=1 SCAR=0.0
Pod documented
83 313 my $self = shift;
84 313 return (unpack 'II', $$self)[1];
85 }
86  
87 =head2 packed_pair
88  
89 Title : packed_pair
90 Usage : my $packed_pair = $chunk_pair->packed_pair();
91 Function: return a packed representation of this ChunkPair by pack()ing
92 index1 and index2 into a string
93 Args : none
94  
95 =cut
96  
97 sub packed_pair
98 313 ▶{
Subroutine packed_pair: called CC=1 SCAR=0.0
Pod documented
99 313 my $self = shift;
100 313 return $$self;
101 }
102  
103 =head2 make_packed_pair
104  
105 Title : make_packed_pair
106 Usage : my $packed_pair = $chunk_pair->make_packed_pair($index1, $index2);
107 Function: return a packed representation of the pair of indexes by pack()ing
108 them into a string
109 Args : two indexes
110  
111 =cut
112  
113 sub make_packed_pair
114 519 ▶{
Subroutine make_packed_pair: called CC=1 SCAR=0.0
Pod documented
115 519 return pack 'II', @_;
116 }
117  
118 =head2 as_string
119  
120 Title : as_string
121 Usage : my $str = $match->as_string
122 Function: return a string representation of this ChunkPair
123 Args : none
124  
125 =cut
126  
127 sub as_string
128 0 ▶{
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
129 0 my $self = shift;
130 0 return $self->chunk_index1 . "<->" . $self->chunk_index2;
131 }
132  
133 =head1 AUTHOR
134  
135 Kim Rutherford <kmr+same@xenu.org.uk>
136  
137 =head1 COPYRIGHT & LICENSE
138  
139 Copyright 2005,2006 Kim Rutherford. All rights reserved.
140  
141 This program is free software; you can redistribute it and/or modify it
142 under the same terms as Perl itself.
143  
144 =head1 DISCLAIMER
145  
146 This module is provided "as is" without warranty of any kind. It
147 may redistributed under the same conditions as Perl itself.
148  
149 =cut
150  
151 4 1;
« Same/MatchMap.pm ↑ Summary Same/Util.pm »