Nasmod/Entity.pm

filter: Statementstmt 90.7% 98 / 108 Branchbran 89.4% 34 / 38 Conditioncond 83.3% 10 / 12 MC/DCmcdc 75.0% 6 / 8 Subroutinesub 91.6% 11 / 12 Podpod 88.8% 8 / 9 totaltotal 89.3% 167 / 187 CC 31 SCAR 24.4
CC
31
Cov
90%
match
20.0
sprint
7.0
setComment
4.6
CRAP 11.5
↑ Summary Nasmod.pm »
1 package CAE::Nastran::Nasmod::Entity;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use vars qw($VERSION $DATE);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 $VERSION = '0.26';
8 4 $DATE = 'Fri Apr 25 13:17:31 2014';
9  
10 sub new
11 116 ▶{
Subroutine new: called CC=2 SCAR=7.1
Pod documented
12 116 my $this = shift;
13 116 ▶ my $class = ref($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
01160
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
14 116 my $self={};
15
16 116 $self =
17 {
18 "content" => [],
19 "comment" => [],
20 };
21
22 116 bless ($self, $class);
23 116 return $self;
24 }
25  
26 #---------------------
27 # adds a line to the comment
28 #---------------------
29 sub addComment
30 0 ▶{
Subroutine addComment: not called CC=1 SCAR=6.9
Pod documented
31 0 my $self = shift;
32 0 my $refa_comment = shift;
33  
34 0 push (@{$self->{'comment'}}, @$refa_comment);
35 }
36 #---------------------
37  
38 #---------------------
39 # sets the comment to a certain value
40 # setComment(\@commentlines)
41 # setComment(\@commentlines, $commentline, \@anotherText, ...)
42 #---------------------
43 sub setComment
44 113 ▶{
Subroutine setComment: called CC=4 SCAR=15.2
Pod documented
45 113 my $self = shift;
46  
47 113 undef(@{$self->{'comment'}});
48
49 113 foreach (@_)
50 {
51 36 ▶ if(ref($_) =~ /array/)
Branch: 1 branch
BranchTrueFalseTotal
if (ref($_) =~ /array/) { } 0 36 36
52 {
53 0 foreach my $line (@$_)
54 {
55 0 push (@{$self->{'comment'}}, $line);
56 }
57 }
58 else
59 {
60 36 push (@{$self->{'comment'}}, $_);
61 }
62 }
63 }
64 #---------------------
65  
66 #---------------------
67 # sets a certain column to a certain value
68 # setCol(<int>, <string>)
69 #---------------------
70 sub setCol
71 735 ▶{
Subroutine setCol: called CC=1 SCAR=0.0
Pod documented
72 735 my $self = shift;
73 735 my $col = shift;
74 735 my $string = shift;
75  
76 735 $self->{content}->[$col-1] = $string;
77 }
78 #---------------------
79  
80 #---------------------
81 # get a col
82 # getCol(<int>)
83 # return: <string>
84 #---------------------
85 sub getCol
86 14 ▶{
Subroutine getCol: called CC=2 SCAR=7.4
Pod documented
87 14 my $self = shift;
88 14 my $col = shift;
89
90 14 ▶ if ($self->{content}->[$col-1])
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'content'}[$col - 1]) { } 14 0 14
91 {
92 14 return $self->{content}->[$col-1];
93 }
94 0 else {return""};
95 }
96 #---------------------
97  
98 #---------------------
99 # get all data
100 # getRow()
101 # return: @<string>
102 #---------------------
103 sub getRow
104 1 ▶{
Subroutine getRow: called CC=1 SCAR=0.0
Pod documented
105 1 my $self = shift;
106 1 return @{$self->{'content'}}
107 }
108 #---------------------
109  
110 #---------------------
111 # match an entity to a pattern
112 # es muessen alle filter gefunden werden, sonst undef
113 # falls es fuer einen row einen ganzen array an moeglichkeiten gibt gilt der filter als bestanden, wenn eine moeglichkeit davon matcht
114 #---------------------
115 sub match
116 185 ▶{
Subroutine match: called CC=20 SCAR=30.0
Pod documented
117 185 my $self = shift;
118 185 my $refa_filter = shift;
119  
120 # $self->print();
121 # print "FILTER: ".join("|", @$refa_filter)."\n";
122 # foreach my $column (1..15)
123 # {
124 # print "COLUMN $column: ".$self->getCol($column)."\n";
125 # }
126  
127 185 my @colFilterResults;
128
129 # falls ein filter fuer dem Kommentar gesetzt wurde, wir der vollstaendige kommentar untersucht
130 # falls der filter dort greift wird auf "true" gesetzt.
131 185 ▶ if ($$refa_filter[0])
Branch: 1 branch
BranchTrueFalseTotal
if ($refa_filter->[0]) 32 153 185
132 {
133 32 ▶ if(!(ref($$refa_filter[0]) =~ m/array/i))
Branch: 1 branch
BranchTrueFalseTotal
if (not ref($refa_filter->[0]) =~ /array/i) { } 16 16 32
134 {
135 16 $colFilterResults[0] = "false";
136 16 foreach my $commentzeile (@{$self->{'comment'}})
137 {
138 # print "GREIFT COMMENTFILTER $$refa_filter[0] AN ZEILE $commentzeile\n";
139 5 ▶ if ( $commentzeile =~ m/$$refa_filter[0]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($commentzeile =~ /$refa_filter->[0]/) { } 3 2 5
140 {
141 # print "JA\n";
142 3 $colFilterResults[0] = "true";
143 }
144 else
145 {
146 # print "NEIN\n";
147 }
148 }
149 }
150 else
151 {
152 16 $colFilterResults[0] = "false";
153 16 foreach my $vergleichsString (@{${$refa_filter}[0]})
154 {
155 32 foreach my $commentzeile (@{$self->{'comment'}})
156 {
157 # print "TEST $vergleichsString on comment '" . $commentzeile ."'\n";
158 10 ▶ if ( $commentzeile =~ m/$vergleichsString/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($commentzeile =~ /$vergleichsString/) 7 3 10
159 {
160 # print "RESULT IS TRUE\n";
161 7 $colFilterResults[0] = "true";
162 }
163 }
164 }
165 }
166 }
167  
168 # print "RESULTAFTERCOMMENT: @colFilterResults\n";
169  
170 # falls der kommentarfilter nicht gefunden wurde, kann hier schon undef zurueckgegeben werden
171 185 ▶ if(grep { $_ eq "false"} @colFilterResults) {return undef;}
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "false";} @colFilterResults) 24 161 185
172  
173 # die filter fuer die spalten
174 161 ▶ for(my $x=0, my $col=1; $x<=(@$refa_filter); $x++, $col++)
Branch: 1 branch
BranchTrueFalseTotal
if ($x <= @$refa_filter) 401 111 512
175 {
176 # wenn es fuer die spalte einen filter gibt
177 401 ▶ if ( $$refa_filter[$col] )
Branch: 1 branch
BranchTrueFalseTotal
if ($refa_filter->[$col]) { } 90 311 401
178 {
179 # mit 'false' beginnen
180 90 $colFilterResults[$col] = "false";
181  
182 # und es sich dabei nicht um ein ARRAY handelt
183 # print "IST ES EIN ARRAY? " . $$refa_filter[$row] . "||" .ref($$refa_filter[$row]) ."\n";
184 90 ▶ if(!(ref($$refa_filter[$col]) =~ m/array/i))
Branch: 1 branch
BranchTrueFalseTotal
if (not ref($refa_filter->[$col]) =~ /array/i) { } 70 20 90
185 {
186 # wenn der filter dieses rows greift, dann auf 'true' setzen
187 # print "TESTING CONTENT ". $self->{'content'}->[$x] . " on regex /^". $$refa_filter[$col] . "\$/\n";
188 70 ▶ if (($self->{'content'}->[$x]) && ($self->{'content'}->[$x] =~ /^$$refa_filter[$col]$/))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'content'}[$x] and $self->{'content'}[$x] =~ /^$refa_filter->[$col]$/) { } 25 45 70
Condition100%3/3
$self->{"content"}[$x] and $self->{"content"}[$x] =~ /^$refa_filter->[$col]$/
!ll&&!rl&&r
123325
MC/DC100%2/2
$self->{"content"}[$x] and $self->{"content"}[$x] =~ /^$refa_filter->[$col]$/
$self->{"content"}[$x] $self->{"content"}[$x] =~ /^$refa_filter->[$col]$/
Truth table100%3/3
A and B
A= $self->{"content"}[$x]B= $self->{"content"}[$x] =~ /^$refa_filter->[$col]$/
ABresult
0X0
100
111
189 {
190 # print "RESULT: GOOD\n";
191 25 $colFilterResults[$col] = "true";
192 }
193 # ansonsten kann direkt 'undef' zurueckgegeben werden
194 else
195 {
196 # print "RESULT: BAD\n";
197 45 return undef;
198 }
199 }
200 else
201 {
202 # jeden eintrag im array durchgehen und ueberpruefen ob ein eintrag passt
203 20 foreach my $vergleichsString (@{${$refa_filter}[$col]})
204 {
205 # wenn eintrag passt
206 40 ▶ if(($self->{'content'}->[$x]) && ( $self->{'content'}->[$x] =~ /^$vergleichsString$/))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"content"}[$x] and $self->{"content"}[$x] =~ /^$vergleichsString$/) 15 25 40
Condition100%3/3
$self->{"content"}[$x] and $self->{"content"}[$x] =~ /^$vergleichsString$/
!ll&&!rl&&r
61915
MC/DC100%2/2
$self->{"content"}[$x] and $self->{"content"}[$x] =~ /^$vergleichsString$/
$self->{"content"}[$x] $self->{"content"}[$x] =~ /^$vergleichsString$/
Truth table100%3/3
A and B
A= $self->{"content"}[$x]B= $self->{"content"}[$x] =~ /^$vergleichsString$/
ABresult
0X0
100
111
207 {
208 15 $colFilterResults[$col] = "true";
209 15 next;
210 }
211 }
212 }
213
214 # wenn der filter zur aktuellen spalte 'false' geliefert hat, kann man sich die ueberpruefung evtl. anderer spalten sparen
215 45 ▶ if($colFilterResults[$col] eq "false")
Branch: 1 branch
BranchTrueFalseTotal
if ($colFilterResults[$col] eq "false") 5 40 45
216 {
217 # print "filter fuer row = 'false'. return undef\n";
218 5 return undef;
219 }
220 }
221 else
222 {
223 311 next;
224 }
225 }
226
227 111 ▶ if(grep { if ($_) {$_ eq "false"} } @colFilterResults)
Branch: 2 branches
BranchTrueFalseTotal
if (grep {if ($_) { $_ eq 'false'; } ;} @colFilterResults) { } 0 111 111
if ($_) 39 66 105
228 {
229 # print "Mindestens 1 Filter fuer Entity lieferte 'false' => return undef.\n";
230 # print "NOMATCH\n";
231 0 return undef;
232 }
233 else
234 {
235 # print "Alle Filter fuer Entity lieferten 'true' => return true.\n";
236 111 return "true";
237 # print "MATCH\n";
238 }
239 }
240 #---------------------
241  
242 #---------------------
243 # sprint entity
244 #---------------------
245 sub sprint
246 6 ▶{
Subroutine sprint: called CC=7 SCAR=19.5
Pod undocumented
247 6 my $self = shift;
248  
249 6 my $return;
250
251 # print comment if available
252 6 foreach (@{$self->{comment}})
253 {
254 0 ▶ unless ($_ =~ m/^\$/) {$_ = "\$".$_;} # falls noch kein Kommentarzeichen vorhanden, eines hinzufuegen
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ =~ /^\$/) 0 2 2
255 2 $return .= $_."\n";
256 # print $_."\n";
257 }
258
259
260 # print content
261 # print "JUPP: ".(1+int((scalar(@{$self->{'content'}}))/10))."\n";
262 6 ▶ for (my $zeile=0; $zeile<(1+int((scalar(@{$self->{'content'}}))/10)); $zeile++)
Branch: 1 branch
BranchTrueFalseTotal
if ($zeile < 1 + int(scalar(@{$self->{"content"};}) / 10)) 7 6 13
263 {
264 # 10er pack befuellen
265 7 my $formatstring;
266 my @ausgabe;
267 7 ▶ for(my $x=(0+$zeile*10); ( ($x<@{$self->{content}}) && ($x<(10+$zeile*10)) ); $x++)
Branch: 1 branch
BranchTrueFalseTotal
if ($x < @{$self->{"content"};} and $x < 10 + $zeile * 10) 43 7 50
Condition100%3/3
$x < @{$self->{"content"};} and $x < 10 + $zeile * 10
!ll&&!rl&&r
6143
MC/DC100%2/2
$x < @{$self->{"content"};} and $x < 10 + $zeile * 10
$x < @{$self->{"content"};} $x < 10 + $zeile * 10
Truth table100%3/3
A and B
A= $x < @{$self->{"content"};}B= $x < 10 + $zeile * 10
ABresult
0X0
100
111
268 {
269 43 ▶ if(defined ${$self->{content}}[$x])
Branch: 1 branch
BranchTrueFalseTotal
if (defined do { $$self{"content"} }->[$x]) 39 4 43
270 {
271 39 push(@ausgabe, ${$self->{content}}[$x]);
272 39 $formatstring .= "%-8.8s";
273 }
274 }
275 7 $return .= sprintf $formatstring."\n", @ausgabe;
276 }
277 6 return $return;
278 }
279 #---------------------
280  
281 #---------------------
282 # print entity
283 #---------------------
284 sub print
285 6 ▶{
Subroutine print: called CC=1 SCAR=0.0
Pod documented
286 6 my $self = shift;
287 6 my $ausgabe = $self->sprint();
288 6 print $ausgabe;
289 }
290  
291 4 1;
292  
293 __END__
↑ Summary Nasmod.pm »