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

filter: Statementstmt 9.0% 11 / 122 Branchbran 0.0% 0 / 58 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 13.0% 3 / 23 Podpod 0.0% 0 / 20 totaltotal 5.7% 14 / 242 SCAR 69.1
CC
34
Cov
6%
new
90.0
reference
30.0
getRank
20.0
CRAP 1002.5
« blib/lib/Lingua/Ogmios/NLPWrappers/Faster.pm ↑ Summary blib/script/Txt2Ogmios.pl »
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 {
11 0 ▶ my ($class, $fields) = @_;
Subroutine new: not called CC=9 SCAR=45.0
Pod undocumented
12 0 ▶ if (!defined $fields->{'id'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fields->{"id"}) 0 0 0
13 0 $fields->{'id'} = -1;
14 }
15 my $section = $class->SUPER::new({
16 0 'id' => $fields->{'id'},
17 }
18 );
19  
20 0 ▶ if (!defined $fields->{'from'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fields->{"from"}) 0 0 0
21 0 die("from is not defined");
22 }
23 0 ▶ if (!defined $fields->{'to'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fields->{"to"}) 0 0 0
24 0 die("to is not defined");
25 }
26  
27 0 bless ($section,$class);
28  
29 0 $section->setFrom($fields->{'from'});
30 0 $section->setTo($fields->{'to'});
31  
32 0 ▶ if (defined $fields->{'title'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields->{"title"}) 0 0 0
33 0 $section->title($fields->{'title'});
34 }
35 0 ▶ if (defined $fields->{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields->{"type"}) 0 0 0
36 0 $section->type($fields->{'type'});
37 }
38 0 ▶ if (defined $fields->{'rank'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields->{"rank"}) 0 0 0
39 0 $section->rank($fields->{'rank'});
40 }
41 0 ▶ if (defined $fields->{'parent_section'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields->{"parent_section"}) 0 0 0
42 0 $section->parent_section($fields->{'parent_section'});
43 }
44 0 ▶ if (defined $fields->{'child_sections'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields->{"child_sections"}) 0 0 0
45 0 $section->child_sections($fields->{'child_sections'});
46 }
47
48 0 return $section;
49 }
50  
51  
52 sub rank {
53 0 ▶ my $self = shift;
Subroutine rank: not called CC=2 SCAR=17.9
Pod undocumented
54  
55 0 ▶ $self->{'rank'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
56 0 return $self->{'rank'};
57 }
58  
59 sub type {
60 0 ▶ my $self = shift;
Subroutine type: not called CC=2 SCAR=17.9
Pod undocumented
61  
62 0 ▶ $self->{'type'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
63 0 return $self->{'type'};
64 }
65  
66  
67 sub title {
68 0 ▶ my $self = shift;
Subroutine title: not called CC=2 SCAR=17.9
Pod undocumented
69  
70 0 ▶ $self->{'title'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
71 0 return $self->{'title'};
72 }
73  
74  
75 sub getRank {
76 0 ▶ my ($self) = @_;
Subroutine getRank: not called CC=4 SCAR=30.0
Pod undocumented
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 sub isTitle {
92 0 ▶ my $self = shift;
Subroutine isTitle: not called CC=4 SCAR=30.0
Pod undocumented
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 sub parent_section {
103 0 ▶ my $self = shift;
Subroutine parent_section: not called CC=2 SCAR=17.9
Pod undocumented
104  
105 0 ▶ $self->{'parent_section'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
106 0 return $self->{'parent_section'};
107 }
108  
109 sub child_sections {
110 0 ▶ my $self = shift;
Subroutine child_sections: not called CC=2 SCAR=17.9
Pod undocumented
111  
112 0 ▶ $self->{'child_sections'} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
113 0 return $self->{'child_sections'};
114 }
115  
116 sub has_child_sections {
117 0 ▶ my $self = shift;
Subroutine has_child_sections: not called CC=2 SCAR=17.9
Pod undocumented
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 sub setFrom {
123 0 ▶ my ($self, $from) = @_;
Subroutine setFrom: not called CC=1 SCAR=6.9
Pod undocumented
124  
125 0 $self->{'from'} = $from;
126  
127 }
128  
129 sub setTo {
130 0 ▶ my ($self, $to) = @_;
Subroutine setTo: not called CC=1 SCAR=6.9
Pod undocumented
131  
132 0 $self->{'to'} = $to;
133 }
134  
135 sub getFrom {
136 0 ▶ my ($self) = @_;
Subroutine getFrom: not called CC=1 SCAR=6.9
Pod undocumented
137  
138 0 return($self->{'from'});
139  
140 }
141  
142 sub getFromOffset {
143 0 ▶ my ($self) = @_;
Subroutine getFromOffset: not called CC=2 SCAR=17.9
Pod undocumented
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 sub getToOffset {
154 0 ▶ my ($self) = @_;
Subroutine getToOffset: not called CC=2 SCAR=17.9
Pod undocumented
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 sub getTo {
165 0 ▶ my ($self) = @_;
Subroutine getTo: not called CC=1 SCAR=6.9
Pod undocumented
166  
167 0 return($self->{'to'});
168 }
169  
170  
171 sub getForm {
172  
173 0 ▶ my ($self, $tokenLevel) = @_;
Subroutine getForm: not called CC=4 SCAR=30.0
Pod undocumented
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 sub firstDefinedTitle {
211 0 ▶ my ($self) = @_;
Subroutine firstDefinedTitle: not called CC=3 SCAR=24.8
Pod undocumented
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 sub XMLout {
226 0 ▶ my ($self, $order) = @_;
Subroutine XMLout: not called CC=1 SCAR=6.9
Pod undocumented
227  
228 0 return($self->SUPER::XMLout("section", $order));
229 }
230  
231  
232 sub tokenIsInside {
233 0 ▶ my ($self, $token) = @_;
Subroutine tokenIsInside: not called CC=3 SCAR=24.8
Pod undocumented
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 sub reference {
244 0 ▶ my ($self) = @_;
Subroutine reference: not called CC=5 SCAR=34.0
Pod undocumented
245  
246 0 my $start_token;
247 my $end_token;
248 0 my @refs;
249 0 my $token;
250  
251 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
252 # from is a token
253 0 $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 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
261 # To is a token
262 0 $end_token = $self->getTo;
263 } else {
264 # to is a offset
265 # $end_token = $tokenLevel->getElementByOffset($self->getTo)->[0];
266 }
267 # warn "...\n";
268 0 ▶ if (defined $start_token) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $start_token) 0 0 0
269 0 $token = $start_token;
270 0 push @refs, $token;
271 0 ▶ while(!$token->equals($end_token)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($token->equals($end_token)) 0 0 0
272 0 $token = $token->next;
273 0 push @refs, $token;
274 };
275 }
276 # warn "....\n";
277 0 return(\@refs);
278 }
279  
280  
281 16 1;
282  
283 __END__
« blib/lib/Lingua/Ogmios/NLPWrappers/Faster.pm ↑ Summary blib/script/Txt2Ogmios.pl »