blib/lib/Text/Editor/Vip/Buffer/Plugins/Tags.pm

filter: Statementstmt 100% 98 / 98 Branchbran 80.0% 40 / 50 Conditioncond 65.1% 43 / 66 MC/DCmcdc 40.0% 14 / 35 Subroutinesub 100% 14 / 14 Podpod 100% 9 / 9 totaltotal 80.1% 218 / 272 CC 48 SCAR 18.5
CC
48
Cov
85%
GotoNextTag
9.0
GotoNamedTag
8.0
GotoPreviousTag
7.2
CRAP 6.4
« blib/lib/Text/Editor/Vip/Buffer/Selection.pm ↑ Summary lib/Text/Editor/Vip/Buffer/Plugins/Clipboard.pm »
1  
2 package Text::Editor::Vip::Buffer::Plugins::Tags ;
3  
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 BEGIN
8 1 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 $VERSION = 0.01;
13 1 @ISA = qw (Exporter);
14 1 @EXPORT = qw ();
15 1 @EXPORT_OK = qw ();
16 1 %EXPORT_TAGS = ();
17 }
18  
19 =head1 NAME
20  
21 Text::Editor::Vip::Buffer::Plugins::Tags- Tagging functionality plugin for Vip::Buffer
22  
23 =head1 SYNOPSIS
24  
25 use 'Text::Editor::Vip::Buffer';
26  
27 my $buffer = new Text::Editor::Vip::Buffer() ;
28 $buffer->LoadAndExpandWith('Text::Editor::Vip::Buffer::Plugins::Tags') ;
29  
30 $buffer->SetTagAtLine('debug', 10) ;
31 ...
32 $buffer->GotoNextTag('debug', 0) ;
33
34 =head1 DESCRIPTION
35  
36 Tagging functionality plugin for Vip::Buffer
37  
38 =head1 FUNCTIONS
39  
40 =cut
41  
42 #-------------------------------------------------------------------------------
43  
44 sub SetTagAtLine
45 4 ▶{
Subroutine SetTagAtLine: called CC=5 SCAR=16.1
Pod documented
46  
47 =head2 SetTagAtLine
48  
49 $buffer->SetTagAtLine($class, $line) ;
50  
51 Sets a tag of class '$class' (a string) at the passed line.
52  
53 Multiple tags of different classes can be set at the same line. The tags are deleted is the line is deleted.
54  
55 =cut
56  
57 4 my $buffer = shift ;
58 4 my $tag_class = shift ;
59 4 my $line_index = shift ;
60 4 ▶$line_index = $buffer->GetModificationLine() unless defined $line_index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line_index 1 3 4
61  
62 4 ▶if(defined $tag_class && $tag_class ne '' && $line_index < $buffer->GetNumberOfLines())
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag_class and $tag_class ne "" and $line_index < $buffer->GetNumberOfLines) 2 2 4
Condition83%5/6
defined $tag_class and $tag_class ne "" and $line_index < $buffer->GetNumberOfLines
!ll&&!rl&&r
112
defined $tag_class and $tag_class ne ""
!ll&&!rl&&r
103
MC/DC66%2/3
defined $tag_class and $tag_class ne "" and $line_index < $buffer->GetNumberOfLines
defined $tag_class $tag_class ne "" $line_index < $buffer->GetNumberOfLines
Truth table75%3/4
A and B and C
A= defined $tag_classB= $tag_class ne ""C= $line_index < $buffer->GetNumberOfLines
ABCresult
0XX0
10X0
1100
1111
63 {
64 2 my $line = $buffer->GetLine($line_index) ;
65 2 $line->{TAGS}{$tag_class} = 1 ;
66 } ;
67 }
68  
69 #-------------------------------------------------------------------------------
70  
71 sub ClearTagAtLine
72 1 ▶{
Subroutine ClearTagAtLine: called CC=5 SCAR=18.1
Pod documented
73  
74 =head2 ClearTagAtLine
75  
76 $buffer->ClearTagAtLine($class, $line) ;
77  
78 =cut
79  
80 1 my $buffer = shift ;
81 1 my $tag_class = shift ;
82 1 my $line_index = shift ;
83 1 ▶$line_index = $buffer->GetModificationLine() unless defined $line_index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line_index 0 1 1
84  
85 1 ▶if(defined $tag_class && $tag_class ne '' && $line_index < $buffer->GetNumberOfLines())
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag_class and $tag_class ne "" and $line_index < $buffer->GetNumberOfLines) 1 0 1
Condition33%2/6
defined $tag_class and $tag_class ne "" and $line_index < $buffer->GetNumberOfLines
!ll&&!rl&&r
001
defined $tag_class and $tag_class ne ""
!ll&&!rl&&r
001
MC/DC0%0/3
defined $tag_class and $tag_class ne "" and $line_index < $buffer->GetNumberOfLines
defined $tag_class $tag_class ne "" $line_index < $buffer->GetNumberOfLines
Truth table25%1/4
A and B and C
A= defined $tag_classB= $tag_class ne ""C= $line_index < $buffer->GetNumberOfLines
ABCresult
0XX0
10X0
1100
1111
86 {
87 1 my $line = $buffer->GetLine($line_index) ;
88  
89 1 delete $line->{TAGS}{$tag_class} ;
90 } ;
91 }
92  
93 #-------------------------------------------------------------------------------
94  
95 sub GotoNextTag
96 4 ▶{
Subroutine GotoNextTag: called CC=8 SCAR=22.0
Pod documented
97  
98 =head2 GotoNextTag
99  
100 $buffer->GotoNextTag($class, $start_line) ;
101  
102 =cut
103  
104 4 my $buffer = shift ;
105 4 my $tag_class = shift ;
106 4 my $start_line_index = shift ;
107  
108 4 ▶$start_line_index = $buffer->GetModificationLine() unless defined $start_line_index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start_line_index 4 0 4
109  
110 4 my $number_of_lines = $buffer->GetNumberOfLines() ;
111  
112 4 ▶if(defined $tag_class && $tag_class ne '' && $start_line_index < $number_of_lines)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag_class and $tag_class ne "" and $start_line_index < $number_of_lines) 4 0 4
Condition33%2/6
defined $tag_class and $tag_class ne "" and $start_line_index < $number_of_lines
!ll&&!rl&&r
004
defined $tag_class and $tag_class ne ""
!ll&&!rl&&r
004
MC/DC0%0/3
defined $tag_class and $tag_class ne "" and $start_line_index < $number_of_lines
defined $tag_class $tag_class ne "" $start_line_index < $number_of_lines
Truth table25%1/4
A and B and C
A= defined $tag_classB= $tag_class ne ""C= $start_line_index < $number_of_lines
ABCresult
0XX0
10X0
1100
1111
113 {
114 4 ▶ for(my $line_index = $start_line_index + 1 ; $line_index < $number_of_lines ; $line_index++)
Branch: 1 branch
BranchTrueFalseTotal
if ($line_index < $number_of_lines) 7 2 9
115 {
116 7 my $line = $buffer->GetLine($line_index) ;
117
118 7 ▶ if(defined $line->{TAGS}{$tag_class} && 1 == $line->{TAGS}{$tag_class})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line->{"TAGS"}{$tag_class} and 1 == $line->{"TAGS"}{$tag_class}) 2 5 7
Condition66%2/3
defined $line->{"TAGS"}{$tag_class} and 1 == $line->{"TAGS"}{$tag_class}
!ll&&!rl&&r
502
MC/DC50%1/2
defined $line->{"TAGS"}{$tag_class} and 1 == $line->{"TAGS"}{$tag_class}
defined $line->{"TAGS"}{$tag_class} 1 == $line->{"TAGS"}{$tag_class}
Truth table66%2/3
A and B
A= defined $line->{"TAGS"}{$tag_class}B= 1 == $line->{"TAGS"}{$tag_class}
ABresult
0X0
100
111
119 {
120 2 $buffer->SetModificationLine($line_index) ;
121 2 return($line_index) ;
122 }
123 }
124 }
125 }
126  
127 #-------------------------------------------------------------------------------
128  
129 sub GotoPreviousTag
130 6 ▶{
Subroutine GotoPreviousTag: called CC=7 SCAR=19.8
Pod documented
131  
132 =head2 GotoPreviousTag
133  
134 $buffer->GotoPreviousTag($class, $start_line) ;
135  
136 =cut
137  
138 6 my $buffer = shift ;
139 6 my $tag_class = shift ;
140 6 my $start_line_index = shift ;
141 6 ▶$start_line_index = $buffer->GetModificationLine() unless defined $start_line_index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start_line_index 6 0 6
142  
143 6 ▶if(defined $tag_class && $tag_class ne '')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag_class and $tag_class ne "") 6 0 6
Condition33%1/3
defined $tag_class and $tag_class ne ""
!ll&&!rl&&r
006
MC/DC0%0/2
defined $tag_class and $tag_class ne ""
defined $tag_class $tag_class ne ""
Truth table33%1/3
A and B
A= defined $tag_classB= $tag_class ne ""
ABresult
0X0
100
111
144 {
145 6 ▶ for(my $line_index = $start_line_index - 1 ; $line_index >= 0 ; $line_index--)
Branch: 1 branch
BranchTrueFalseTotal
if ($line_index >= 0) 10 1 11
146 {
147 10 my $line = $buffer->GetLine($line_index) ;
148
149 10 ▶ if(defined $line->{TAGS}{$tag_class} && 1 == $line->{TAGS}{$tag_class})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line->{"TAGS"}{$tag_class} and 1 == $line->{"TAGS"}{$tag_class}) 5 5 10
Condition100%3/3
defined $line->{"TAGS"}{$tag_class} and 1 == $line->{"TAGS"}{$tag_class}
!ll&&!rl&&r
415
MC/DC100%2/2
defined $line->{"TAGS"}{$tag_class} and 1 == $line->{"TAGS"}{$tag_class}
defined $line->{"TAGS"}{$tag_class} 1 == $line->{"TAGS"}{$tag_class}
Truth table100%3/3
A and B
A= defined $line->{"TAGS"}{$tag_class}B= 1 == $line->{"TAGS"}{$tag_class}
ABresult
0X0
100
111
150 {
151 5 $buffer->SetModificationLine($line_index) ;
152 5 return($line_index) ;
153 }
154 }
155 }
156 }
157  
158 #-------------------------------------------------------------------------------
159  
160 sub FlipTagAtLine
161 3 ▶{
Subroutine FlipTagAtLine: called CC=7 SCAR=19.8
Pod documented
162  
163 =head2 FlipTagAtLine
164  
165 $buffer->FlipTagAtLine($class, $line) ;
166  
167 Sets a tag at the given line if not already set; in that case the tag is removed.
168  
169 =cut
170  
171 3 my $buffer = shift ;
172 3 my $tag_class = shift ;
173 3 my $line_index = shift ;
174 3 ▶$line_index = $buffer->GetModificationLine() unless defined $line_index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line_index 0 3 3
175  
176 3 ▶if(defined $tag_class && $tag_class ne '' && $line_index < $buffer->GetNumberOfLines())
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag_class and $tag_class ne "" and $line_index < $buffer->GetNumberOfLines) 2 1 3
Condition66%4/6
defined $tag_class and $tag_class ne "" and $line_index < $buffer->GetNumberOfLines
!ll&&!rl&&r
102
defined $tag_class and $tag_class ne ""
!ll&&!rl&&r
102
MC/DC33%1/3
defined $tag_class and $tag_class ne "" and $line_index < $buffer->GetNumberOfLines
defined $tag_class $tag_class ne "" $line_index < $buffer->GetNumberOfLines
Truth table50%2/4
A and B and C
A= defined $tag_classB= $tag_class ne ""C= $line_index < $buffer->GetNumberOfLines
ABCresult
0XX0
10X0
1100
1111
177 {
178 2 my $line = $buffer->GetLine($line_index) ;
179
180 2 ▶ if(defined $line->{TAGS}{$tag_class} && 1 == $line->{TAGS}{$tag_class})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line->{'TAGS'}{$tag_class} and 1 == $line->{'TAGS'}{$tag_class}) { } 1 1 2
Condition66%2/3
defined $line->{"TAGS"}{$tag_class} and 1 == $line->{"TAGS"}{$tag_class}
!ll&&!rl&&r
101
MC/DC50%1/2
defined $line->{"TAGS"}{$tag_class} and 1 == $line->{"TAGS"}{$tag_class}
defined $line->{"TAGS"}{$tag_class} 1 == $line->{"TAGS"}{$tag_class}
Truth table66%2/3
A and B
A= defined $line->{"TAGS"}{$tag_class}B= 1 == $line->{"TAGS"}{$tag_class}
ABresult
0X0
100
111
181 {
182 1 $line->{TAGS}{$tag_class} = 0 ;
183 }
184 else
185 {
186 1 $line->{TAGS}{$tag_class} = 1 ;
187 }
188 }
189 }
190  
191 #-------------------------------------------------------------------------------
192  
193 sub ClearAllTags
194 1 ▶{
Subroutine ClearAllTags: called CC=4 SCAR=14.2
Pod documented
195  
196 =head2 ClearAllTags
197  
198 =cut
199  
200 1 my $buffer = shift ;
201 1 my $tag_class = shift ;
202  
203 1 ▶if(defined $tag_class && $tag_class ne '')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag_class and $tag_class ne "") 1 0 1
Condition33%1/3
defined $tag_class and $tag_class ne ""
!ll&&!rl&&r
001
MC/DC0%0/2
defined $tag_class and $tag_class ne ""
defined $tag_class $tag_class ne ""
Truth table33%1/3
A and B
A= defined $tag_classB= $tag_class ne ""
ABresult
0X0
100
111
204 {
205 1 my $number_of_lines = $buffer->GetNumberOfLines() ;
206
207 1 ▶ for(my $line_index = 0 ; $line_index < $number_of_lines ; $line_index++)
Branch: 1 branch
BranchTrueFalseTotal
if ($line_index < $number_of_lines) 6 1 7
208 {
209 6 my $line = $buffer->GetLine($line_index) ;
210 6 delete $line->{TAGS}{$tag_class} ;
211 }
212 }
213 }
214  
215 #-------------------------------------------------------------------------------
216  
217 sub AddNamedTag
218 6 ▶{
Subroutine AddNamedTag: called CC=7 SCAR=19.6
Pod documented
219  
220 =head2 AddNamedTag
221  
222 $buffer->AddNamedTag($class, $line, $name) ;
223  
224 Multiple named tags, with different classes, can be set at the same line. The same named tag can
225 be set at multiple line.
226  
227 =cut
228  
229 6 my $buffer = shift ;
230 6 my $tag_class = shift ;
231  
232 6 my $line_index = shift ;
233 6 ▶$line_index = $buffer->GetModificationLine() unless defined $line_index;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line_index 0 6 6
234  
235 6 my $tag_identifier = shift ;
236  
237 6 ▶if(defined $tag_class && $tag_class ne '' && defined $tag_identifier && $tag_identifier ne ''&& $line_index < $buffer->GetNumberOfLines())
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag_class and $tag_class ne "" and defined $tag_identifier and $tag_identifier ne "" and $line_index < $buffer->GetNumberOfLines) 3 3 6
Condition83%10/12
defined $tag_class and $tag_class ne "" and defined $tag_identifier and $tag_identifier ne "" and $line_index < $buffer->GetNumberOfLines
!ll&&!rl&&r
213
defined $tag_class and $tag_class ne "" and defined $tag_identifier and $tag_identifier ne ""
!ll&&!rl&&r
204
defined $tag_class and $tag_class ne "" and defined $tag_identifier
!ll&&!rl&&r
114
defined $tag_class and $tag_class ne ""
!ll&&!rl&&r
105
MC/DC60%3/5
defined $tag_class and $tag_class ne "" and defined $tag_identifier and $tag_identifier ne "" and $line_index < $buffer->GetNumberOfLines
defined $tag_class $tag_class ne "" defined $tag_identifier $tag_identifier ne "" $line_index < $buffer->GetNumberOfLines
Truth table66%4/6
A and B and C and D and E
A= defined $tag_classB= $tag_class ne ""C= defined $tag_identifierD= $tag_identifier ne ""E= $line_index < $buffer->GetNumberOfLines
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
238 {
239 3 my $line = $buffer->GetLine($line_index) ;
240 3 $line->{TAGS}{$tag_class} = $tag_identifier ;
241 } ;
242 }
243  
244 #-------------------------------------------------------------------------------
245  
246 sub GetNamedTags
247 2 ▶{
Subroutine GetNamedTags: called CC=5 SCAR=16.3
Pod documented
248  
249 =head2 GetNamedTags
250  
251 $buffer->GetNamedTags($class) ;
252  
253 Returns a list of array references containing:
254  
255 =over 2
256  
257 =item * the tag name
258  
259 =item * the tag's line
260  
261 =back
262  
263 =cut
264  
265 2 my $buffer = shift ;
266 2 my $tag_class = shift ;
267 2 my @tags ;
268  
269 2 ▶if(defined $tag_class && $tag_class ne '')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag_class and $tag_class ne "") 2 0 2
Condition33%1/3
defined $tag_class and $tag_class ne ""
!ll&&!rl&&r
002
MC/DC0%0/2
defined $tag_class and $tag_class ne ""
defined $tag_class $tag_class ne ""
Truth table33%1/3
A and B
A= defined $tag_classB= $tag_class ne ""
ABresult
0X0
100
111
270 {
271 2 my $number_of_lines = $buffer->GetNumberOfLines() ;
272
273 2 ▶ for(my $line_index = 0 ; $line_index < $number_of_lines ; $line_index++)
Branch: 1 branch
BranchTrueFalseTotal
if ($line_index < $number_of_lines) 12 2 14
274 {
275 12 my $line = $buffer->GetLine($line_index) ;
276
277 12 ▶ if(defined $line->{TAGS}{$tag_class})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line->{"TAGS"}{$tag_class}) 3 9 12
278 {
279 3 push @tags, [$line->{TAGS}{$tag_class}, $line_index] ;
280 }
281 }
282
283 2 return(\@tags) ;
284 }
285 }
286  
287 #-------------------------------------------------------------------------------
288  
289 sub GotoNamedTag
290 6 ▶{
Subroutine GotoNamedTag: called CC=8 SCAR=20.8
Pod documented
291  
292 =head2 GotoNamedTag
293  
294 $buffer->GotoNamedTag($class, $name) ;
295  
296 Sets the modification line at the tags location.
297  
298 =cut
299  
300 6 my $buffer = shift ;
301 6 my $tag_class = shift ;
302 6 my $tag_identifier = shift ;
303  
304 # should we wrap around and allow multiple instance of the same named tag?
305  
306 6 ▶if(defined $tag_class && $tag_class ne '' && defined $tag_identifier && $tag_identifier ne '')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag_class and $tag_class ne "" and defined $tag_identifier and $tag_identifier ne "") 4 2 6
Condition77%7/9
defined $tag_class and $tag_class ne "" and defined $tag_identifier and $tag_identifier ne ""
!ll&&!rl&&r
204
defined $tag_class and $tag_class ne "" and defined $tag_identifier
!ll&&!rl&&r
114
defined $tag_class and $tag_class ne ""
!ll&&!rl&&r
105
MC/DC50%2/4
defined $tag_class and $tag_class ne "" and defined $tag_identifier and $tag_identifier ne ""
defined $tag_class $tag_class ne "" defined $tag_identifier $tag_identifier ne ""
Truth table60%3/5
A and B and C and D
A= defined $tag_classB= $tag_class ne ""C= defined $tag_identifierD= $tag_identifier ne ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
307 {
308 4 my $number_of_lines = $buffer->GetNumberOfLines() ;
309
310 4 ▶ for(my $line_index = 0 ; $line_index < $number_of_lines ; $line_index++)
Branch: 1 branch
BranchTrueFalseTotal
if ($line_index < $number_of_lines) 20 2 22
311 {
312 20 my $line = $buffer->GetLine($line_index) ;
313
314 20 ▶ if(exists $line->{TAGS}{$tag_class} && $line->{TAGS}{$tag_class} eq $tag_identifier)
Branch: 1 branch
BranchTrueFalseTotal
if (exists $line->{"TAGS"}{$tag_class} and $line->{"TAGS"}{$tag_class} eq $tag_identifier) 2 18 20
Condition100%3/3
exists $line->{"TAGS"}{$tag_class} and $line->{"TAGS"}{$tag_class} eq $tag_identifier
!ll&&!rl&&r
1622
MC/DC100%2/2
exists $line->{"TAGS"}{$tag_class} and $line->{"TAGS"}{$tag_class} eq $tag_identifier
exists $line->{"TAGS"}{$tag_class} $line->{"TAGS"}{$tag_class} eq $tag_identifier
Truth table100%3/3
A and B
A= exists $line->{"TAGS"}{$tag_class}B= $line->{"TAGS"}{$tag_class} eq $tag_identifier
ABresult
0X0
100
111
315 {
316 2 $buffer->SetModificationLine($line_index) ;
317 2 return($line_index) ;
318 }
319 }
320 }
321
322 4 return() ;
323 }
324  
325 #-------------------------------------------------------------------------------
326  
327 1 1 ;
328  
329 =head1 AUTHOR
330  
331 Khemir Nadim ibn Hamouda
332 CPAN ID: NKH
333 mailto:nadim@khemir.net
334 http:// no web site
335  
336 =head1 COPYRIGHT
337  
338 This program is free software; you can redistribute
339 it and/or modify it under the same terms as Perl itself.
340  
341 The full text of the license can be found in the
342 LICENSE file included with this module.
343  
344 =cut
« blib/lib/Text/Editor/Vip/Buffer/Selection.pm ↑ Summary lib/Text/Editor/Vip/Buffer/Plugins/Clipboard.pm »