blib/lib/Lingua/Ogmios/Annotations/Section.pm

filter: Statementstmt 56.5% 69 / 122 Branchbran 43.1% 25 / 58 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 60.8% 14 / 23 Podpod 0.0% 0 / 20 totaltotal 44.6% 108 / 242 CC 34 SCAR 21.6
CC
34
Cov
49%
getRank
20.0
isTitle
20.0
getForm
20.0
CRAP 8.7
« blib/lib/Lingua/Ogmios/FileManager.pm ↑ Summary blib/lib/Lingua/Ogmios/NLPWrappers/NegEx.pm »
1 package Lingua::Ogmios::Annotations::Section;
2  
3 16 ▶use Lingua::Ogmios::Annotations::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 16 our @ISA = qw(Lingua::Ogmios::Annotations::Element);
8  
9 sub new
10 78 ▶{
Subroutine new: called CC=9 SCAR=22.5
Pod undocumented
11 78 my ($class, $fields) = @_;
12 78 ▶ if (!defined $fields->{'id'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fields->{"id"}) 78 0 78
13 78 $fields->{'id'} = -1;
14 }
15 my $section = $class->SUPER::new({
16 78 'id' => $fields->{'id'},
17 }
18 );
19  
20 78 ▶ if (!defined $fields->{'from'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fields->{"from"}) 0 78 78
21 0 die("from is not defined");
22 }
23 78 ▶ if (!defined $fields->{'to'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fields->{"to"}) 0 78 78
24 0 die("to is not defined");
25 }
26  
27 78 bless ($section,$class);
28  
29 78 $section->setFrom($fields->{'from'});
30 78 $section->setTo($fields->{'to'});
31  
32 78 ▶ if (defined $fields->{'title'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields->{"title"}) 12 66 78
33 12 $section->title($fields->{'title'});
34 }
35 78 ▶ if (defined $fields->{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields->{"type"}) 15 63 78
36 15 $section->type($fields->{'type'});
37 }
38 78 ▶ if (defined $fields->{'rank'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields->{"rank"}) 78 0 78
39 78 $section->rank($fields->{'rank'});
40 }
41 78 ▶ if (defined $fields->{'parent_section'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields->{"parent_section"}) 64 14 78
42 64 $section->parent_section($fields->{'parent_section'});
43 }
44 78 ▶ if (defined $fields->{'child_sections'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields->{"child_sections"}) 78 0 78
45 78 $section->child_sections($fields->{'child_sections'});
46 }
47
48 78 return $section;
49 }
50  
51  
52 78 ▶sub rank {
Subroutine rank: called CC=2 SCAR=7.1
Pod undocumented
53 78 my $self = shift;
54  
55 78 ▶ $self->{'rank'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 78 0 78
56 78 return $self->{'rank'};
57 }
58  
59 15 ▶sub type {
Subroutine type: called CC=2 SCAR=7.1
Pod undocumented
60 15 my $self = shift;
61  
62 15 ▶ $self->{'type'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 15 0 15
63 15 return $self->{'type'};
64 }
65  
66  
67 12 ▶sub title {
Subroutine title: called CC=2 SCAR=7.1
Pod undocumented
68 12 my $self = shift;
69  
70 12 ▶ $self->{'title'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 12 0 12
71 12 return $self->{'title'};
72 }
73  
74  
75 0 ▶sub getRank {
Subroutine getRank: not called CC=4 SCAR=30.0
Pod undocumented
76 0 my ($self) = @_;
77  
78 0 my $i = 0;
79  
80 0 ▶ if (defined $self->parent_section) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->parent_section) 0 0 0
81 0 ▶ for($i = 0; $i < scalar(@{$self->parent_section->child_sections}); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$self->parent_section->child_sections;}) 0 0 0
82 0 ▶ if ($self->getId == $self->parent_section->child_sections->[$i]->getId) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getId == $self->parent_section->child_sections->[$i]->getId) 0 0 0
83 0 return($i);
84 }
85 }
86 }
87 0 return(-1);
88  
89 }
90  
91 0 ▶sub isTitle {
Subroutine isTitle: not called CC=4 SCAR=30.0
Pod undocumented
92 0 my $self = shift;
93  
94 0 ▶ if ((defined $self->parent_section) && (defined $self->parent_section->{'title'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->parent_section and defined $self->parent_section->{"title"} and $self->rank == 0) 0 0 0
Condition0%0/6
defined $self->parent_section and defined $self->parent_section->{"title"} and $self->rank == 0
!ll&&!rl&&r
000
defined $self->parent_section and defined $self->parent_section->{"title"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $self->parent_section and defined $self->parent_section->{"title"} and $self->rank == 0
defined $self->parent_section defined $self->parent_section->{"title"} $self->rank == 0
Truth table0%0/4
A and B and C
A= defined $self->parent_sectionB= defined $self->parent_section->{"title"}C= $self->rank == 0
ABCresult
0XX0
10X0
1100
1111
95 && ($self->rank == 0)) {
96 0 return(1);
97 }
98 0 return(0);
99  
100 }
101  
102 64 ▶sub parent_section {
Subroutine parent_section: called CC=2 SCAR=7.1
Pod undocumented
103 64 my $self = shift;
104  
105 64 ▶ $self->{'parent_section'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 64 0 64
106 64 return $self->{'parent_section'};
107 }
108  
109 156 ▶sub child_sections {
Subroutine child_sections: called CC=2 SCAR=6.9
Pod undocumented
110 156 my $self = shift;
111  
112 156 ▶ $self->{'child_sections'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 78 78 156
113 156 return $self->{'child_sections'};
114 }
115  
116 0 ▶sub has_child_sections {
Subroutine has_child_sections: not called CC=2 SCAR=17.9
Pod undocumented
117 0 my $self = shift;
118  
119 0 ▶ return((defined $self->child_sections) && (scalar(@{$self->child_sections}) > 0));
Condition0%0/3
defined $self->child_sections && scalar @{$self->child_sections;} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->child_sections && scalar @{$self->child_sections;} > 0
defined $self->child_sections scalar @{$self->child_sections;} > 0
Truth table0%0/3
A && B
A= defined $self->child_sectionsB= scalar @{$self->child_sections;} > 0
ABresult
0X0
100
111
120 }
121  
122 78 ▶sub setFrom {
Subroutine setFrom: called CC=1 SCAR=0.0
Pod undocumented
123 78 my ($self, $from) = @_;
124  
125 78 $self->{'from'} = $from;
126  
127 }
128  
129 156 ▶sub setTo {
Subroutine setTo: called CC=1 SCAR=0.0
Pod undocumented
130 156 my ($self, $to) = @_;
131  
132 156 $self->{'to'} = $to;
133 }
134  
135 958 ▶sub getFrom {
Subroutine getFrom: called CC=1 SCAR=0.0
Pod undocumented
136 958 my ($self) = @_;
137  
138 958 return($self->{'from'});
139  
140 }
141  
142 0 ▶sub getFromOffset {
Subroutine getFromOffset: not called CC=2 SCAR=17.9
Pod undocumented
143 0 my ($self) = @_;
144  
145 0 ▶ if (ref($self->{'from'}) eq "Lingua::Ogmios::Annotations::Token") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'from'} eq 'Lingua::Ogmios::Annotations::Token') { } 0 0 0
146 0 return($self->{'from'}->getFrom);
147 } else {
148 0 return($self->{'from'});
149 }
150  
151 }
152  
153 0 ▶sub getToOffset {
Subroutine getToOffset: not called CC=2 SCAR=17.9
Pod undocumented
154 0 my ($self) = @_;
155  
156 0 ▶ if (ref($self->{'to'}) eq "Lingua::Ogmios::Annotations::Token") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'to'} eq 'Lingua::Ogmios::Annotations::Token') { } 0 0 0
157 0 return($self->{'to'}->getTo);
158 } else {
159 0 return($self->{'to'});
160 }
161  
162 }
163  
164 958 ▶sub getTo {
Subroutine getTo: called CC=1 SCAR=0.0
Pod undocumented
165 958 my ($self) = @_;
166  
167 958 return($self->{'to'});
168 }
169  
170  
171 0 ▶sub getForm {
Subroutine getForm: not called CC=4 SCAR=30.0
Pod undocumented
172  
173 0 my ($self, $tokenLevel) = @_;
174  
175 # warn "ref start: " . ref($self->getFrom) . "\n";
176 # warn "ref to: " . ref($self->getTo) . "\n";
177 0 my $token;
178 my $start_token;
179 0 my $end_token;
180  
181 0 my $sectionForm;
182  
183 0 ▶ if (ref($self->getFrom) eq "Lingua::Ogmios::Annotations::Token") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->getFrom eq 'Lingua::Ogmios::Annotations::Token') { } 0 0 0
184 # from is a token
185 0 $start_token = $self->getFrom;
186 } else {
187 # from is a offset
188 0 $start_token = $tokenLevel->getElementByOffset($self->getFrom)->[0];
189 }
190 0 ▶ if (ref($self->getTo) eq "Lingua::Ogmios::Annotations::Token") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->getTo eq 'Lingua::Ogmios::Annotations::Token') { } 0 0 0
191 # To is a token
192 0 $end_token = $self->getTo;
193 } else {
194 # to is a offset
195 0 $end_token = $tokenLevel->getElementByOffset($self->getTo)->[0];
196 }
197  
198 0 $token = $start_token;
199 0 $sectionForm = $token->getContent;
200 0 ▶ while(!$token->equals($end_token)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($token->equals($end_token)) 0 0 0
201 0 $token = $token->next;
202 0 $sectionForm .= $token->getContent;
203
204 };
205 # warn "$sectionForm\n";
206 0 return($start_token, $end_token, $sectionForm);
207  
208 }
209  
210 0 ▶sub firstDefinedTitle {
Subroutine firstDefinedTitle: not called CC=3 SCAR=24.8
Pod undocumented
211 0 my ($self) = @_;
212  
213 0 ▶ if (defined $self->title) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->title) { } 0 0 0
214 0 return($self->title);
215 } else {
216 0 ▶ if (defined $self->parent_section) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->parent_section) { } 0 0 0
217 0 return($self->parent_section->firstDefinedTitle);
218 } else {
219 0 return(undef);
220 }
221 }
222  
223 }
224  
225 0 ▶sub XMLout {
Subroutine XMLout: not called CC=1 SCAR=6.9
Pod undocumented
226 0 my ($self, $order) = @_;
227  
228 0 return($self->SUPER::XMLout("section", $order));
229 }
230  
231  
232 0 ▶sub tokenIsInside {
Subroutine tokenIsInside: not called CC=3 SCAR=24.8
Pod undocumented
233 0 my ($self, $token) = @_;
234  
235 0 ▶ if (($self->getFromOffset < $token->getFrom) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->getFromOffset < $token->getFrom and $token->getTo < $self->getToOffset) { } 0 0 0
Condition0%0/3
$self->getFromOffset < $token->getFrom and $token->getTo < $self->getToOffset
!ll&&!rl&&r
000
MC/DC0%0/2
$self->getFromOffset < $token->getFrom and $token->getTo < $self->getToOffset
$self->getFromOffset < $token->getFrom $token->getTo < $self->getToOffset
Truth table0%0/3
A and B
A= $self->getFromOffset < $token->getFromB= $token->getTo < $self->getToOffset
ABresult
0X0
100
111
236 ($token->getTo < $self->getToOffset)) {
237 0 return(1);
238 } else {
239 0 return(0)
240 }
241 }
242  
243 606 ▶sub reference {
Subroutine reference: called CC=5 SCAR=16.1
Pod undocumented
244 606 my ($self) = @_;
245  
246 606 my $start_token;
247 my $end_token;
248 606 my @refs;
249 606 my $token;
250  
251 606 ▶ if (ref($self->getFrom) eq "Lingua::Ogmios::Annotations::Token") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->getFrom eq 'Lingua::Ogmios::Annotations::Token') { } 264 342 606
252 # from is a token
253 264 $start_token = $self->getFrom;
254 } else {
255 # from is a offset
256 # $start_token = $tokenLevel->getElementByOffset($self->getFrom)->[0];
257 }
258 # warn "..\n";
259 # warn $self->getTo . " : " . ref($self->getTo) . "\n";
260 606 ▶ if (ref($self->getTo) eq "Lingua::Ogmios::Annotations::Token") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->getTo eq 'Lingua::Ogmios::Annotations::Token') { } 264 342 606
261 # To is a token
262 264 $end_token = $self->getTo;
263 } else {
264 # to is a offset
265 # $end_token = $tokenLevel->getElementByOffset($self->getTo)->[0];
266 }
267 # warn "...\n";
268 606 ▶ if (defined $start_token) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start_token) 264 342 606
269 264 $token = $start_token;
270 264 push @refs, $token;
271 264 ▶ while(!$token->equals($end_token)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($token->equals($end_token)) 115608 264 115872
272 115608 $token = $token->next;
273 115608 push @refs, $token;
274 };
275 }
276 # warn "....\n";
277 606 return(\@refs);
278 }
279  
280  
281 16 1;
282  
283 __END__
« blib/lib/Lingua/Ogmios/FileManager.pm ↑ Summary blib/lib/Lingua/Ogmios/NLPWrappers/NegEx.pm »