lib/Text/Editor/Vip/Buffer/Plugins/Clipboard.pm

filter: Statementstmt 95.6% 155 / 162 Branchbran 93.0% 67 / 72 Conditioncond 96.1% 75 / 78 MC/DCmcdc 92.3% 36 / 39 Subroutinesub 95.2% 20 / 21 Podpod 100% 12 / 12 totaltotal 95.0% 365 / 384 CC 63 SCAR 17.1
CC
63
Cov
95%
YankLineToClipboard
8.1
AppendToClipboardContents
7.0
SetClipboardContents
7.0
CRAP 5.5
« blib/lib/Text/Editor/Vip/Buffer/Plugins/Tags.pm ↑ Summary blib/lib/Text/Editor/Vip/Buffer/Plugins/InsertConstruct.pm »
1  
2 package Text::Editor::Vip::Buffer::Plugins::Clipboard ;
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::Clipboard - Internal clipboard handling
22  
23 =head1 SYNOPSIS
24  
25 use Text::Editor::Vip::Buffer ;
26 $buffer = new Text::Editor::Vip::Buffer() ;
27
28 $buffer->LoadAndExpandWith('Text::Editor::Vip::Buffer::Plugins::Clipboard') ;
29
30 =head1 DESCRIPTION
31  
32 Access Text::Editor::Vip::Buffer internal buffers.
33  
34 =head1 Functions
35  
36 =cut
37  
38 #-------------------------------------------------------------------------------------------------------------
39  
40 sub SetClipboardContents
41 11 ▶{
Subroutine SetClipboardContents: called CC=7 SCAR=19.5
Pod documented
42  
43 =head2 SetClipboardContents
44  
45 Sets the content of the named clipboard.
46  
47 B<Arguments:>
48  
49 =over 2
50  
51 =item * clipboard name, a scalar
52  
53 =item * text, a scalar, or an array ref (elements are joined to a single string)
54  
55 =back
56  
57 $buffer->SetClipboardContents(4, 'something') ;
58 $buffer->SetClipboardContents(4, ['something', "\n", 'hi']) ;
59  
60 =cut
61  
62 11 my ($buffer, $clipboard_name, $text_to_insert) = @_ ;
63  
64 11 ▶if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
Branch: 1 branch
BranchTrueFalseTotal
if ("" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name) 3 8 11
Condition100%6/6
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
l!l&&r!l&&!r
218
"" ne ref $clipboard_name or not defined $clipboard_name
l!l&&r!l&&!r
119
MC/DC100%3/3
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
"" ne ref $clipboard_name not defined $clipboard_name "" eq $clipboard_name
Truth table100%4/4
A or not(B) or C
A= "" ne ref $clipboard_nameB= not defined $clipboard_nameC= "" eq $clipboard_name
ABCresult
1XX1
01X1
0011
0000
65 {
66 3 $buffer->PrintError("SetClipboardContents: Invalid clipboard name!") ;
67 3 return(0) ;
68 }
69
70 8 ▶if(@_ != 3)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 3) 1 7 8
71 {
72 1 $buffer->PrintError("SetClipboardContents: wrong number of arguments!") ;
73 1 return(0) ;
74 }
75  
76 7 ▶$text_to_insert ='' unless defined $text_to_insert ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text_to_insert 0 7 7
77 7 my @text_to_insert ;
78  
79 7 ▶if(ref($text_to_insert) eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $text_to_insert eq 'ARRAY') { } 1 6 7
80 {
81 1 @text_to_insert = @$text_to_insert ;
82 }
83 else
84 {
85 6 @text_to_insert = ($text_to_insert) ;
86 }
87  
88 #~ $buffer->{CLIPBOARDS}{$clipboard_name} = join('', @text_to_insert) ;
89  
90 7 $buffer->{CLIPBOARDS}{$clipboard_name} = [@text_to_insert] ;
91 }
92  
93 #-------------------------------------------------------------------------------------------------------------
94  
95 sub GetClipboardContents
96 41 ▶{
Subroutine GetClipboardContents: called CC=6 SCAR=18.0
Pod documented
97  
98 =head2 GetClipboardContents
99  
100 Returns the contents of the named clipboard.
101  
102 B<Arguments:>
103  
104 =over 2
105  
106 =item * clipboard name
107  
108 =back
109  
110 $buffer->GetClipboardContents(4) ;
111  
112 =cut
113  
114 41 my ($buffer, $clipboard_name) = @_ ;
115  
116 41 ▶if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
Branch: 1 branch
BranchTrueFalseTotal
if ("" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name) 1 40 41
Condition66%4/6
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
l!l&&r!l&&!r
1040
"" ne ref $clipboard_name or not defined $clipboard_name
l!l&&r!l&&!r
0140
MC/DC33%1/3
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
"" ne ref $clipboard_name not defined $clipboard_name "" eq $clipboard_name
Truth table50%2/4
A or not(B) or C
A= "" ne ref $clipboard_nameB= not defined $clipboard_nameC= "" eq $clipboard_name
ABCresult
1XX1
01X1
0011
0000
117 {
118 1 $buffer->PrintError("GetClipboardContents: Invalid clipboard name!") ;
119 1 return('') ;
120 }
121  
122 40 ▶if(@_ != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 2) 1 39 40
123 {
124 1 $buffer->PrintError("GetClipboardContents: wrong number of arguments!") ;
125 1 return('') ;
126 }
127  
128 #~ exists $buffer->{CLIPBOARDS}{$clipboard_name} ? $buffer->{CLIPBOARDS}{$clipboard_name} : '' ;
129 39 ▶if(exists $buffer->{CLIPBOARDS}{$clipboard_name})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $buffer->{'CLIPBOARDS'}{$clipboard_name}) { } 32 7 39
130 {
131 return
132 (
133 32 join('', @{$buffer->{CLIPBOARDS}{$clipboard_name}})
134 )
135 }
136 else
137 {
138 7 return('') ;
139 }
140 }
141  
142 #-------------------------------------------------------------------------------------------------------------
143  
144 sub CopySelectionToClipboard
145 12 ▶{
Subroutine CopySelectionToClipboard: called CC=6 SCAR=17.9
Pod documented
146  
147 =head2 CopySelectionToClipboard
148  
149 Makes a copy of the selected text and copies it to the named clipboard.
150  
151 B<Arguments:>
152  
153 =over 2
154  
155 =item * clipboard name
156  
157 =back
158  
159 $buffer->CopySelectionToClipboard('some_clipboard_name') ;
160  
161 =cut
162  
163 12 my ($buffer, $clipboard_name) = @_ ;
164  
165 12 ▶if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
Branch: 1 branch
BranchTrueFalseTotal
if ("" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name) 3 9 12
Condition100%6/6
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
l!l&&r!l&&!r
219
"" ne ref $clipboard_name or not defined $clipboard_name
l!l&&r!l&&!r
1110
MC/DC100%3/3
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
"" ne ref $clipboard_name not defined $clipboard_name "" eq $clipboard_name
Truth table100%4/4
A or not(B) or C
A= "" ne ref $clipboard_nameB= not defined $clipboard_nameC= "" eq $clipboard_name
ABCresult
1XX1
01X1
0011
0000
166 {
167 3 $buffer->PrintError("CopySelectionToClipboard: Invalid clipboard name!") ;
168 3 return(0) ;
169 }
170  
171 9 ▶if(@_ != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 2) 1 8 9
172 {
173 1 $buffer->PrintError("CopySelectionToClipboard: wrong number of arguments!") ;
174 1 return(0) ;
175 }
176  
177 8 ▶if($buffer->IsSelectionEmpty)
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer->IsSelectionEmpty) { } 1 7 8
178 {
179 # do nothing
180 1 return(0) ;
181 }
182 else
183 {
184 $buffer->RunSubOnSelection
185 (
186 sub
187 18 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
188 18 my ($text, $selection_line_index, $modification_character, $original_selection, $buffer) = @_;
189
190 18 ▶ my $add_newline = $selection_line_index != $original_selection->GetEndLine()
Branch: 1 branch
BranchTrueFalseTotal
$selection_line_index != $original_selection->GetEndLine ? : 11 7 18
191 ? "\n"
192 : '' ;
193
194 18 $buffer->AppendToClipboardContents($clipboard_name, $text . $add_newline) ;
195
196 # remember to not modify the line
197 18 $text ;
198 }
199 , sub
200 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
201 0 $buffer->PrintError("Please select text to copy to clipboard '$clipboard_name'.\n") ;
202 }
203 7 ) ;
204
205 7 return(1) ;
206 }
207 }
208  
209 #-------------------------------------------------------------------------------------------------------------
210  
211 sub InsertClipboardContents
212 6 ▶{
Subroutine InsertClipboardContents: called CC=5 SCAR=16.3
Pod documented
213  
214 =head2 InsertClipboardContents
215  
216 Inserts the Contents of the named clipboard into the buffer.
217  
218 B<Arguments:>
219  
220 =over 2
221  
222 =item * clipboard name
223  
224 =back
225  
226 $buffer->InsertClipboardContents('my_clipboard') ;
227  
228 =cut
229  
230 6 my ($buffer, $clipboard_name) = @_ ;
231  
232 6 ▶if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
Branch: 1 branch
BranchTrueFalseTotal
if ("" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name) 3 3 6
Condition100%6/6
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
l!l&&r!l&&!r
213
"" ne ref $clipboard_name or not defined $clipboard_name
l!l&&r!l&&!r
114
MC/DC100%3/3
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
"" ne ref $clipboard_name not defined $clipboard_name "" eq $clipboard_name
Truth table100%4/4
A or not(B) or C
A= "" ne ref $clipboard_nameB= not defined $clipboard_nameC= "" eq $clipboard_name
ABCresult
1XX1
01X1
0011
0000
233 {
234 3 $buffer->PrintError("InsertClipboardContents: Invalid clipboard name!") ;
235 3 return(0) ;
236 }
237  
238 3 ▶if(@_ != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 2) 0 3 3
239 {
240 0 $buffer->PrintError("InsertClipboardContents: wrong number of arguments!") ;
241 0 return(0) ;
242 }
243  
244 #~ $buffer->Insert($buffer->{CLIPBOARDS}{$clipboard_name}) ;
245 3 $buffer->Insert($buffer->GetClipboardContents($clipboard_name)) ;
246  
247 3 return(1) ;
248 }
249  
250 #---------------------------------------------------------------------------------------------
251  
252 sub ClearClipboardContents
253 14 ▶{
Subroutine ClearClipboardContents: called CC=5 SCAR=16.1
Pod documented
254  
255 =head2 ClearClipboardContents
256  
257  
258 B<Arguments:>
259  
260 =over 2
261  
262 =item * clipboard name
263  
264 =back
265  
266 $buffer->ClearClipboardContents('clipboard_1') ;
267  
268 =cut
269  
270 14 my ($buffer, $clipboard_name) = @_ ;
271  
272 14 ▶if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
Branch: 1 branch
BranchTrueFalseTotal
if ("" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name) 4 10 14
Condition100%6/6
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
l!l&&r!l&&!r
3110
"" ne ref $clipboard_name or not defined $clipboard_name
l!l&&r!l&&!r
2111
MC/DC100%3/3
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
"" ne ref $clipboard_name not defined $clipboard_name "" eq $clipboard_name
Truth table100%4/4
A or not(B) or C
A= "" ne ref $clipboard_nameB= not defined $clipboard_nameC= "" eq $clipboard_name
ABCresult
1XX1
01X1
0011
0000
273 {
274 4 $buffer->PrintError("ClearClipboardContents: Invalid clipboard name!") ;
275 4 return(0) ;
276 }
277  
278 10 ▶if(@_ != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 2) 1 9 10
279 {
280 1 $buffer->PrintError("ClearClipboardContents: wrong number of arguments!") ;
281 1 return(0) ;
282 }
283  
284 9 delete $buffer->{CLIPBOARDS}{$clipboard_name} ;
285  
286 9 return(1) ;
287 }
288  
289 #---------------------------------------------------------------------------------------------
290  
291 sub AppendToClipboardContents
292 40 ▶{
Subroutine AppendToClipboardContents: called CC=7 SCAR=19.5
Pod documented
293  
294 =head2 AppendToClipboardContents
295  
296 Adds the text argument to the end of the clipboard.
297  
298 B<Arguments:>
299  
300 =over 2
301  
302 =item * clipboard name, a scalar
303  
304 =item * text, a scalar, or an array ref (elements are joined to a single string)
305  
306 =back
307  
308 $buffer->AppendToClipboardContents('clipboard_2', "some string and a newline\n") ;
309  
310 =cut
311  
312 40 my ($buffer, $clipboard_name, $text_to_insert) = @_ ;
313  
314 40 ▶if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
Branch: 1 branch
BranchTrueFalseTotal
if ("" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name) 2 38 40
Condition83%5/6
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
l!l&&r!l&&!r
1138
"" ne ref $clipboard_name or not defined $clipboard_name
l!l&&r!l&&!r
0139
MC/DC66%2/3
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
"" ne ref $clipboard_name not defined $clipboard_name "" eq $clipboard_name
Truth table75%3/4
A or not(B) or C
A= "" ne ref $clipboard_nameB= not defined $clipboard_nameC= "" eq $clipboard_name
ABCresult
1XX1
01X1
0011
0000
315 {
316 2 $buffer->PrintError("AppendToClipboardContents: Invalid clipboard name!") ;
317 2 return(0) ;
318 }
319  
320 38 ▶if(@_ != 3)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 3) 1 37 38
321 {
322 1 $buffer->PrintError("AppendToClipboardContents: wrong number of arguments!") ;
323 1 return(0) ;
324 }
325  
326 37 ▶$text_to_insert = '' unless defined $text_to_insert ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text_to_insert 0 37 37
327 37 my @text_to_insert ;
328  
329 37 ▶if(ref($text_to_insert) eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $text_to_insert eq 'ARRAY') { } 1 36 37
330 {
331 1 @text_to_insert = @$text_to_insert ;
332 }
333 else
334 {
335 36 @text_to_insert = ($text_to_insert) ;
336 }
337  
338 #~ $buffer->{CLIPBOARDS}{$clipboard_name} .= join('', @text_to_insert) ;
339  
340 37 push @{$buffer->{CLIPBOARDS}{$clipboard_name}}, @text_to_insert ;
341  
342 37 return(1) ;
343 }
344  
345 #-------------------------------------------------------------------------------------------------------------
346  
347 sub PopClipboard
348 7 ▶{
Subroutine PopClipboard: called CC=6 SCAR=17.9
Pod documented
349  
350 =head2 PopClipboard
351  
352 Removes the last entry of a clipboard and returnes it. An error is displayed if the clipboard is empty.
353  
354 B<Arguments:>
355  
356 =over 2
357  
358 =item * clipboard name, a scalar
359  
360 =back
361  
362 $buffer->PopClipboard(4) ;
363  
364 =cut
365  
366 7 my ($buffer, $clipboard_name, $text_to_insert) = @_ ;
367  
368 7 ▶if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
Branch: 1 branch
BranchTrueFalseTotal
if ("" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name) 3 4 7
Condition100%6/6
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
l!l&&r!l&&!r
214
"" ne ref $clipboard_name or not defined $clipboard_name
l!l&&r!l&&!r
115
MC/DC100%3/3
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
"" ne ref $clipboard_name not defined $clipboard_name "" eq $clipboard_name
Truth table100%4/4
A or not(B) or C
A= "" ne ref $clipboard_nameB= not defined $clipboard_nameC= "" eq $clipboard_name
ABCresult
1XX1
01X1
0011
0000
369 {
370 3 $buffer->PrintError("PopClipboard: Invalid clipboard name!") ;
371 3 return(0) ;
372 }
373
374 4 ▶if(@_ != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 2) 1 3 4
375 {
376 1 $buffer->PrintError("PopClipboard: wrong number of arguments!") ;
377 1 return(0) ;
378 }
379  
380 3 ▶if(@{$buffer->{CLIPBOARDS}{$clipboard_name}})
Branch: 1 branch
BranchTrueFalseTotal
if (@{$buffer->{'CLIPBOARDS'}{$clipboard_name};}) { } 2 1 3
381 {
382 2 return( pop @{$buffer->{CLIPBOARDS}{$clipboard_name}} ) ;
383 }
384 else
385 {
386 1 $buffer->PrintError("PopClipboard: clipboard '$clipboard_name' is empty!") ;
387 1 return('') ;
388 }
389 }
390  
391 #-------------------------------------------------------------------------------------------------------------
392  
393 sub GetNumberOfClipboardElements
394 6 ▶{
Subroutine GetNumberOfClipboardElements: called CC=6 SCAR=17.9
Pod documented
395  
396 =head2 GetNumberOfClipboardElements
397  
398 Returns the number of elements in the clipboard, zero if the clipboard doesn't exist.
399  
400 B<Arguments:>
401  
402 =over 2
403  
404 =item * clipboard name, a scalar
405  
406 =back
407  
408 $buffer->GetNumberOfClipboardElements(4) ;
409  
410 =cut
411  
412 6 my ($buffer, $clipboard_name) = @_ ;
413  
414 6 ▶if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
Branch: 1 branch
BranchTrueFalseTotal
if ("" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name) 3 3 6
Condition100%6/6
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
l!l&&r!l&&!r
213
"" ne ref $clipboard_name or not defined $clipboard_name
l!l&&r!l&&!r
114
MC/DC100%3/3
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
"" ne ref $clipboard_name not defined $clipboard_name "" eq $clipboard_name
Truth table100%4/4
A or not(B) or C
A= "" ne ref $clipboard_nameB= not defined $clipboard_nameC= "" eq $clipboard_name
ABCresult
1XX1
01X1
0011
0000
415 {
416 3 $buffer->PrintError("PopClipboard: Invalid clipboard name!") ;
417 3 return(0) ;
418 }
419
420 3 ▶if(@_ != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 2) 1 2 3
421 {
422 1 $buffer->PrintError("PopClipboard: wrong number of arguments!") ;
423 1 return(0) ;
424 }
425  
426 2 ▶if(exists $buffer->{CLIPBOARDS}{$clipboard_name})
Branch: 1 branch
BranchTrueFalseTotal
if (exists $buffer->{'CLIPBOARDS'}{$clipboard_name}) { } 1 1 2
427 {
428 1 return(scalar (@{$buffer->{CLIPBOARDS}{$clipboard_name}})) ;
429 }
430 else
431 {
432 1 return(0) ;
433 }
434 }
435  
436 #-------------------------------------------------------------------------------------------------------------
437  
438 sub YankLineToClipboard
439 11 ▶{
Subroutine YankLineToClipboard: called CC=8 SCAR=20.9
Pod documented
440  
441 =head2 YankLineToClipboard
442  
443 Removes a line from the buffer and adds it to a clipboard
444  
445 B<Arguments:>
446  
447 =over 2
448  
449 =item * line number
450  
451 =item * clipboard name, a scalar
452  
453 =back
454  
455 $buffer->YankLineToClipboard(4, 'clipboard') ;
456  
457 =cut
458  
459 11 my ($buffer, $line, $clipboard_name) = @_ ;
460  
461 11 ▶if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
Branch: 1 branch
BranchTrueFalseTotal
if ("" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name) 4 7 11
Condition100%6/6
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
l!l&&r!l&&!r
317
"" ne ref $clipboard_name or not defined $clipboard_name
l!l&&r!l&&!r
128
MC/DC100%3/3
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
"" ne ref $clipboard_name not defined $clipboard_name "" eq $clipboard_name
Truth table100%4/4
A or not(B) or C
A= "" ne ref $clipboard_nameB= not defined $clipboard_nameC= "" eq $clipboard_name
ABCresult
1XX1
01X1
0011
0000
462 {
463 4 $buffer->PrintError("YankLineToClipboard: Invalid clipboard name!") ;
464 4 return(0) ;
465 }
466
467 7 ▶if(@_ != 3)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 3) 0 7 7
468 {
469 0 $buffer->PrintError("YankLineToClipboard: wrong number of arguments!") ;
470 0 return(0) ;
471 }
472  
473 7 ▶if(! defined $line || $line < 0 || $line > $buffer->GetLastLineIndex())
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $line or $line < 0 or $line > $buffer->GetLastLineIndex) 3 4 7
Condition100%6/6
not defined $line or $line < 0 or $line > $buffer->GetLastLineIndex
l!l&&r!l&&!r
214
not defined $line or $line < 0
l!l&&r!l&&!r
115
MC/DC100%3/3
not defined $line or $line < 0 or $line > $buffer->GetLastLineIndex
not defined $line $line < 0 $line > $buffer->GetLastLineIndex
Truth table100%4/4
not(A) or B or C
A= not defined $lineB= $line < 0C= $line > $buffer->GetLastLineIndex
ABCresult
1XX1
01X1
0011
0000
474 {
475 3 $buffer->PrintError("SetClipboardContents: Invalid line arguments!") ;
476 3 return(0) ;
477 }
478
479 4 $buffer->AppendToClipboardContents($clipboard_name, $buffer->GetLineTextWithNewline($line));
480 4 $buffer->DeleteLine($line) ;
481  
482 4 return(1) ;
483 }
484  
485 #-------------------------------------------------------------------------------------------------------------
486  
487 sub YankSelectionToClipboard
488 9 ▶{
Subroutine YankSelectionToClipboard: called CC=5 SCAR=16.2
Pod documented
489  
490 =head2 YankSelectionToClipboard
491  
492 Removes the current selection from the buffer and adds it to a clipboard
493  
494 B<Arguments:>
495  
496 =over 2
497  
498 =item * clipboard name, a scalar
499  
500 =item * text, a scalar, or an array ref (elements are joined to a single string)
501  
502 =back
503  
504 $buffer->YankSelectionToClipboard('clipboard') ;
505  
506 =cut
507  
508 9 my ($buffer, $clipboard_name) = @_ ;
509  
510 9 ▶if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
Branch: 1 branch
BranchTrueFalseTotal
if ("" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name) 3 6 9
Condition100%6/6
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
l!l&&r!l&&!r
216
"" ne ref $clipboard_name or not defined $clipboard_name
l!l&&r!l&&!r
117
MC/DC100%3/3
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
"" ne ref $clipboard_name not defined $clipboard_name "" eq $clipboard_name
Truth table100%4/4
A or not(B) or C
A= "" ne ref $clipboard_nameB= not defined $clipboard_nameC= "" eq $clipboard_name
ABCresult
1XX1
01X1
0011
0000
511 {
512 3 $buffer->PrintError("YankSelectionToClipboard: Invalid clipboard name!") ;
513 3 return(0) ;
514 }
515
516 6 ▶if(@_ != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 2) 0 6 6
517 {
518 0 $buffer->PrintError("YankSelectionToClipboard: wrong number of arguments!") ;
519 0 return(0) ;
520 }
521  
522 $buffer->RunSubOnSelection
523 (
524 sub
525 8 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
526 8 my ($text, $selection_line_index, $modification_character, $original_selection, $buffer) = @_;
527
528 #~ $buffer->AppendToClipboardContents($clipboard_name, $buffer->GetSelectionText($selection_line_index)) ;
529
530 8 ▶ my $add_newline = $selection_line_index != $original_selection->GetEndLine()
Branch: 1 branch
BranchTrueFalseTotal
$selection_line_index != $original_selection->GetEndLine ? : 4 4 8
531 ? "\n"
532 : '' ;
533
534 8 $buffer->AppendToClipboardContents($clipboard_name, $text . $add_newline) ;
535
536 # remove selection content from buffer
537 8 return(undef) ;
538 }
539 , sub
540 2 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
541 2 $buffer->PrintError("Please select text to yank to clipboard '$clipboard_name'.\n") ;
542 }
543 6 ) ;
544
545 6 return(1) ;
546  
547 }
548  
549 #-------------------------------------------------------------------------------------------------------------
550  
551 sub AppendCurrentLineToClipboardContents
552 6 ▶{
Subroutine AppendCurrentLineToClipboardContents: called CC=5 SCAR=16.1
Pod documented
553  
554 =head2 AppendCurrentLineToClipboardContents
555  
556 Adds the current line to a clipboars
557  
558 B<Arguments:>
559  
560 =over 2
561  
562 =item * clipboard name, a scalar
563  
564 =back
565  
566 $buffer->AppendCurrentLineToClipboardContents(4) ;
567  
568 =cut
569  
570 6 my ($buffer, $clipboard_name) = @_ ;
571  
572 6 ▶if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
Branch: 1 branch
BranchTrueFalseTotal
if ("" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name) 3 3 6
Condition100%6/6
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
l!l&&r!l&&!r
213
"" ne ref $clipboard_name or not defined $clipboard_name
l!l&&r!l&&!r
114
MC/DC100%3/3
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
"" ne ref $clipboard_name not defined $clipboard_name "" eq $clipboard_name
Truth table100%4/4
A or not(B) or C
A= "" ne ref $clipboard_nameB= not defined $clipboard_nameC= "" eq $clipboard_name
ABCresult
1XX1
01X1
0011
0000
573 {
574 3 $buffer->PrintError("AppendCurrentLineToClipboardContents: Invalid clipboard name!") ;
575 3 return(0) ;
576 }
577
578 3 ▶if(@_ != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 2) 1 2 3
579 {
580 1 $buffer->PrintError("AppendCurrentLineToClipboardContents: wrong number of arguments!") ;
581 1 return(0) ;
582 }
583  
584 2 $buffer->AppendToClipboardContents($clipboard_name, $buffer->GetLineTextWithNewline()) ;
585  
586 2 return(1) ;
587 }
588  
589 #-------------------------------------------------------------------------------------------------------------
590  
591 sub AppendSelectionToClipboardContents
592 7 ▶{
Subroutine AppendSelectionToClipboardContents: called CC=6 SCAR=17.9
Pod documented
593  
594 =head2 AppendSelectionToClipboardContents
595  
596 Adds the current selection to a clipboars
597  
598 B<Arguments:>
599  
600 =over 2
601  
602 =item * clipboard name, a scalar
603  
604 =back
605  
606 $buffer->AppendSelectionToClipboardContents(4, 'clipboard') ;
607  
608 =cut
609  
610 7 my ($buffer, $clipboard_name) = @_ ;
611  
612 7 ▶if('' ne ref $clipboard_name || ! defined $clipboard_name || '' eq $clipboard_name)
Branch: 1 branch
BranchTrueFalseTotal
if ("" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name) 3 4 7
Condition100%6/6
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
l!l&&r!l&&!r
214
"" ne ref $clipboard_name or not defined $clipboard_name
l!l&&r!l&&!r
115
MC/DC100%3/3
"" ne ref $clipboard_name or not defined $clipboard_name or "" eq $clipboard_name
"" ne ref $clipboard_name not defined $clipboard_name "" eq $clipboard_name
Truth table100%4/4
A or not(B) or C
A= "" ne ref $clipboard_nameB= not defined $clipboard_nameC= "" eq $clipboard_name
ABCresult
1XX1
01X1
0011
0000
613 {
614 3 $buffer->PrintError("AppendSelectionToClipboardContents: Invalid clipboard name!") ;
615 3 return(0) ;
616 }
617
618 4 ▶if(@_ != 2)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ != 2) 1 3 4
619 {
620 1 $buffer->PrintError("AppendSelectionToClipboardContents: wrong number of arguments!") ;
621 1 return(0) ;
622 }
623  
624 3 ▶unless($buffer->IsSelectionEmpty())
Branch: 1 branch
BranchTrueFalseTotal
if ($buffer->IsSelectionEmpty) { } 1 2 3
625 {
626 2 $buffer->AppendToClipboardContents($clipboard_name, $buffer->GetSelectionText()) ;
627 }
628 else
629 {
630 1 $buffer->PrintError("AppendSelectionToClipboardContents: no selection!") ;
631 }
632  
633 3 return(1) ;
634 }
635  
636 #-------------------------------------------------------------------------------------------------------------
637 1 1 ;
638  
639 =head1 AUTHOR
640  
641 Khemir Nadim ibn Hamouda
642 CPAN ID: NKH
643 mailto:nadim@khemir.net
644 http:// no web site
645  
646 =head1 COPYRIGHT
647  
648 This program is free software; you can redistribute
649 it and/or modify it under the same terms as Perl itself.
650  
651 The full text of the license can be found in the
652 LICENSE file included with this module.
653  
654 =cut
« blib/lib/Text/Editor/Vip/Buffer/Plugins/Tags.pm ↑ Summary blib/lib/Text/Editor/Vip/Buffer/Plugins/InsertConstruct.pm »