blib/lib/Text/Editor/Vip/Buffer/List.pm

filter: Statementstmt 76.3% 55 / 72 Branchbran 44.4% 8 / 18 Conditioncond 27.7% 5 / 18 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 92.8% 13 / 14 Podpod 100% 8 / 8 totaltotal 62.6% 89 / 142 CC 16 SCAR 15.4
CC
16
Cov
63%
SetNodeData
12.0
InsertBefore
7.3
DeleteNode
5.0
CRAP 4.7
« blib/lib/Text/Editor/Vip/Buffer/Plugins/InsertConstruct.pm ↑ Summary blib/lib/Text/Editor/Vip/Buffer/DoUndoRedo.pm »
1  
2 package Text::Editor::Vip::Buffer::List;
3  
4 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 19 ▶use warnings ;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 19 ▶use Carp qw(cluck) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 BEGIN
9 19 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 19 $VERSION = 0.01;
13 19 @ISA = qw (Exporter);
14 19 @EXPORT = qw ();
15 19 @EXPORT_OK = qw ();
16 19 %EXPORT_TAGS = ();
17 }
18  
19 =head1 NAME
20  
21 Text::Editor::Vip::Buffer::List - lines container
22  
23 =head1 SYNOPSIS
24  
25 use Text::Editor::Vip::Buffer::List
26  
27 =head1 DESCRIPTION
28  
29 Container class used by B<Text::Editor::Vip::Buffer> to hold the buffers text. Elements aer accessed by index.
30  
31 =head1 MEMBER FUNCTIONS
32  
33 =cut
34  
35 #-------------------------------------------------------------------------------
36  
37 sub new
38 251 ▶{
Subroutine new: called CC=2 SCAR=7.6
Pod documented
39  
40 =head2 new
41  
42 Create an empty container. Takes no arguments.
43  
44 =cut
45  
46 251 my $invocant = shift ;
47 251 ▶my $class = ref($invocant) || $invocant ;
Condition33%1/3
ref $invocant || $invocant
l!l&&r!l&&!r
02510
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant $invocant
Truth table33%1/3
A || B
A= ref $invocantB= $invocant
ABresult
1X1
011
000
48  
49 251 return( bless [], $class );
50 }
51  
52 #-------------------------------------------------------------------------------
53  
54 sub GetNumberOfNodes
55 31457 ▶{
Subroutine GetNumberOfNodes: called CC=1 SCAR=0.0
Pod documented
56  
57 =head2 GetNumberOfNodes
58  
59 Returns the number of contained elements.
60  
61 =cut
62  
63 31457 return(scalar(@{$_[0]})) ;
64 }
65  
66 #-------------------------------------------------------------------------------
67  
68 sub Push
69 252 ▶{
Subroutine Push: called CC=1 SCAR=0.0
Pod documented
70  
71 =head2 Push
72  
73 Adds an element at the end of the the container. Returns it's index.
74  
75 =cut
76  
77 252 push @{$_[0]}, $_[1] ;
78 252 return($#{$_[0]}) ;
79 }
80  
81 #-------------------------------------------------------------------------------
82  
83 sub GetNodeData
84 12686 ▶{
Subroutine GetNodeData: called CC=3 SCAR=13.5
Pod documented
85  
86 =head2 GetNodeData
87  
88 Returns an element or undef if the element doesn't exist.
89  
90 $list = new Text::Editor::Vip::Buffer::List() ;
91 $list->Push(['some_element']) ;
92 my $element = $list->GetNodeData(0) ;
93  
94 =cut
95  
96 12686 my $this = shift ;
97 12686 my $a_node_index = shift ;
98  
99 12686 ▶if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes())
Branch: 1 branch
BranchTrueFalseTotal
if (0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes) { } 12686 0 12686
Condition33%1/3
0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes
!ll&&!rl&&r
0012686
MC/DC0%0/2
0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes
0 <= $a_node_index $a_node_index < $this->GetNumberOfNodes
Truth table33%1/3
A and B
A= 0 <= $a_node_indexB= $a_node_index < $this->GetNumberOfNodes
ABresult
0X0
100
111
100 {
101 12686 return($this->[$a_node_index]) ;
102 }
103 else
104 {
105 0 cluck("$a_node_index is an invalide node index") ;
106 0 return(undef) ;
107 }
108 }
109  
110 #-------------------------------------------------------------------------------
111  
112 sub SetNodeData
113 0 ▶{
Subroutine SetNodeData: not called CC=3 SCAR=24.8
Pod documented
114  
115 =head2 SetNodeData
116  
117 Sets the element at the given index. The element must exist.
118  
119 my $index = 0 ;
120 my $element = [] ;
121 $list->SetNodeData($index, $element) ;
122  
123 =cut
124  
125 0 my $this = shift ;
126 0 my $a_node_index = shift ;
127 0 my $a_node_data = shift ;
128  
129 0 ▶if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes())
Branch: 1 branch
BranchTrueFalseTotal
if (0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes) { } 0 0 0
Condition0%0/3
0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes
!ll&&!rl&&r
000
MC/DC0%0/2
0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes
0 <= $a_node_index $a_node_index < $this->GetNumberOfNodes
Truth table0%0/3
A and B
A= 0 <= $a_node_indexB= $a_node_index < $this->GetNumberOfNodes
ABresult
0X0
100
111
130 {
131 0 $this->[$a_node_index] = $a_node_data ;
132 }
133 else
134 {
135 0 cluck("$a_node_index is an invalide node index") ;
136 0 return(undef) ;
137 }
138  
139 }
140  
141 #-------------------------------------------------------------------------------
142  
143 sub DeleteNode
144 708 ▶{
Subroutine DeleteNode: called CC=4 SCAR=16.1
Pod documented
145  
146 =head2 DeleteNode
147  
148 Removes the lement at the given index. all elements after the given index are shifted up in the list. The element
149 must exist.
150  
151 $list->DeleteNode($index) ;
152  
153 =cut
154  
155 708 my $this = shift ;
156 708 my $a_node_index = shift ;
157  
158 708 ▶if(0 != $this->GetNumberOfNodes())
Branch: 1 branch
BranchTrueFalseTotal
if (0 != $this->GetNumberOfNodes) { } 708 0 708
159 {
160 708 ▶ if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes())
Branch: 1 branch
BranchTrueFalseTotal
if (0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes) { } 708 0 708
Condition33%1/3
0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes
!ll&&!rl&&r
00708
MC/DC0%0/2
0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes
0 <= $a_node_index $a_node_index < $this->GetNumberOfNodes
Truth table33%1/3
A and B
A= 0 <= $a_node_indexB= $a_node_index < $this->GetNumberOfNodes
ABresult
0X0
100
111
161 {
162 splice
163 (
164 708 @{$this}
165 , $a_node_index
166 , 1
167 ) ;
168 }
169 else
170 {
171 0 cluck("$a_node_index is an invalide node index") ;
172 }
173 }
174 else
175 {
176 0 cluck('List is empty, nothing to delete !!') ;
177 }
178 }
179  
180 #-------------------------------------------------------------------------------
181  
182 sub InsertAfter
183 2165 ▶{
Subroutine InsertAfter: called CC=4 SCAR=15.5
Pod documented
184  
185 =head2 InsertAfter
186  
187 Creates and inserts an element in the list after the given index. The element at the given index must exist.
188  
189 $list->InsertAfter($index, $element_data) ;
190  
191 =cut
192  
193 2165 my $this = shift ;
194 2165 my $a_node_index = shift ;
195 2165 my $a_node_data = shift ;
196  
197 2165 ▶if(0 != $this->GetNumberOfNodes())
Branch: 1 branch
BranchTrueFalseTotal
if (0 != $this->GetNumberOfNodes) { } 2165 0 2165
198 {
199 2165 ▶ if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes())
Branch: 1 branch
BranchTrueFalseTotal
if (0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes) { } 2165 0 2165
Condition33%1/3
0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes
!ll&&!rl&&r
002165
MC/DC0%0/2
0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes
0 <= $a_node_index $a_node_index < $this->GetNumberOfNodes
Truth table33%1/3
A and B
A= 0 <= $a_node_indexB= $a_node_index < $this->GetNumberOfNodes
ABresult
0X0
100
111
200 {
201 splice
202 (
203 2165 @{$this}
204 , $a_node_index + 1
205 , 0
206 , $a_node_data
207 ) ;
208
209 2165 return($a_node_index + 1) ;
210 }
211 else
212 {
213 0 cluck("$a_node_index is an invalide node index") ;
214 }
215 }
216 else
217 {
218 0 cluck('List is empty !!') ;
219 }
220 }
221  
222 #-------------------------------------------------------------------------------
223  
224 sub InsertBefore
225 1 ▶{
Subroutine InsertBefore: called CC=5 SCAR=19.8
Pod documented
226  
227 =head2 InsertBefore
228  
229 Creates and inserts an element in the list before the given index. The element at the given index must exist.
230  
231 $list->InsertBefore($index, $element_data) ;
232  
233 =cut
234  
235 1 my ($this, $a_node_index, $a_node_data) = @_ ;
236  
237 1 ▶if(0 != $this->GetNumberOfNodes())
Branch: 1 branch
BranchTrueFalseTotal
if (0 != $this->GetNumberOfNodes) { } 1 0 1
238 {
239 1 ▶ if(0 <= $a_node_index && $a_node_index < $this->GetNumberOfNodes())
Branch: 1 branch
BranchTrueFalseTotal
if (0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes) { } 1 0 1
Condition33%1/3
0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes
!ll&&!rl&&r
001
MC/DC0%0/2
0 <= $a_node_index and $a_node_index < $this->GetNumberOfNodes
0 <= $a_node_index $a_node_index < $this->GetNumberOfNodes
Truth table33%1/3
A and B
A= 0 <= $a_node_indexB= $a_node_index < $this->GetNumberOfNodes
ABresult
0X0
100
111
240 {
241 1 ▶ if(0 == $a_node_index)
Branch: 1 branch
BranchTrueFalseTotal
if (0 == $a_node_index) { } 0 1 1
242 {
243 0 unshift @{$this}, $a_node_data ;
244 }
245 else
246 {
247 splice
248 (
249 1 @{$this}
250 , $a_node_index
251 , 0
252 , $a_node_data
253 ) ;
254
255 1 return($a_node_index) ;
256 }
257 }
258 else
259 {
260 0 cluck("$a_node_index is an invalide node index") ;
261 }
262 }
263 else
264 {
265 0 cluck('List is empty !!') ;
266 }
267 }
268  
269 #-------------------------------------------------------------------------------
270  
271 19 1;
272  
273 =head1 AUTHOR
274  
275 Khemir Nadim ibn Hamouda
276 CPAN ID: NKH
277 mailto:nadim@khemir.net
278 http:// no web site
279  
280 =head1 COPYRIGHT
281  
282 This program is free software; you can redistribute
283 it and/or modify it under the same terms as Perl itself.
284  
285 The full text of the license can be found in the
286 LICENSE file included with this module.
287  
288 =cut
« blib/lib/Text/Editor/Vip/Buffer/Plugins/InsertConstruct.pm ↑ Summary blib/lib/Text/Editor/Vip/Buffer/DoUndoRedo.pm »