Document.pm

filter: Statementstmt 98.5% 395 / 401 Branchbran 93.3% 183 / 196 Conditioncond 83.2% 119 / 143 MC/DCmcdc 68.1% 60 / 88 Subroutinesub 100% 25 / 25 Podpod 66.6% 2 / 3 totaltotal 91.5% 784 / 856 CC 152 SCAR 34.6
CC
152
Cov
94%
_parse
55.2
_add_text
44.6
_apply_markup
17.0
CRAP 32.0
« Element/Timestamp.pm ↑ Summary Parser.pm »
1 package Org::Document;
2  
3 26 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 26 ▶use locale;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 26 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 26 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 26 ▶no if $] >= 5.021_006, warnings => "locale";
Subroutine BEGIN: called CC=1 SCAR=0.0
8 26 extends 'Org::Element';
9  
10 26 ▶use List::MoreUtils qw(firstidx);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 26 ▶use Time::HiRes qw(gettimeofday tv_interval);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 26 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
14 26 our $DATE = '2026-07-21'; # DATE
15 26 our $DIST = 'Org-Parser'; # DIST
16 26 our $VERSION = '0.563'; # VERSION
17  
18 26 has _srclabel => (is => 'rw');
19 26 has tags => (is => 'rw');
20 26 has todo_states => (is => 'rw');
21 26 has done_states => (is => 'rw');
22 26 has priorities => (is => 'rw');
23 26 has drawer_names => (is => 'rw');
24 26 has properties => (is => 'rw');
25 26 has radio_targets => (is => 'rw');
26  
27 26 has time_zone => (is => 'rw');
28  
29 26 has ignore_unknown_settings => (is => 'rw');
30 26 has ignore_unknown_drawers => (is => 'rw');
31  
32 26 our $tags_re = qr/:(?:[\w@]+:)+/u;
33 26 my $ls_re = qr/(?:(?<=[\015\012])|\A)/; # line start
34 26 my $le_re = qr/(?:\R|\z)/; # line end
35 26 our $arg_re = qr/(?: '(?<squote> [^']*)' |
36 "(?<dquote> [^"]*)" |
37 (?<bare> \S+) )
38 /x;
39 26 our $args_re = qr/(?: $arg_re (?:[ \t]+ $arg_re)*)/x;
40 26 my $tstamp_re = qr/(?:\[\d{4}-\d{2}-\d{2} [^\n\]]*\])/x;
41 26 my $act_tstamp_re = qr/(?: <\d{4}-\d{2}-\d{2} [^\n>]* >)/x;
42 26 my $fn_name_re = qr/(?:[^ \t\n:\]]+)/x;
43 26 my $text_re =
44 qr{
45 (?<link> \[\[(?<link_link> [^\]\n]+)\]
46 (?:\[(?<link_desc> (?:[^\]]|\R)+)\])?\]) |
47 (?<radio_target> <<<(?<rt_target> [^>\n]+)>>>) |
48 (?<target> <<(?<t_target> [^>\n]+)>>) |
49  
50 # timestamp & time range
51 (?<trange> (?<trange_ts1> $tstamp_re)--
52 (?<trange_ts2> $tstamp_re)) |
53 (?<tstamp> $tstamp_re) |
54 (?<act_trange> (?<act_trange_ts1> $act_tstamp_re)--
55 (?<act_trange_ts2> $act_tstamp_re)) |
56 (?<act_tstamp> $act_tstamp_re) |
57  
58 # footnote (num, name + def, name + inline definition)
59 (?<fn_num> \[(?<fn_num_num>\d+)\]) |
60 (?<fn_namedef> $ls_re \[fn:(?<fn_namedef_name> $fn_name_re)\]
61 [ \t]* (?<fn_namedef_def> [^ \t\n]+)) |
62 (?<fn_nameidef> \[fn:(?<fn_nameidef_name> $fn_name_re?):?
63 (?<fn_nameidef_def> ([^\n\]]+)?)\]) |
64  
65 (?<markup_start> (?:(?<=\s|\(|\{)|\A) # whitespace, open paren, open curly paren
66 [*/+=~_]
67 (?=\S)) |
68 (?<markup_end> (?<=\S)
69 [*/+=~_]
70 # actually emacs doesn't allow ! after markup
71 (?:(?=[ \t\n:;"',.!?\)*-])|\z)) |
72  
73 (?<plain_text> (?:[^\[<*/+=~_\n]+|.+?))
74 #(?<plain_text> .+?) # too dispersy
75 }sxi;
76  
77 # XXX parser must be fixed: block elements have different precedence instead of
78 # flat like this. a headline has the highest precedence and a block or a drawer
79 # cannot contain a headline (e.g. "#+BEGIN_SRC foo\n* header\n#+END_SRC" should
80 # not contain a literal "* header" text but that is a headline. currently, a
81 # block or a drawer swallows a headline.
82  
83 26 my $block_elems_re = # top level elements
84 qr/(?<block> $ls_re (?<block_begin_indent>[ \t]*)
85 \#\+BEGIN_(?<block_name>\w+)
86 (?:[ \t]+(?<block_raw_arg>[^\n]*))?\R
87 (?<block_content>(?:.|\R)*?)
88 \R(?<block_end_indent>[ \t]*)
89 \#\+END_\k<block_name> $le_re) |
90 (?<setting> $ls_re (?<setting_indent>[ \t]*) \#\+
91 (?<setting_name> \w+): (?: [ \t]+
92 (?<setting_raw_arg> [^\n]*))? $le_re) |
93 (?<fixedw> (?: $ls_re [ \t]* (?::[ ][^\n]* | :$) $le_re )+ ) |
94 (?<comment> $ls_re [ \t]*\#[^\n]*(?:\R\#[^\n]*)* (?:\R|\z)) |
95 (?<headline> $ls_re (?<h_bullet>\*+) [ \t]
96 (?<h_title>[^\n]*?)
97 (?:[ \t]+(?<h_tags> $tags_re))?[ \t]* $le_re) |
98 (?<li_header> $ls_re (?<li_indent>[ \t]*)
99 (?<li_bullet>[+*-]|\d+\.) [ \t]+
100 (?<li_checkbox> \[(?<li_cbstate> [ X-])\])?
101 (?: (?<li_dt> [^\n]+?) [ ]::)?) |
102 (?<table> (?: $ls_re [ \t]* \| [ \t]* \S[^\n]* $le_re)+) |
103 (?<drawer> $ls_re [ \t]* :(?<drawer_name> \w+): [ \t]*\R
104 (?<drawer_content>(?:.|\R)*?)
105 $ls_re [ \t]* :END:) |
106 (?<text> (?:[^#|:+*0-9\n-]+|\n+|.)+?)
107 #(?<text> .+?) # too dispersy
108 /msxi;
109  
110 95 ▶sub _init_pass1 {
Subroutine _init_pass1: called CC=1 SCAR=0.0
111 95 my ($self) = @_;
112 95 $self->tags([]);
113 95 $self->todo_states([]);
114 95 $self->done_states([]);
115 95 $self->priorities([]);
116 95 $self->properties({});
117 95 $self->drawer_names([qw/CLOCK LOGBOOK PROPERTIES/]);
118 # FEEDSTATUS
119 95 $self->radio_targets([]);
120 }
121  
122 93 ▶sub _init_pass2 {
Subroutine _init_pass2: called CC=4 SCAR=13.9
123 93 my ($self) = @_;
124 93 ▶ if (!@{ $self->todo_states } && !@{ $self->done_states }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->todo_states;} or @{$self->done_states;}) 81 12 93
Condition66%2/3
@{$self->todo_states;} or @{$self->done_states;}
l!l&&r!l&&!r
12081
MC/DC50%1/2
@{$self->todo_states;} or @{$self->done_states;}
@{$self->todo_states;} @{$self->done_states;}
Truth table66%2/3
A or B
A= @{$self->todo_states;}B= @{$self->done_states;}
ABresult
1X1
011
000
125 81 $self->todo_states(['TODO']);
126 81 $self->done_states(['DONE']);
127 }
128 93 ▶ if (!@{ $self->priorities }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->priorities;}) 89 4 93
129 89 $self->priorities([qw/A B C/]);
130 }
131 93 $self->children([]);
132 }
133  
134 57 ▶sub __parse_args {
Subroutine __parse_args: called CC=6 SCAR=18.8
135 57 my $args = shift;
136 57 ▶ return [] unless defined($args) && length($args);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args and length $args 2 55 57
Condition66%2/3
defined $args and length $args
!ll&&!rl&&r
2055
MC/DC50%1/2
defined $args and length $args
defined $args length $args
Truth table66%2/3
A and B
A= defined $argsB= length $args
ABresult
0X0
100
111
137 #$log->tracef("args = %s", $args);
138 55 my @args;
139 55 ▶ while ($args =~ /$arg_re (?:\s+|\z)/xg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args =~ /$Org::Document::arg_re (?:\s+|\z)/glx) 165 55 220
140 165 ▶ if (defined $+{squote}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $+{'squote'}) { } 0 165 165
elsif (defined $+{'dquote'}) { } 0 165 165
141 0 push @args, $+{squote};
142 } elsif (defined $+{dquote}) {
143 0 push @args, $+{dquote};
144 } else {
145 165 push @args, $+{bare};
146 }
147 }
148 #$log->tracef("\\\@args = %s", \@args);
149 55 \@args;
150 }
151  
152 2 ▶sub __format_args {
Subroutine __format_args: called CC=4 SCAR=16.4
153 2 my ($args) = @_;
154 2 my @s;
155 2 for (@$args) {
156 4 ▶ if (/\A(?:[A-Za-z0-9_:-]+|\|)\z/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/\A(?:[A-Za-z0-9_:-]+|\|)\z/l) { } 4 0 4
elsif (/"/l) { } 0 0 0
157 4 push @s, $_;
158 } elsif (/"/) {
159 0 push @s, qq('$_');
160 } else {
161 0 push @s, qq("$_");
162 }
163 }
164 2 join " ", @s;
165 }
166  
167 96 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=11.0
Pod undocumented
168 96 my ($self, $args) = @_;
169 96 ▶ $self->document($self) unless $self->document;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->document 96 0 96
170  
171 96 ▶ if (defined $args->{from_string}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{"from_string"}) 95 1 96
172  
173 # NOTE: parsing is done twice. first pass will set settings (e.g. custom
174 # todo keywords set by #+TODO), scan for radio targets. after that we
175 # scan again to build the elements tree.
176  
177 95 $self->_init_pass1();
178 95 $self->_parse($args->{from_string}, 1);
179 93 $self->_init_pass2();
180 93 $self->_parse($args->{from_string}, 2);
181 }
182 }
183  
184 # parse blocky elements: setting, blocks, headline, drawer
185 188 ▶sub _parse {
Subroutine _parse: called CC=55 SCAR=40.1
186 188 my ($self, $str, $pass) = @_;
187 188 log_trace('-> _parse(%s, pass=%d)', $str, $pass);
188 188 my $t0 = [gettimeofday];
189  
190 188 my $last_el;
191  
192 my $last_headline;
193 188 my $last_headlines = [$self]; # [$doc, $last_hl_level1, $last_hl_lvl2, ...]
194 188 my $last_listitem;
195 188 my $last_lists = []; # [last_List_obj_for_indent_level0, ...]
196 188 my $parent;
197  
198 my @text;
199 188 ▶ while ($str =~ /$block_elems_re/og) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /$block_elems_re/glo) 4729 184 4913
200 4729 ▶ $parent = $last_listitem // $last_headline // $self;
Condition83%5/6
($last_listitem // $last_headline) // $self
l!l&&r!l&&!r
161531140
$last_listitem // $last_headline
l!l&&r!l&&!r
8787373114
MC/DC0%0/3
($last_listitem // $last_headline) // $self
$last_listitem $last_headline $self
Truth table75%3/4
A // B // C
A= $last_listitemB= $last_headlineC= $self
ABCresult
1XX1
01X1
0011
0000
201 #$log->tracef("TMP: parent=%s (%s)", ref($parent), $parent->_str);
202 4729 my %m = %+;
203 4729 ▶ next unless keys %m; # perlre bug?
Branch: 1 branch
BranchTrueFalseTotal
unless keys %m 0 4729 4729
204 #if ($log->is_trace) {
205 # # profiler shows that this is very heavy, so commenting this out
206 # $log->tracef("TMP: match block element: %s", \%+) if $pass==2;
207 #}
208  
209 4729 ▶ if (defined $m{text}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $m{'text'}) { } 4049 680 4729
210 4049 push @text, $m{text};
211 4049 next;
212 } else {
213 680 ▶ if (@text) {
Branch: 1 branch
BranchTrueFalseTotal
if (@text) 270 410 680
214 270 my $text = join("", @text);
215 270 ▶ if ($last_el && $last_el->isa('Org::Element::ListItem')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_el and $last_el->isa("Org::Element::ListItem")) 85 185 270
Condition100%3/3
$last_el and $last_el->isa("Org::Element::ListItem")
!ll&&!rl&&r
1414485
MC/DC100%2/2
$last_el and $last_el->isa("Org::Element::ListItem")
$last_el $last_el->isa("Org::Element::ListItem")
Truth table100%3/3
A and B
A= $last_elB= $last_el->isa("Org::Element::ListItem")
ABresult
0X0
100
111
216 # a list is broken by either: a) another list (where the
217 # bullet type or indent is different; handled in the
218 # handling of $m{li_header}) or b) by two blank lines, or c)
219 # by non-blank text that is indented less than or equal to
220 # the last list item's indent.
221  
222 # a single blank line does not break a list. a text that is
223 # more indented than the last list item's indent will become
224 # the child of that list item.
225  
226 85 my ($firstline, $restlines) = $text =~ /(.*?\r?\n)(.+)/s;
227 85 ▶ if ($restlines) {
Branch: 1 branch
BranchTrueFalseTotal
if ($restlines) 17 68 85
228 17 $restlines =~ /\A([ \t]*)/;
229 17 my $restlineslevel = length($1);
230 17 my $listlevel = length($last_el->parent->indent);
231 17 ▶ if ($restlineslevel <= $listlevel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($restlineslevel <= $listlevel) 11 6 17
232 11 my $origparent = $parent;
233 # find lesser-indented list
234 11 ▶ $parent = $last_headline // $self;
Condition33%1/3
$last_headline // $self
l!l&&r!l&&!r
1100
MC/DC0%0/2
$last_headline // $self
$last_headline $self
Truth table33%1/3
A // B
A= $last_headlineB= $self
ABresult
1X1
011
000
235 11 ▶ for (my $i=$restlineslevel-1; $i>=0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 2 9 11
236 2 ▶ if ($last_lists->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_lists->[$i]) 2 0 2
237 2 $parent = $last_lists->[$i];
238 2 last;
239 }
240 }
241 11 splice @$last_lists, $restlineslevel;
242 11 $self->_add_text($firstline, $origparent, $pass);
243 11 $self->_add_text($restlines, $parent, $pass);
244 11 goto SKIP1;
245 }
246 }
247 }
248 259 $self->_add_text($text, $parent, $pass);
249 270 SKIP1:
250 @text = ();
251 270 $last_el = undef;
252 }
253 }
254  
255 680 my $el;
256 680 ▶ if ($m{block} && $pass == 2) {
Branch: 8 branches
BranchTrueFalseTotal
if ($m{'block'} and $pass == 2) { } 3 677 680
elsif ($m{'setting'}) { } 60 617 677
elsif ($m{'fixedw'} and $pass == 2) { } 7 610 617
elsif ($m{'comment'} and $pass == 2) { } 18 592 610
elsif ($m{'table'} and $pass == 2) { } 6 586 592
elsif ($m{'drawer'} and $pass == 2) { } 15 571 586
elsif ($m{'li_header'} and $pass == 2) { } 90 481 571
elsif ($m{'headline'} and $pass == 2) { } 171 449 620
Condition100%3/3
$m{"block"} and $pass == 2
!ll&&!rl&&r
67433
MC/DC100%2/2
$m{"block"} and $pass == 2
$m{"block"} $pass == 2
Truth table100%3/3
A and B
A= $m{"block"}B= $pass == 2
ABresult
0X0
100
111
257  
258 3 require Org::Element::Block;
259 $el = Org::Element::Block->new(
260 _str=>$m{block},
261 document=>$self, parent=>$parent,
262 begin_indent=>$m{block_begin_indent},
263 end_indent=>$m{block_end_indent},
264 name=>$m{block_name}, args=>__parse_args($m{block_raw_arg}),
265 raw_content=>$m{block_content},
266 3 );
267  
268 } elsif ($m{setting}) {
269  
270 60 require Org::Element::Setting;
271 60 my $uc_setting_name = uc($m{setting_name});
272 60 ▶ if ($m{setting_indent} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($m{'setting_indent'} and not grep({$_ eq $uc_setting_name;} @{'Org::Element::Setting'->indentable_settings;})) { } 6 54 60
Condition100%3/3
$m{"setting_indent"} and not grep({$_ eq $uc_setting_name;} @{"Org::Element::Setting"->indentable_settings;})
!ll&&!rl&&r
5226
MC/DC100%2/2
$m{"setting_indent"} and not grep({$_ eq $uc_setting_name;} @{"Org::Element::Setting"->indentable_settings;})
$m{"setting_indent"} not grep({$_ eq $uc_setting_name;} @{"Org::Element::Setting"->indentable_settings;})
Truth table100%3/3
A and not(B)
A= $m{"setting_indent"}B= not grep({$_ eq $uc_setting_name;} @{"Org::Element::Setting"->indentable_settings;})
ABresult
0X0
100
111
273 8 !(grep { $_ eq $uc_setting_name }
274 8 @{Org::Element::Setting->indentable_settings})) {
275 6 push @text, $m{setting};
276 6 next;
277 } else {
278 $el = Org::Element::Setting->new(
279 pass => $pass,
280 _str=>$m{setting},
281 document=>$self, parent=>$parent,
282 indent => $m{setting_indent},
283 name=>$m{setting_name},
284 raw_arg => $m{setting_raw_arg},
285 54 args=>__parse_args($m{setting_raw_arg}),
286 );
287 }
288  
289 ▶ } elsif ($m{fixedw} && $pass == 2) {
Condition100%3/3
$m{"fixedw"} and $pass == 2
!ll&&!rl&&r
60377
MC/DC100%2/2
$m{"fixedw"} and $pass == 2
$m{"fixedw"} $pass == 2
Truth table100%3/3
A and B
A= $m{"fixedw"}B= $pass == 2
ABresult
0X0
100
111
290  
291 7 require Org::Element::FixedWidthSection;
292 $el = Org::Element::FixedWidthSection->new(
293 pass => $pass,
294 _str=>$m{fixedw},
295 7 document=>$self, parent=>$parent,
296 );
297  
298 ▶ } elsif ($m{comment} && $pass == 2) {
Condition100%3/3
$m{"comment"} and $pass == 2
!ll&&!rl&&r
5741818
MC/DC100%2/2
$m{"comment"} and $pass == 2
$m{"comment"} $pass == 2
Truth table100%3/3
A and B
A= $m{"comment"}B= $pass == 2
ABresult
0X0
100
111
299  
300 18 require Org::Element::Comment;
301 $el = Org::Element::Comment->new(
302 _str=>$m{comment},
303 18 document=>$self, parent=>$parent,
304 );
305  
306 ▶ } elsif ($m{table} && $pass == 2) {
Condition100%3/3
$m{"table"} and $pass == 2
!ll&&!rl&&r
58066
MC/DC100%2/2
$m{"table"} and $pass == 2
$m{"table"} $pass == 2
Truth table100%3/3
A and B
A= $m{"table"}B= $pass == 2
ABresult
0X0
100
111
307  
308 6 require Org::Element::Table;
309 $el = Org::Element::Table->new(
310 pass=>$pass,
311 _str=>$m{table},
312 6 document=>$self, parent=>$parent,
313 );
314  
315 ▶ } elsif ($m{drawer} && $pass == 2) {
Condition100%3/3
$m{"drawer"} and $pass == 2
!ll&&!rl&&r
5561515
MC/DC100%2/2
$m{"drawer"} and $pass == 2
$m{"drawer"} $pass == 2
Truth table100%3/3
A and B
A= $m{"drawer"}B= $pass == 2
ABresult
0X0
100
111
316  
317 15 require Org::Element::Drawer;
318 15 my $raw_content = $m{drawer_content};
319 $el = Org::Element::Drawer->new(
320 document=>$self, parent=>$parent,
321 15 name => uc($m{drawer_name}), pass => $pass,
322 );
323 14 $self->_add_text($raw_content, $el, $pass);
324  
325 # for properties, we also parse property lines from raw drawer
326 # content. this is currently separate from normal Org text parsing,
327 # i'm not clear yet on how to do this canonically.
328 14 $el->_parse_properties($raw_content);
329  
330 ▶ } elsif ($m{li_header} && $pass == 2) {
Condition100%3/3
$m{"li_header"} and $pass == 2
!ll&&!rl&&r
3919090
MC/DC100%2/2
$m{"li_header"} and $pass == 2
$m{"li_header"} $pass == 2
Truth table100%3/3
A and B
A= $m{"li_header"}B= $pass == 2
ABresult
0X0
100
111
331  
332 90 require Org::Element::List;
333 90 require Org::Element::ListItem;
334  
335 90 my $level = length($m{li_indent});
336 90 my $bullet = $m{li_bullet};
337 90 my $indent = $m{li_indent};
338 90 my $dt = $m{li_dt};
339 90 my $cbstate = $m{li_cbstate};
340 90 ▶ my $type = defined($dt) ? 'D' :
Branch: 2 branches
BranchTrueFalseTotal
defined $dt ? : 8 82 90
$bullet =~ /^\d+\./l ? : 6 76 82
341 $bullet =~ /^\d+\./ ? 'O' : 'U';
342 90 ▶ my $bstyle = $type eq 'O' ? '<N>.' : $bullet;
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'O' ? : 6 84 90
343  
344 # parent for list is the last listitem of a lesser-indented list (or
345 # last headline, or document)
346 90 ▶ $parent = $last_headline // $self;
Condition66%2/3
$last_headline // $self
l!l&&r!l&&!r
8370
MC/DC0%0/2
$last_headline // $self
$last_headline $self
Truth table66%2/3
A // B
A= $last_headlineB= $self
ABresult
1X1
011
000
347 90 ▶ for (my $i=$level-1; $i>=0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 107 63 170
348 107 ▶ if ($last_lists->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_lists->[$i]) 27 80 107
349 27 $parent = $last_lists->[$i]->children->[-1];
350 27 last;
351 }
352 }
353  
354 90 my $list = $last_lists->[$level];
355 90 ▶ if (!$list || $list->type ne $type ||
Branch: 1 branch
BranchTrueFalseTotal
if (not $list or $list->type ne $type or $list->bullet_style ne $bstyle) 51 39 90
Condition100%6/6
not $list or $list->type ne $type or $list->bullet_style ne $bstyle
l!l&&r!l&&!r
49239
not $list or $list->type ne $type
l!l&&r!l&&!r
45441
MC/DC100%3/3
not $list or $list->type ne $type or $list->bullet_style ne $bstyle
not $list $list->type ne $type $list->bullet_style ne $bstyle
Truth table100%4/4
not(A) or B or C
A= not $listB= $list->type ne $typeC= $list->bullet_style ne $bstyle
ABCresult
1XX1
01X1
0011
0000
356 $list->bullet_style ne $bstyle) {
357 51 $list = Org::Element::List->new(
358 document => $self, parent => $parent,
359 indent=>$indent, type=>$type, bullet_style=>$bstyle,
360 );
361 51 $last_lists->[$level] = $list;
362 51 ▶ $parent->children([]) if !$parent->children;
Branch: 1 branch
BranchTrueFalseTotal
unless $parent->children 11 40 51
363 51 push @{ $parent->children }, $list;
364 }
365 90 $last_lists->[$level] = $list;
366  
367 # parent for list item is list
368 90 $parent = $list;
369  
370 90 $el = Org::Element::ListItem->new(
371 document=>$self, parent=>$list,
372 indent=>$indent, bullet=>$bullet);
373 90 ▶ $el->check_state($cbstate) if $cbstate;
Branch: 1 branch
BranchTrueFalseTotal
if $cbstate 6 84 90
374 90 ▶ $el->desc_term($self->_add_text_container($dt, $list, $pass))
Branch: 1 branch
BranchTrueFalseTotal
if defined $dt 8 82 90
375 if defined($dt);
376  
377 90 splice @$last_lists, $level+1;
378 90 $last_listitem = $el;
379  
380 ▶ } elsif ($m{headline} && $pass == 2) {
Condition100%3/3
$m{"headline"} and $pass == 2
!ll&&!rl&&r
139171171
MC/DC100%2/2
$m{"headline"} and $pass == 2
$m{"headline"} $pass == 2
Truth table100%3/3
A and B
A= $m{"headline"}B= $pass == 2
ABresult
0X0
100
111
381  
382 171 require Org::Element::Headline;
383 171 my $level = length $m{h_bullet};
384  
385 # parent is upper-level headline
386 171 $parent = undef;
387 171 ▶ for (my $i=$level-1; $i>=0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 181 0 181
388 181 ▶ $parent = $last_headlines->[$i] and last;
Branch: 1 branch
BranchTrueFalseTotal
$parent = $last_headlines->[$i] and last 171 10 181
389 }
390 171 ▶ $parent //= $self;
Condition33%1/3
$parent //= $self
l!l&&r!l&&!r
17100
MC/DC0%0/2
$parent //= $self
$parent $self
Truth table33%1/3
A //= B
A= $parentB= $self
ABresult
1X1
011
000
391  
392 $el = Org::Element::Headline->new(
393 _str=>$m{headline},
394 171 document=>$self, parent=>$parent,
395 level=>$level,
396 );
397 171 ▶ $el->tags(__split_tags($m{h_tags})) if ($m{h_tags});
Branch: 1 branch
BranchTrueFalseTotal
if $m{"h_tags"} 7 164 171
398 171 my $title = $m{h_title};
399  
400 # recognize todo keyword
401 my $todo_kw_re = "(?:".
402 595 join("|", map {quotemeta}
403 "COMMENT",
404 171 @{$self->todo_states}, @{$self->done_states}) . ")";
405 171 ▶ if ($title =~ s/^($todo_kw_re)(\s+|\W)/$2/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($title =~ s/^($todo_kw_re)(\s+|\W)/$2/l) 38 133 171
406 38 my $state = $1;
407 38 $title =~ s/^\s+//;
408 38 $el->is_todo(1);
409 38 $el->todo_state($state);
410 38 ▶ $el->is_done((grep { $_ eq $state } @{ $self->done_states }) ? 1:0);
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq $state;} @{$self->done_states;}) ? : 6 32 38
411 }
412  
413 # recognize priority cookie
414 my $prio_re = "(?:".
415 171 join("|", map {quotemeta} @{$self->priorities}) . ")";
416 171 ▶ if ($title =~ s/\[#($prio_re)\]\s*//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($title =~ s/\[#($prio_re)\]\s*//l) 4 167 171
417 4 $el->priority($1);
418 }
419  
420 # recognize statistics cookie
421 171 ▶ if ($title =~ s!\[(\d+%|\d+/\d+)\]\s*!!o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($title =~ s(\[(\d+%|\d+/\d+)\]\s*)[]lo) 6 165 171
422 6 $el->statistics_cookie($1);
423 }
424  
425 171 $el->title($self->_add_text_container($title, $parent, $pass));
426  
427 171 $last_headlines->[$el->level] = $el;
428 171 splice @$last_headlines, $el->level+1;
429 171 $last_headline = $el;
430 171 $last_listitem = undef;
431 171 $last_lists = [];
432 }
433  
434 # we haven't caught other matches to become element
435 670 ▶ die "BUG1: no element" unless $el || $pass != 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $el or $pass != 2 0 670 670
Condition66%2/3
$el or $pass != 2
l!l&&r!l&&!r
3603100
MC/DC0%0/2
$el or $pass != 2
$el $pass != 2
Truth table66%2/3
A or B
A= $elB= $pass != 2
ABresult
1X1
011
000
436  
437 670 ▶ $parent->children([]) if !$parent->children;
Branch: 1 branch
BranchTrueFalseTotal
unless $parent->children 155 515 670
438 670 push @{ $parent->children }, $el;
439 670 $last_el = $el;
440 }
441  
442 # remaining text
443 184 ▶ if (@text) {
Branch: 1 branch
BranchTrueFalseTotal
if (@text) 79 105 184
444 79 $self->_add_text(join("", @text), $parent, $pass);
445 }
446 181 @text = ();
447  
448 181 log_trace('<- _parse(), elapsed time=%.3fs',
449 tv_interval($t0, [gettimeofday]));
450 }
451  
452 185 ▶sub _add_text_container {
Subroutine _add_text_container: called CC=4 SCAR=13.9
453 185 require Org::Element::Text;
454 185 my ($self, $str, $parent, $pass) = @_;
455 185 my $container = Org::Element::Text->new(
456 document=>$self, parent=>$parent,
457 text=>'', style=>'',
458 );
459 185 $self->_add_text($str, $container, $pass);
460 $container = $container->children->[0] if
461 185 ▶ $container->children && @{$container->children} == 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if $container->children and @{$container->children;} == 1 and $container->children->[0]->isa("Org::Element::Text") 172 13 185
Condition83%5/6
$container->children and @{$container->children;} == 1 and $container->children->[0]->isa("Org::Element::Text")
!ll&&!rl&&r
130172
$container->children and @{$container->children;} == 1
!ll&&!rl&&r
211172
MC/DC66%2/3
$container->children and @{$container->children;} == 1 and $container->children->[0]->isa("Org::Element::Text")
$container->children @{$container->children;} == 1 $container->children->[0]->isa("Org::Element::Text")
Truth table75%3/4
A and B and C
A= $container->childrenB= @{$container->children;} == 1C= $container->children->[0]->isa("Org::Element::Text")
ABCresult
0XX0
10X0
1100
1111
462 $container->children->[0]->isa('Org::Element::Text');
463 185 $container;
464 }
465  
466 591 ▶sub _add_text {
Subroutine _add_text: called CC=44 SCAR=38.0
467 591 require Org::Element::Text;
468 591 my ($self, $str, $parent, $pass) = @_;
469 591 ▶ $parent //= $self;
Condition33%1/3
$parent //= $self
l!l&&r!l&&!r
59100
MC/DC0%0/2
$parent //= $self
$parent $self
Truth table33%1/3
A //= B
A= $parentB= $self
ABresult
1X1
011
000
470 #$log->tracef("-> _add_text(%s, pass=%d)", $str, $pass);
471  
472 591 my @plain_text;
473 591 ▶ while ($str =~ /$text_re/og) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /$text_re/glo) 1976 588 2564
474 1976 my %m = %+;
475 #if ($log->is_trace) {
476 # # profiler shows that this is very heavy, so commenting this out
477 # $log->tracef("TMP: match text: %s", \%+);
478 #}
479 1976 my $el;
480  
481 1976 ▶ if (defined $m{plain_text} && $pass == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $m{'plain_text'} and $pass == 2) { } 1012 964 1976
Condition100%3/3
defined $m{"plain_text"} and $pass == 2
!ll&&!rl&&r
2666981012
MC/DC100%2/2
defined $m{"plain_text"} and $pass == 2
defined $m{"plain_text"} $pass == 2
Truth table100%3/3
A and B
A= defined $m{"plain_text"}B= $pass == 2
ABresult
0X0
100
111
482 1012 push @plain_text, $m{plain_text};
483 1012 next;
484 } else {
485 964 ▶ if (@plain_text) {
Branch: 1 branch
BranchTrueFalseTotal
if (@plain_text) 117 847 964
486 117 $self->_add_plain_text(join("", @plain_text), $parent, $pass);
487 117 @plain_text = ();
488 }
489 }
490  
491 964 ▶ if ($m{link} && $pass == 2) {
Branch: 12 branches
BranchTrueFalseTotal
if ($m{'link'} and $pass == 2) { } 6 958 964
elsif ($m{'radio_target'}) { } 4 954 958
elsif ($m{'target'} and $pass == 2) { } 0 954 954
elsif ($m{'fn_num'} and $pass == 2) { } 1 953 954
elsif ($m{'fn_namedef'} and $pass == 2) { } 1 952 953
elsif ($m{'fn_nameidef'} and $pass == 2) { } 3 949 952
elsif ($m{'trange'} and $pass == 2) { } 3 946 949
elsif ($m{'tstamp'} and $pass == 2) { } 26 920 946
elsif ($m{'act_trange'} and $pass == 2) { } 5 915 920
elsif ($m{'act_tstamp'} and $pass == 2) { } 29 886 915
elsif ($m{'markup_start'} and $pass == 2) { } 24 862 886
elsif ($m{'markup_end'} and $pass == 2) { } 48 1594 1642
Condition100%3/3
$m{"link"} and $pass == 2
!ll&&!rl&&r
95266
MC/DC100%2/2
$m{"link"} and $pass == 2
$m{"link"} $pass == 2
Truth table100%3/3
A and B
A= $m{"link"}B= $pass == 2
ABresult
0X0
100
111
492 6 require Org::Element::Link;
493 $el = Org::Element::Link->new(
494 document => $self, parent => $parent,
495 link=>$m{link_link},
496 6 );
497 6 ▶ if (defined($m{link_desc}) && length($m{link_desc})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $m{"link_desc"} and length $m{"link_desc"}) 3 3 6
Condition66%2/3
defined $m{"link_desc"} and length $m{"link_desc"}
!ll&&!rl&&r
303
MC/DC50%1/2
defined $m{"link_desc"} and length $m{"link_desc"}
defined $m{"link_desc"} length $m{"link_desc"}
Truth table66%2/3
A and B
A= defined $m{"link_desc"}B= length $m{"link_desc"}
ABresult
0X0
100
111
498 $el->description(
499 $self->_add_text_container($m{link_desc},
500 3 $el, $pass));
501 }
502 } elsif ($m{radio_target}) {
503 4 require Org::Element::RadioTarget;
504 $el = Org::Element::RadioTarget->new(
505 pass => $pass,
506 document => $self, parent => $parent,
507 target=>$m{rt_target},
508 4 );
509 ▶ } elsif ($m{target} && $pass == 2) {
Condition33%1/3
$m{"target"} and $pass == 2
!ll&&!rl&&r
95400
MC/DC0%0/2
$m{"target"} and $pass == 2
$m{"target"} $pass == 2
Truth table33%1/3
A and B
A= $m{"target"}B= $pass == 2
ABresult
0X0
100
111
510 0 require Org::Element::Target;
511 $el = Org::Element::Target->new(
512 document => $self, parent => $parent,
513 target=>$m{t_target},
514 0 );
515 ▶ } elsif ($m{fn_num} && $pass == 2) {
Condition100%3/3
$m{"fn_num"} and $pass == 2
!ll&&!rl&&r
95211
MC/DC100%2/2
$m{"fn_num"} and $pass == 2
$m{"fn_num"} $pass == 2
Truth table100%3/3
A and B
A= $m{"fn_num"}B= $pass == 2
ABresult
0X0
100
111
516 1 require Org::Element::Footnote;
517 $el = Org::Element::Footnote->new(
518 document => $self, parent => $parent,
519 1 name=>$m{fn_num_num}, is_ref=>1,
520 );
521 ▶ } elsif ($m{fn_namedef} && $pass == 2) {
Condition100%3/3
$m{"fn_namedef"} and $pass == 2
!ll&&!rl&&r
95111
MC/DC100%2/2
$m{"fn_namedef"} and $pass == 2
$m{"fn_namedef"} $pass == 2
Truth table100%3/3
A and B
A= $m{"fn_namedef"}B= $pass == 2
ABresult
0X0
100
111
522 1 require Org::Element::Footnote;
523 $el = Org::Element::Footnote->new(
524 document => $self, parent => $parent,
525 name=>$m{fn_namedef_name},
526 1 ▶ is_ref=>$m{fn_namedef_def} ? 0:1,
Branch: 1 branch
BranchTrueFalseTotal
$m{'fn_namedef_def'} ? : 1 0 1
527 );
528 $el->def($self->_add_text_container($m{fn_namedef_def},
529 1 $parent, $pass));
530 ▶ } elsif ($m{fn_nameidef} && $pass == 2) {
Condition100%3/3
$m{"fn_nameidef"} and $pass == 2
!ll&&!rl&&r
94633
MC/DC100%2/2
$m{"fn_nameidef"} and $pass == 2
$m{"fn_nameidef"} $pass == 2
Truth table100%3/3
A and B
A= $m{"fn_nameidef"}B= $pass == 2
ABresult
0X0
100
111
531 3 require Org::Element::Footnote;
532 $el = Org::Element::Footnote->new(
533 document => $self, parent => $parent,
534 name=>$m{fn_nameidef_name},
535 is_ref=>($m{fn_nameidef_def} ? 0:1) ||
536 3 ▶ !length($m{fn_nameidef_name}),
Branch: 1 branch
BranchTrueFalseTotal
$m{'fn_nameidef_def'} ? : 2 1 3
Condition100%3/3
($m{'fn_nameidef_def'} ? 0 : 1) || !length($m{'fn_nameidef_name'})
l!l&&r!l&&!r
111
MC/DC100%2/2
($m{'fn_nameidef_def'} ? 0 : 1) || !length($m{'fn_nameidef_name'})
($m{'fn_nameidef_def'} ? 0 : 1) !length($m{'fn_nameidef_name'})
Truth table100%3/3
A || not(B)
A= ($m{'fn_nameidef_def'} ? 0 : 1)B= !length($m{'fn_nameidef_name'})
ABresult
1X1
011
000
537 );
538 $el->def(length($m{fn_nameidef_def}) ?
539 $self->_add_text_container($m{fn_nameidef_def},
540 3 ▶ $parent, $pass) : undef);
Branch: 1 branch
BranchTrueFalseTotal
length $m{'fn_nameidef_def'} ? : 2 1 3
541 ▶ } elsif ($m{trange} && $pass == 2) {
Condition100%3/3
$m{"trange"} and $pass == 2
!ll&&!rl&&r
94333
MC/DC100%2/2
$m{"trange"} and $pass == 2
$m{"trange"} $pass == 2
Truth table100%3/3
A and B
A= $m{"trange"}B= $pass == 2
ABresult
0X0
100
111
542 3 require Org::Element::TimeRange;
543 3 require Org::Element::Timestamp;
544 3 $el = Org::Element::TimeRange->new(
545 document => $self, parent => $parent,
546 );
547 3 my $opts = {allow_event_duration=>0, allow_repeater=>0};
548 $el->ts1(Org::Element::Timestamp->new(
549 3 _str=>$m{trange_ts1}, document=>$self, parent=>$parent));
550 3 $el->ts1->_parse_timestamp($m{trange_ts1}, $opts);
551 $el->ts2(Org::Element::Timestamp->new(
552 3 _str=>$m{trange_ts2}, document=>$self, parent=>$parent));
553 3 $el->ts2->_parse_timestamp($m{trange_ts2}, $opts);
554 3 $el->children([$el->ts1, $el->ts2]);
555 ▶ } elsif ($m{tstamp} && $pass == 2) {
Condition100%3/3
$m{"tstamp"} and $pass == 2
!ll&&!rl&&r
8972326
MC/DC100%2/2
$m{"tstamp"} and $pass == 2
$m{"tstamp"} $pass == 2
Truth table100%3/3
A and B
A= $m{"tstamp"}B= $pass == 2
ABresult
0X0
100
111
556 26 require Org::Element::Timestamp;
557 $el = Org::Element::Timestamp->new(
558 26 _str => $m{tstamp}, document => $self, parent => $parent,
559 );
560 26 $el->_parse_timestamp($m{tstamp});
561 ▶ } elsif ($m{act_trange} && $pass == 2) {
Condition100%3/3
$m{"act_trange"} and $pass == 2
!ll&&!rl&&r
91055
MC/DC100%2/2
$m{"act_trange"} and $pass == 2
$m{"act_trange"} $pass == 2
Truth table100%3/3
A and B
A= $m{"act_trange"}B= $pass == 2
ABresult
0X0
100
111
562 5 require Org::Element::TimeRange;
563 5 require Org::Element::Timestamp;
564 5 $el = Org::Element::TimeRange->new(
565 document => $self, parent => $parent,
566 );
567 5 my $opts = {allow_event_duration=>0, allow_repeater=>0};
568 $el->ts1(Org::Element::Timestamp->new(
569 5 _str=>$m{act_trange_ts1}, document=>$self, parent=>$parent));
570 5 $el->ts1->_parse_timestamp($m{act_trange_ts1}, $opts);
571 $el->ts2(Org::Element::Timestamp->new(
572 3 _str=>$m{act_trange_ts2}, document=>$self, parent=>$parent));
573 3 $el->ts2->_parse_timestamp($m{act_trange_ts2}, $opts);
574 3 $el->children([$el->ts1, $el->ts2]);
575 ▶ } elsif ($m{act_tstamp} && $pass == 2) {
Condition100%3/3
$m{"act_tstamp"} and $pass == 2
!ll&&!rl&&r
8652129
MC/DC100%2/2
$m{"act_tstamp"} and $pass == 2
$m{"act_tstamp"} $pass == 2
Truth table100%3/3
A and B
A= $m{"act_tstamp"}B= $pass == 2
ABresult
0X0
100
111
576 29 require Org::Element::Timestamp;
577 $el = Org::Element::Timestamp->new(
578 29 _str => $m{act_tstamp}, document => $self, parent => $parent,
579 );
580 29 $el->_parse_timestamp($m{act_tstamp});
581 ▶ } elsif ($m{markup_start} && $pass == 2) {
Condition100%3/3
$m{"markup_start"} and $pass == 2
!ll&&!rl&&r
8431924
MC/DC100%2/2
$m{"markup_start"} and $pass == 2
$m{"markup_start"} $pass == 2
Truth table100%3/3
A and B
A= $m{"markup_start"}B= $pass == 2
ABresult
0X0
100
111
582 24 require Org::Element::Text;
583 $el = Org::Element::Text->new(
584 document => $self, parent => $parent,
585 style=>'', text=>$m{markup_start},
586 24 );
587 # temporary mark, we need to apply markup later
588 24 $el->{_mu_start}++;
589 ▶ } elsif ($m{markup_end} && $pass == 2) {
Condition100%3/3
$m{"markup_end"} and $pass == 2
!ll&&!rl&&r
7803448
MC/DC100%2/2
$m{"markup_end"} and $pass == 2
$m{"markup_end"} $pass == 2
Truth table100%3/3
A and B
A= $m{"markup_end"}B= $pass == 2
ABresult
0X0
100
111
590 48 require Org::Element::Text;
591 $el = Org::Element::Text->new(
592 document => $self, parent => $parent,
593 style=>'', text=>$m{markup_end},
594 48 );
595 # temporary mark, we need to apply markup later
596 48 $el->{_mu_end}++;
597 }
598 961 ▶ die "BUG2: no element" unless $el || $pass != 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $el or $pass != 2 0 961 961
Condition66%2/3
$el or $pass != 2
l!l&&r!l&&!r
1478140
MC/DC0%0/2
$el or $pass != 2
$el $pass != 2
Truth table66%2/3
A or B
A= $elB= $pass != 2
ABresult
1X1
011
000
599 961 ▶ $parent->children([]) if !$parent->children;
Branch: 1 branch
BranchTrueFalseTotal
unless $parent->children 40 921 961
600 961 push @{ $parent->children }, $el;
601 }
602  
603 # remaining text
604 588 ▶ if (@plain_text && $pass == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@plain_text and $pass == 2) 394 194 588
Condition66%2/3
@plain_text and $pass == 2
!ll&&!rl&&r
1940394
MC/DC50%1/2
@plain_text and $pass == 2
@plain_text $pass == 2
Truth table66%2/3
A and B
A= @plain_textB= $pass == 2
ABresult
0X0
100
111
605 394 ▶ $parent->children([]) if !$parent->children;
Branch: 1 branch
BranchTrueFalseTotal
unless $parent->children 268 126 394
606 394 push @{$parent->children}, Org::Element::Text->new(
607 text => join("", @plain_text), style=>'',
608 document=>$self, parent=>$parent);
609 394 @plain_text = ();
610 }
611  
612 588 ▶ if ($pass == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pass == 2) 413 175 588
613 413 $self->_apply_markup($parent);
614 413 ▶ if (@{$self->radio_targets}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->radio_targets;}) 1 412 413
615 1 my $re = join "|", map {quotemeta} @{$self->radio_targets};
616 1 $re = qr/(?:$re)/i;
617 1 $self->_linkify_rt_recursive($re, $parent);
618 }
619 413 ▶ my $c = $parent->children // [];
Condition100%2/2
$parent->children // []
l!l
4076
MC/DC100%1/1
$parent->children // []
$parent->children
Truth table100%2/2
A
A= $parent->children
Aresult
11
00
620 }
621  
622 #$log->tracef('<- _add_text()');
623 }
624  
625 # to keep parser's regexes simple and fast, we detect markup in regex rather
626 # simplistically (as text element) and then apply some more filtering & applying
627 # logic here
628  
629 413 ▶sub _apply_markup {
Subroutine _apply_markup: called CC=17 SCAR=28.4
630 #$log->trace("-> _apply_markup()");
631 413 my ($self, $parent) = @_;
632 413 my $last_index = 0;
633 413 ▶ my $c = $parent->children or return;
Branch: 1 branch
BranchTrueFalseTotal
my $c = $parent->children or return 407 6 413
634  
635 407 while (1) {
636 #$log->tracef("text cluster = %s", [map {$_->as_string} @$c]);
637 # find a new mu_start
638 429 my $mu_start_index = -1;
639 429 my $mu;
640 429 ▶ for (my $i = $last_index; $i < @$c; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$c) 831 407 1238
641 831 ▶ next unless $c->[$i]->{_mu_start};
Branch: 1 branch
BranchTrueFalseTotal
unless $c->[$i]{"_mu_start"} 809 22 831
642 22 $mu_start_index = $i; $mu = $c->[$i]->text;
643 #$log->tracef("found mu_start at %d (%s)", $i, $mu);
644 22 last;
645 }
646 429 ▶ unless ($mu_start_index >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mu_start_index >= 0) 407 22 429
647 #$log->trace("no more mu_start found");
648 407 last;
649 }
650  
651 # check whether this is a valid markup (has text, has markup end, not
652 # interspersed with non-text, no more > 1 newlines)
653 22 my $mu_end_index = 0;
654 22 my $newlines = 0;
655 22 my $has_text;
656 my $has_unmarkable;
657 22 ▶ for (my $i=$mu_start_index+1; $i < @$c; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$c) 60 7 67
658 60 ▶ if ($c->[$i]->isa('Org::Element::Text')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->[$i]->isa('Org::Element::Text')) { } 59 1 60
659 59 $has_text++;
660 } elsif (1) {
661 } else {
662 $has_unmarkable++; last;
663 }
664 60 ▶ if ($c->[$i]->{_mu_end} && $c->[$i]->text eq $mu) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->[$i]{"_mu_end"} and $c->[$i]->text eq $mu) 13 47 60
Condition100%3/3
$c->[$i]{"_mu_end"} and $c->[$i]->text eq $mu
!ll&&!rl&&r
40713
MC/DC100%2/2
$c->[$i]{"_mu_end"} and $c->[$i]->text eq $mu
$c->[$i]{"_mu_end"} $c->[$i]->text eq $mu
Truth table100%3/3
A and B
A= $c->[$i]{"_mu_end"}B= $c->[$i]->text eq $mu
ABresult
0X0
100
111
665 #$log->tracef("found mu_end at %d", $i);
666 13 $mu_end_index = $i; last;
667 }
668 47 my $text = $c->[$i]->as_string;
669 47 ▶ $newlines++ while $text =~ /\R/g;
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /\R/gl and do { ++$newlines } 10 47 57
670 47 ▶ last if $newlines > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $newlines > 1 2 45 47
671 }
672 22 ▶ my $valid = $has_text && !$has_unmarkable
Condition55%5/9
$has_text && !$has_unmarkable && $mu_end_index && $newlines <= 1
!ll&&!rl&&r
9013
$has_text and not $has_unmarkable and $mu_end_index
!ll&&!rl&&r
0913
$has_text and not $has_unmarkable
!ll&&!rl&&r
0022
MC/DC25%1/4
$has_text && !$has_unmarkable && $mu_end_index && $newlines <= 1
$has_text not $has_unmarkable $mu_end_index $newlines <= 1
Truth table40%2/5
A and not(B) and C && D
A= $has_textB= not $has_unmarkableC= $mu_end_indexD= $newlines <= 1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
673 && $mu_end_index && $newlines <= 1;
674 #$log->tracef("mu candidate: start=%d, end=%s, ".
675 # "has_text=%s, has_unmarkable=%s, newlines=%d, valid=%s",
676 # $mu_start_index, $mu_end_index,
677 # $has_text, $has_unmarkable, $newlines, $valid
678 # );
679 22 ▶ if ($valid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($valid) { } 13 9 22
680 26 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
681 my $mu_el = Org::Element::Text->new(
682 document => $self, parent => $parent,
683 13 style=>$Org::Element::Text::mu2style{$mu}, text=>'',
684 );
685 13 my @c2 = splice @$c, $mu_start_index,
686 $mu_end_index-$mu_start_index+1, $mu_el;
687 #$log->tracef("grouping %s", [map {$_->text} @c2]);
688 13 $mu_el->children(\@c2);
689 13 shift @c2;
690 13 pop @c2;
691 13 for (@c2) {
692 22 $_->{parent} = $mu_el;
693 }
694 13 $self->_merge_text_elements(\@c2);
695 # squish if only one child
696 13 ▶ if (@c2 == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@c2 == 1) 12 1 13
697 12 $mu_el->text($c2[0]->text);
698 12 $mu_el->children(undef);
699 }
700 } else {
701 9 undef $c->[$mu_start_index]->{_mu_start};
702 9 $last_index++;
703 }
704 }
705 407 $self->_merge_text_elements($c);
706 #$log->trace("<- _apply_markup()");
707 }
708  
709 420 ▶sub _merge_text_elements {
Subroutine _merge_text_elements: called CC=12 SCAR=24.9
710 420 my ($self, $els) = @_;
711 #$log->tracef("-> _merge_text_elements(%s)", [map {$_->as_string} @$els]);
712 420 ▶ return unless @$els >= 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$els >= 2 310 110 420
713 110 my $i=-1;
714 110 while (1) {
715 462 $i++;
716 462 ▶ last if $i >= @$els;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= @$els 110 352 462
717 352 ▶ next if $els->[$i]->children || !$els->[$i]->isa('Org::Element::Text');
Branch: 1 branch
BranchTrueFalseTotal
if $els->[$i]->children or not $els->[$i]->isa("Org::Element::Text") 137 215 352
Condition100%3/3
$els->[$i]->children or not $els->[$i]->isa("Org::Element::Text")
l!l&&r!l&&!r
33104215
MC/DC100%2/2
$els->[$i]->children or not $els->[$i]->isa("Org::Element::Text")
$els->[$i]->children not $els->[$i]->isa("Org::Element::Text")
Truth table100%3/3
A or not(B)
A= $els->[$i]->childrenB= not $els->[$i]->isa("Org::Element::Text")
ABresult
1X1
011
000
718 215 ▶ my $istyle = $els->[$i]->style // "";
Condition50%1/2
$els->[$i]->style // ""
l!l
2150
MC/DC0%0/1
$els->[$i]->style // ""
$els->[$i]->style
Truth table50%1/2
A
A= $els->[$i]->style
Aresult
11
00
719 215 while (1) {
720 298 ▶ last if $i+1 >= @$els || $els->[$i+1]->children ||
Branch: 1 branch
BranchTrueFalseTotal
if $i + 1 >= @$els or $$els[$i + 1]->children or not $$els[$i + 1]->isa("Org::Element::Text") 194 104 298
Condition100%6/6
$i + 1 >= @$els or $$els[$i + 1]->children or not $$els[$i + 1]->isa("Org::Element::Text")
l!l&&r!l&&!r
12371104
$i + 1 >= @$els or $$els[$i + 1]->children
l!l&&r!l&&!r
10320175
MC/DC100%3/3
$i + 1 >= @$els or $$els[$i + 1]->children or not $$els[$i + 1]->isa("Org::Element::Text")
$i + 1 >= @$els $$els[$i + 1]->children not $$els[$i + 1]->isa("Org::Element::Text")
Truth table100%4/4
A or B or not(C)
A= $i + 1 >= @$elsB= $$els[$i + 1]->childrenC= not $$els[$i + 1]->isa("Org::Element::Text")
ABCresult
1XX1
01X1
0011
0000
721 !$els->[$i+1]->isa('Org::Element::Text');
722 104 ▶ last if ($els->[$i+1]->style // "") ne $istyle;
Branch: 1 branch
BranchTrueFalseTotal
if ($$els[$i + 1]->style // "") ne $istyle 21 83 104
Condition50%1/2
$$els[$i + 1]->style // ""
l!l
1040
MC/DC0%0/1
$$els[$i + 1]->style // ""
$$els[$i + 1]->style
Truth table50%1/2
A
A= $$els[$i + 1]->style
Aresult
11
00
723 #$log->tracef("merging text[%d] '%s' with '%s'",
724 # $i, $els->[$i]->text, $els->[$i+1]->text);
725 83 ▶ $els->[$i]->{text} .= $els->[$i+1]->{text} // "";
Condition50%1/2
$$els[$i + 1]{"text"} // ""
l!l
830
MC/DC0%0/1
$$els[$i + 1]{"text"} // ""
$$els[$i + 1]{"text"}
Truth table50%1/2
A
A= $$els[$i + 1]{"text"}
Aresult
11
00
726 83 splice @$els, $i+1, 1;
727 }
728 }
729 #$log->tracef("merge result = %s", [map {$_->as_string} @$els]);
730 #$log->trace("<- _merge_text_elements()");
731 }
732  
733 8 ▶sub _linkify_rt_recursive {
Subroutine _linkify_rt_recursive: called CC=8 SCAR=20.8
734 8 require Org::Element::Text;
735 8 require Org::Element::Link;
736 8 my ($self, $re, $parent) = @_;
737 8 my $c = $parent->children;
738 8 ▶ return unless $c;
Branch: 1 branch
BranchTrueFalseTotal
unless $c 7 1 8
739 1 ▶ for (my $i=0; $i<@$c; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$c) 12 1 13
740 12 my $el = $c->[$i];
741 12 ▶ if ($el->isa('Org::Element::Text')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($el->isa("Org::Element::Text")) 7 5 12
742 7 my @split0 = split /\b($re)\b/, $el->text;
743 7 ▶ next unless @split0 > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @split0 > 1 5 2 7
744 2 my @split;
745 2 for my $s (@split0) {
746 8 ▶ if ($s =~ /^$re$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($s =~ /^$re$/l) { } 3 5 8
elsif (length $s) { } 4 1 5
747 3 push @split, Org::Element::Link->new(
748 document=>$self, parent=>$parent,
749 link=>$s, description=>undef,
750 from_radio_target=>1,
751 );
752 } elsif (length $s) {
753 4 push @split, Org::Element::Text->new(
754 document=>$self, parent=>$parent,
755 text=>$s, style=>$el->style,
756 );
757 }
758 }
759 2 splice @$c, $i, 1, @split;
760 }
761 7 $self->_linkify_rt_recursive($re, $el);
762 }
763 }
764  
765 117 ▶sub _add_plain_text {
Subroutine _add_plain_text: called CC=2 SCAR=6.9
766 117 require Org::Element::Text;
767 117 my ($self, $str, $parent, $pass) = @_;
768 117 my $el = Org::Element::Text->new(
769 document=>$self, parent=>$parent, style=>'', text=>$str);
770 117 ▶ $parent->children([]) if !$parent->children;
Branch: 1 branch
BranchTrueFalseTotal
unless $parent->children 30 87 117
771 117 push @{ $parent->children }, $el;
772 }
773  
774 7 ▶sub __split_tags {
Subroutine __split_tags: called CC=1 SCAR=0.0
775 7 [$_[0] =~ /:([^:]+)/g];
776 }
777  
778 2 ▶sub load_element_modules {
Subroutine load_element_modules: called CC=2 SCAR=6.9
Pod documented
779 2 require Module::List;
780 2 require Module::Load;
781  
782 2 my $mm = Module::List::list_modules("Org::Element::", {list_modules=>1});
783 2 for (keys %$mm) {
784 38 Module::Load::load($_);
785 }
786 }
787  
788 11 ▶sub cmp_priorities {
Subroutine cmp_priorities: called CC=3 SCAR=11.0
Pod documented
789 11 my ($self, $p1, $p2) = @_;
790  
791 11 my $pp = $self->priorities;
792 11 ▶ my $pos1 = firstidx {$_ eq $p1} @$pp;
Subroutine __ANON__: called CC=1 SCAR=0.0
793 11 ▶ return undef unless $pos1 >= 0; ## no critic: Subroutines::ProhibitExplicitReturnUndef
Branch: 1 branch
BranchTrueFalseTotal
unless $pos1 >= 0 2 9 11
794 9 ▶ my $pos2 = firstidx {$_ eq $p2} @$pp;
Subroutine __ANON__: called CC=1 SCAR=0.0
795 9 ▶ return undef unless $pos2 >= 0; ## no critic: Subroutines::ProhibitExplicitReturnUndef
Branch: 1 branch
BranchTrueFalseTotal
unless $pos2 >= 0 2 7 9
796 7 $pos1 <=> $pos2;
797 }
798  
799 26 1;
800 # ABSTRACT: Represent an Org document
801  
802 __END__
« Element/Timestamp.pm ↑ Summary Parser.pm »