blib/lib/XML/Grammar/Screenplay/FromProto/Parser/QnD.pm

filter: Statementstmt 89.6% 217 / 242 Branchbran 80.8% 55 / 68 Conditioncond 89.7% 35 / 39 MC/DCmcdc 75.0% 18 / 24 Subroutinesub 92.5% 50 / 54 Podpod n/a totaltotal 87.8% 375 / 427 CC 48 SCAR 13.4
CC
48
Cov
88%
_generate_non_tag_text_event
13.1
_handle_saying_event
6.0
__ANON__
5.3
CRAP 3.8
« blib/lib/XML/Grammar/FictionBase/TagsTree2XML.pm ↑ Summary blib/lib/XML/Grammar/Fiction/FromProto.pm »
1 package XML::Grammar::Screenplay::FromProto::Parser::QnD;
2 8 $XML::Grammar::Screenplay::FromProto::Parser::QnD::VERSION = '0.32.0';
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use Carp qw/ cluck /;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use MooX 'late';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 extends('XML::Grammar::FictionBase::FromProto::Parser::XmlIterator');
10  
11 8 ▶use XML::Grammar::Fiction::Struct::Tag ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use XML::Grammar::FictionBase::Event ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use List::MoreUtils ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 8 has "_in_saying" => ( isa => "Bool", is => "rw" );
18 8 has "_prev_line_is_empty" => ( isa => "Bool", is => "rw", default => 1 );
19 8 has '_is_start' => ( isa => 'Bool', is => 'rw' );
20  
21 928 ▶before 'next_line_ref' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
22 928 my $self = shift;
23  
24 $self->_prev_line_is_empty(
25 928 scalar( ${ $self->curr_line_ref() } =~ m{\A\s*\z} ) );
26  
27 928 return;
28 8 };
29  
30 sub _debug
31 0 ▶{
Subroutine _debug: not called CC=1 SCAR=6.9
32 0 my ( $self, $args ) = @_;
33  
34 0 if (1)
35 {
36 0 my $name = $args->{name};
37 cluck "${name}[[["
38 0 . join( ",", map { $_->name() } @{ $self->_tags_stack } ) . "; "
39 0 . ${ $self->curr_line_ref } . "]]]";
40 }
41  
42 0 return;
43 }
44  
45 sub _top_is_para
46 693 ▶{
Subroutine _top_is_para: called CC=2 SCAR=6.9
47 693 my $self = shift;
48  
49 693 ▶ return $self->_in_para() && ( $self->_top_is('p') );
Condition100%3/3
$self->_in_para && $self->_top_is('p')
!ll&&!rl&&r
35177265
MC/DC100%2/2
$self->_in_para && $self->_top_is('p')
$self->_in_para $self->_top_is('p')
Truth table100%3/3
A && B
A= $self->_in_paraB= $self->_top_is('p')
ABresult
0X0
100
111
50 }
51  
52 sub _top_is_saying
53 322 ▶{
Subroutine _top_is_saying: called CC=2 SCAR=6.9
54 322 my $self = shift;
55  
56 322 ▶ return $self->_in_saying() && ( $self->_top_is('saying') );
Condition100%3/3
$self->_in_saying && $self->_top_is('saying')
!ll&&!rl&&r
1794895
MC/DC100%2/2
$self->_in_saying && $self->_top_is('saying')
$self->_in_saying $self->_top_is('saying')
Truth table100%3/3
A && B
A= $self->_in_sayingB= $self->_top_is('saying')
ABresult
0X0
100
111
57 }
58  
59 sub _top_is
60 1101 ▶{
Subroutine _top_is: called CC=2 SCAR=6.9
61 1101 my ( $self, $want_name ) = @_;
62  
63 1101 my $_top_tag = $self->_top_tag;
64 1101 ▶ return ( $_top_tag and $_top_tag->name eq $want_name );
Condition100%3/3
$_top_tag && $_top_tag->name eq $want_name
!ll&&!rl&&r
33671397
MC/DC100%2/2
$_top_tag && $_top_tag->name eq $want_name
$_top_tag $_top_tag->name eq $want_name
Truth table100%3/3
A && B
A= $_top_tagB= $_top_tag->name eq $want_name
ABresult
0X0
100
111
65 }
66  
67 sub _top_is_desc
68 616 ▶{
Subroutine _top_is_desc: called CC=1 SCAR=0.0
69 616 my $self = shift;
70  
71 616 return $self->_top_is('desc');
72 }
73  
74 606 ▶around '_pop_tag' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
75 606 my ( $orig, $self ) = @_;
76  
77 606 my $open = $self->$orig();
78  
79 606 ▶ if ( $open->name() eq "saying" )
Branch: 1 branch
BranchTrueFalseTotal
if ($open->name eq "saying") 130 476 606
80 {
81 130 $self->_in_saying(0);
82 }
83  
84 606 return $open;
85 8 };
86  
87 sub _count_tags_in_stack
88 1842 ▶{
Subroutine _count_tags_in_stack: called CC=1 SCAR=0.0
89 1842 my $self = shift;
90 1842 my $name = shift;
91  
92 1842 ▶ my @tags = $self->_grep_tags_stack( sub { $_->name() eq $name; } );
Subroutine __ANON__: called CC=1 SCAR=0.0
93  
94 1842 return scalar(@tags);
95 }
96  
97 614 ▶after '_push_tag' => sub {
Subroutine __ANON__: called CC=4 SCAR=16.6
98 614 my $self = shift;
99  
100 # This is an assert - it must never happen.
101 614 ▶ if ( $self->_count_tags_in_stack("p") >= 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_count_tags_in_stack("p") >= 2) 0 614 614
102 {
103 0 Carp::confess(qq{Two paragraphs in the tags stack.});
104 }
105  
106 614 ▶ if ( $self->_count_tags_in_stack("para") >= 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_count_tags_in_stack("para") >= 2) 0 614 614
107 {
108 0 Carp::confess(qq{Two paragraphs in the tags stack.});
109 }
110  
111 # This is an assert - it must never happen.
112 614 ▶ if ( $self->_count_tags_in_stack("saying") >= 2 )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_count_tags_in_stack("saying") >= 2) 0 614 614
113 {
114 0 Carp::confess(qq{Two sayings in the tags stack at the same time.});
115 }
116  
117 614 return;
118 8 };
119  
120 sub _new_saying
121 261 ▶{
Subroutine _new_saying: called CC=1 SCAR=0.0
122 261 my $self = shift;
123 261 my $sayer = shift;
124 261 my $contents = shift;
125  
126 261 return $self->_new_node(
127 {
128 t => "Saying",
129 character => $sayer,
130 children => $self->_new_list($contents),
131 }
132 );
133 }
134  
135 sub _get_desc_name
136 75 ▶{
Subroutine _get_desc_name: called CC=2 SCAR=6.9
137 75 my $self = shift;
138  
139 75 ▶ return ( $self->_in_para() ? "innerdesc" : "desc" );
Branch: 1 branch
BranchTrueFalseTotal
$self->_in_para ? : 8 67 75
140 }
141  
142 sub _create_closing_desc_tag
143 71 ▶{
Subroutine _create_closing_desc_tag: called CC=1 SCAR=0.0
144 71 my $self = shift;
145  
146 71 return XML::Grammar::Fiction::Struct::Tag->new(
147 name => $self->_get_desc_name(),
148 line => $self->line_num(),
149 );
150 }
151  
152 sub _detect_closing_desc_tag
153 211 ▶{
Subroutine _detect_closing_desc_tag: called CC=1 SCAR=0.0
154 211 my $self = shift;
155  
156 211 return ( ${ $self->curr_line_ref() } =~ m{\G\]}cg );
157 }
158  
159 211 ▶around '_parse_closing_tag' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
160 211 my ( $orig, $self ) = @_;
161  
162 211 ▶ return $self->_detect_closing_desc_tag
Branch: 1 branch
BranchTrueFalseTotal
$self->_detect_closing_desc_tag ? : 71 140 211
163 ? $self->_create_closing_desc_tag
164 : $self->$orig();
165 8 };
166  
167 sub _detect_open_desc_tag
168 237 ▶{
Subroutine _detect_open_desc_tag: called CC=1 SCAR=0.0
169 237 my $self = shift;
170  
171 237 return ( ${ $self->curr_line_ref } =~ m{\G\[}cg );
172 }
173  
174 sub _create_open_desc_tag
175 72 ▶{
Subroutine _create_open_desc_tag: called CC=4 SCAR=13.9
176 72 my ($self) = @_;
177  
178 72 my $not_inline = 0;
179 72 ▶ if ( $self->_is_start && $self->_prev_line_is_empty() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_start and $self->_prev_line_is_empty) 68 4 72
Condition100%3/3
$self->_is_start and $self->_prev_line_is_empty
!ll&&!rl&&r
3168
MC/DC100%2/2
$self->_is_start and $self->_prev_line_is_empty
$self->_is_start $self->_prev_line_is_empty
Truth table100%3/3
A and B
A= $self->_is_startB= $self->_prev_line_is_empty
ABresult
0X0
100
111
180 {
181 68 $self->_close_top_tags();
182 68 $not_inline = 1;
183 }
184  
185 72 ▶ return XML::Grammar::Fiction::Struct::Tag->new(
Branch: 1 branch
BranchTrueFalseTotal
$not_inline ? : 68 4 72
186 name => $not_inline ? "desc" : $self->_get_desc_name(),
187 line => $self->line_num(),
188 attrs => [],
189 );
190 }
191  
192 sub _set_is_start
193 237 ▶{
Subroutine _set_is_start: called CC=1 SCAR=0.0
194 237 my $self = shift;
195  
196 237 $self->_is_start( $self->at_line_start );
197  
198 237 return;
199 }
200  
201 237 ▶around '_parse_opening_tag' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
202 237 my ( $orig, $self ) = @_;
203  
204 237 $self->_set_is_start;
205  
206 237 ▶ return $self->_detect_open_desc_tag
Branch: 1 branch
BranchTrueFalseTotal
$self->_detect_open_desc_tag ? : 72 165 237
207 ? $self->_create_open_desc_tag
208 : $self->$orig();
209 8 };
210  
211 sub _parse_speech_unit
212 175 ▶{
Subroutine _parse_speech_unit: called CC=5 SCAR=16.5
213 175 my $self = shift;
214  
215 175 ▶ if ( ${ $self->curr_line_ref() } !~ /\G([^:\n]+): /cgms )
Branch: 1 branch
BranchTrueFalseTotal
unless (${$self->curr_line_ref;} =~ /\G([^:\n]+): /cgms) 0 175 175
216 {
217 0 Carp::confess( "Cannot match addressing at line " . $self->line_num() );
218 }
219  
220 175 my $sayer = $1;
221  
222 175 ▶ if ( $sayer =~ m{[\[\]]} )
Branch: 1 branch
BranchTrueFalseTotal
if ($sayer =~ /[\[\]]/) 1 174 175
223 {
224 1 Carp::confess(
225 "Tried to put an inner-desc inside an addressing at line "
226 . $self->line_num() );
227 }
228  
229 # All pluses
230 174 ▶ if ( $sayer =~ m{\A\++\z} )
Branch: 1 branch
BranchTrueFalseTotal
if ($sayer =~ /\A\++\z/) { } 43 131 174
231 {
232 43 ▶ if ( not $self->_top_is_saying() )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_top_is_saying) 0 43 43
233 {
234 0 Carp::confess(
235 sprintf(
236 qq{Top element for a "+++:" sayer-syntax is not a saying at line %d},
237 $self->line_num() )
238 );
239 }
240 43 return { elem => $self->_new_para( [] ), para_end => 0 };
241 }
242 else
243 {
244 return {
245 131 elem => $self->_new_saying( $sayer, [] ),
246 sayer => $sayer,
247 para_end => 0
248 };
249 }
250 }
251  
252 sub _non_tag_text_unit_consume_regex
253 800 ▶{
Subroutine _non_tag_text_unit_consume_regex: called CC=1 SCAR=0.0
254 800 return qr{(?:[\<\[\]]|^\n?$)}ms;
255 }
256  
257 sub _is_there_a_speech_unit
258 975 ▶{
Subroutine _is_there_a_speech_unit: called CC=3 SCAR=11.0
259 975 my $self = shift;
260  
261 975 my $l = $self->curr_line_ref();
262  
263 975 ▶ return ( $self->at_line_start()
Condition100%6/6
$self->at_line_start && !$self->_top_is_desc && $$l =~ /\A[^\[][^:]*:/
!ll&&!rl&&r
612188175
$self->at_line_start and not $self->_top_is_desc
!ll&&!rl&&r
59517363
MC/DC100%3/3
$self->at_line_start && !$self->_top_is_desc && $$l =~ /\A[^\[][^:]*:/
$self->at_line_start not $self->_top_is_desc $$l =~ /\A[^\[][^:]*:/
Truth table100%4/4
A and not(B) && C
A= $self->at_line_startB= not $self->_top_is_descC= $$l =~ /\A[^\[][^:]*:/
ABCresult
0XX0
10X0
1100
1111
264 && ( !$self->_top_is_desc() )
265 && ( $$l =~ m{\A[^\[][^:]*:} ) );
266 }
267  
268 975 ▶around '_parse_non_tag_text_unit' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
269 975 my ( $orig, $self ) = @_;
270  
271 return (
272 975 ▶ $self->_is_there_a_speech_unit()
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_there_a_speech_unit ? : 175 800 975
273 ? $self->_parse_speech_unit()
274 : $self->$orig()
275 );
276 8 };
277  
278 sub _look_for_tag_opener
279 1121 ▶{
Subroutine _look_for_tag_opener: called CC=2 SCAR=6.9
280 1121 my $self = shift;
281  
282 1121 my $l = $self->curr_line_ref();
283  
284 1121 ▶ if ( $$l =~ m{\G([<\[\]])} )
Branch: 1 branch
BranchTrueFalseTotal
if ($$l =~ /\G([<\[\]])/) { } 146 975 1121
285 {
286 146 return $1;
287 }
288 else
289 {
290 975 return;
291 }
292 }
293  
294 sub _is_closing_tag
295 146 ▶{
Subroutine _is_closing_tag: called CC=1 SCAR=0.0
296 146 my $self = shift;
297 146 my $tag_start = shift;
298  
299 146 return ( ${ $self->curr_line_ref() } =~ m{\G(</|\])} );
300 }
301  
302 sub _generate_non_tag_text_event
303 975 ▶{
Subroutine _generate_non_tag_text_event: called CC=13 SCAR=25.7
304 975 my $self = shift;
305 975 my $status = $self->_parse_non_tag_text_unit();
306  
307 974 ▶ if ( !defined($status) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $status) 396 578 974
308 {
309 396 return;
310 }
311  
312 578 my $elem = $status->{'elem'};
313 578 my $is_para_end = $status->{'para_end'};
314 578 my $is_saying =
315 $elem->isa("XML::Grammar::Fiction::FromProto::Node::Saying");
316 578 my $is_para =
317 $elem->isa("XML::Grammar::Fiction::FromProto::Node::Paragraph");
318  
319 578 my $in_para = $self->_in_para();
320 578 my $was_already_enqueued = 0;
321  
322 578 ▶ if ( ( $is_saying || $is_para ) && $in_para )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_saying || $is_para and $in_para) 0 578 578
Condition83%5/6
$is_saying || $is_para and $in_para
!ll&&!rl&&r
4041740
$is_saying or $is_para
l!l&&r!l&&!r
13143404
MC/DC0%0/3
$is_saying || $is_para and $in_para
$is_saying $is_para $in_para
Truth table60%3/5
A or B and C
A= $is_sayingB= $is_paraC= $in_para
ABCresult
00X0
1X00
0100
1X11
0111
323 {
324 0 $self->_enqueue_event(
325 XML::Grammar::FictionBase::Event->new(
326 {
327 line_idx => scalar( $self->line_idx() ),
328  
329 type => "close",
330 tag => "para"
331 }
332 )
333 );
334 0 $in_para = 0;
335 }
336  
337 578 ▶ if ( $is_saying && $self->_in_saying() )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_saying and $self->_in_saying) 78 500 578
Condition100%3/3
$is_saying and $self->_in_saying
!ll&&!rl&&r
4475378
MC/DC100%2/2
$is_saying and $self->_in_saying
$is_saying $self->_in_saying
Truth table100%3/3
A and B
A= $is_sayingB= $self->_in_saying
ABresult
0X0
100
111
338 {
339 78 $self->_enqueue_event(
340 XML::Grammar::FictionBase::Event->new(
341 {
342 line_idx => scalar( $self->line_idx() ),
343 type => "close",
344 tag => "saying"
345 }
346 )
347 );
348 }
349  
350 578 ▶ if ($is_saying)
Branch: 2 branches
BranchTrueFalseTotal
if ($is_saying) { } 131 447 578
elsif ($is_para and not $in_para) { } 43 808 851
351 {
352 131 $self->_enqueue_event(
353 XML::Grammar::FictionBase::Event->new(
354 {
355  
356 line_idx => scalar( $self->line_idx() ),
357 type => "open",
358 tag => "saying",
359 tag_elem => $elem,
360 },
361 ),
362 );
363 131 $was_already_enqueued = 1;
364  
365 131 $self->_enqueue_event(
366 XML::Grammar::FictionBase::Event->new(
367 {
368 line_idx => scalar( $self->line_idx() ),
369 type => "open",
370 tag => "para"
371 }
372 )
373 );
374 131 $in_para = 1;
375 }
376 ▶ elsif ( $is_para && !$in_para )
Condition66%2/3
$is_para and not $in_para
!ll&&!rl&&r
404043
MC/DC50%1/2
$is_para and not $in_para
$is_para not $in_para
Truth table66%2/3
A and not(B)
A= $is_paraB= not $in_para
ABresult
0X0
100
111
377 {
378 43 $self->_enqueue_event(
379 XML::Grammar::FictionBase::Event->new(
380 {
381 line_idx => scalar( $self->line_idx() ),
382 type => "open",
383 tag => "para"
384 }
385 ),
386 );
387 43 $in_para = 1;
388 }
389  
390 578 ▶ if ( $elem->isa("XML::Grammar::Fiction::FromProto::Node::Text")
Branch: 1 branch
BranchTrueFalseTotal
if ($elem->isa("XML::Grammar::Fiction::FromProto::Node::Text") and not $was_already_enqueued) 404 174 578
Condition100%3/3
$elem->isa("XML::Grammar::Fiction::FromProto::Node::Text") and not $was_already_enqueued
!ll&&!rl&&r
43131404
MC/DC100%2/2
$elem->isa("XML::Grammar::Fiction::FromProto::Node::Text") and not $was_already_enqueued
$elem->isa("XML::Grammar::Fiction::FromProto::Node::Text") not $was_already_enqueued
Truth table100%3/3
A and not(B)
A= $elem->isa("XML::Grammar::Fiction::FromProto::Node::Text")B= not $was_already_enqueued
ABresult
0X0
100
111
391 && !$was_already_enqueued )
392 {
393 404 ▶ if ( !$in_para )
Branch: 1 branch
BranchTrueFalseTotal
unless ($in_para) 71 333 404
394 {
395 71 $self->_enqueue_event(
396 XML::Grammar::FictionBase::Event->new(
397 {
398 line_idx => scalar( $self->line_idx() ),
399 type => "open",
400 tag => "para"
401 },
402 )
403 );
404 71 $in_para = 1;
405 }
406 $self->_enqueue_event(
407 404 XML::Grammar::FictionBase::Event->new(
408 {
409 line_idx => scalar( $self->line_idx() ),
410 type => "elem",
411 elem => $elem,
412 }
413 )
414 );
415 404 $was_already_enqueued = 1;
416 }
417  
418 578 return;
419 }
420  
421 sub _handle_close_saying
422 130 ▶{
Subroutine _handle_close_saying: called CC=2 SCAR=7.1
423 130 my $self = shift;
424 130 my $open = $self->_pop_tag();
425  
426 # This is an assert.
427 130 ▶ if ( $open->name() ne "saying" )
Branch: 1 branch
BranchTrueFalseTotal
if ($open->name ne "saying") 0 130 130
428 {
429 0 Carp::confess(
430 sprintf( qq{Not a saying tag. open-line = %d .},
431 scalar( $open->line_idx() ) )
432 );
433 }
434  
435 my $new_elem = $self->_new_saying(
436 (
437 130 ▶ List::Util::first { $_->{key} eq "character" }
Subroutine __ANON__: called CC=1 SCAR=0.0
438 130 @{ $open->attrs() }
439 )->{value},
440 130 $open->detach_children(),
441 );
442  
443 130 $self->_add_to_top_tag($new_elem);
444  
445 130 return;
446 }
447  
448 sub _assert_top_is_para
449 265 ▶{
Subroutine _assert_top_is_para: called CC=2 SCAR=7.6
450 265 my ( $self, $open ) = @_;
451  
452 265 ▶ if ( $open->name() ne "p" )
Branch: 1 branch
BranchTrueFalseTotal
if ($open->name ne "p") 0 265 265
453 {
454 0 Carp::confess(qq{Not a para tag.});
455 }
456  
457 265 return;
458 }
459 {
460 8 my $ALLOWED_PARA_PARENTS = +{ 'desc' => 1, 'saying' => 1, };
461  
462 sub _process_closed_para
463 265 ▶ {
Subroutine _process_closed_para: called CC=4 SCAR=14.1
464 265 my ( $self, $open ) = @_;
465  
466 265 my $children = $open->detach_children();
467  
468 # Filter away empty paragraphs.
469 265 ▶ if ( defined($children) && @$children )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $children and @$children) 265 0 265
Condition33%1/3
defined $children and @$children
!ll&&!rl&&r
00265
MC/DC0%0/2
defined $children and @$children
defined $children @$children
Truth table33%1/3
A and B
A= defined $childrenB= @$children
ABresult
0X0
100
111
470 {
471 265 my $para = $self->_new_para($children);
472 265 my $name = $self->_top_tag->name;
473  
474 265 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $ALLOWED_PARA_PARENTS->{$name}) 1 264 265
475 not exists
476  
477 $ALLOWED_PARA_PARENTS->{$name}
478 )
479 {
480 1 Carp::confess(
481 1 qq#Unanchored paragraph not inside a saying or a description at line @{[$open->line()]}#
482 );
483 }
484 264 $self->_add_to_top_tag($para);
485 }
486  
487 264 return;
488 }
489 }
490  
491 sub _close_para
492 8 ▶{
Subroutine _close_para: called CC=1 SCAR=0.0
493 265 my $self = shift;
494  
495 265 my $open = $self->_pop_tag();
496  
497 265 $self->_assert_top_is_para($open);
498  
499 265 $self->_process_closed_para($open);
500  
501 264 $self->_in_para(0);
502  
503 264 return;
504 }
505  
506 sub _create_start_para
507 265 ▶{
Subroutine _create_start_para: called CC=1 SCAR=0.0
508 265 my $self = shift;
509  
510 265 return XML::Grammar::Fiction::Struct::Tag::Para->new(
511 name => "p",
512 is_standalone => 0,
513 line => $self->line_num(),
514 attrs => [],
515 children => [],
516 );
517 }
518  
519 sub _start_para
520 265 ▶{
Subroutine _start_para: called CC=1 SCAR=0.0
521 265 my $self = shift;
522 265 $self->_push_tag( $self->_create_start_para() );
523  
524 265 $self->_in_para(1);
525  
526 265 return;
527 }
528  
529 sub _close_top_tags
530 279 ▶{
Subroutine _close_top_tags: called CC=3 SCAR=11.0
531 279 my $self = shift;
532  
533 279 ▶ if ( $self->_top_is_para() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_top_is_para) 50 229 279
534 {
535 50 $self->_close_para();
536 }
537  
538 279 ▶ if ( $self->_top_is_saying() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_top_is_saying) 52 227 279
539 {
540 52 $self->_handle_close_saying();
541 }
542  
543 279 return;
544 }
545  
546 sub _handle_close_para
547 0 ▶{
Subroutine _handle_close_para: not called CC=1 SCAR=6.9
548 0 my ( $self, $event ) = @_;
549  
550 0 return $self->_close_para();
551 }
552  
553 sub _handle_open_para
554 245 ▶{
Subroutine _handle_open_para: called CC=1 SCAR=0.0
555 245 my ( $self, $event ) = @_;
556  
557 245 return $self->_start_para();
558 }
559  
560 sub _create_open_saying_tag
561 131 ▶{
Subroutine _create_open_saying_tag: called CC=1 SCAR=0.0
562 131 my $self = shift;
563 131 my $event = shift;
564  
565 131 return XML::Grammar::Fiction::Struct::Tag->new(
566 {
567 name => "saying",
568 is_standalone => 0,
569  
570 # TODO : propagate the correct line_num
571 # from the called-to layers.
572 line => $self->line_num(),
573 attrs => [
574 { key => "character", value => $event->tag_elem->character() }
575 ],
576 children => [],
577 }
578 );
579 }
580  
581 sub _handle_open_saying
582 131 ▶{
Subroutine _handle_open_saying: called CC=1 SCAR=0.0
583 131 my ( $self, $event ) = @_;
584  
585 131 $self->_push_tag( $self->_create_open_saying_tag($event) );
586  
587 131 $self->_in_saying(1);
588  
589 131 return;
590 }
591  
592 sub _handle_saying_event
593 0 ▶{
Subroutine _handle_saying_event: not called CC=2 SCAR=17.9
594 0 my ( $self, $event ) = @_;
595  
596 0 ▶ return $event->is_open()
Branch: 1 branch
BranchTrueFalseTotal
$event->is_open ? : 0 0 0
597 ? $self->_handle_open_saying($event)
598 : $self->_handle_close_saying();
599 }
600  
601 sub _list_valid_tag_events
602 6 ▶{
Subroutine _list_valid_tag_events: called CC=1 SCAR=0.0
603 6 return [qw(para saying)];
604 }
605  
606 236 ▶before '_handle_open_tag' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
607 236 my $self = shift;
608  
609 236 ▶ if ( $self->_top_is_desc )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_top_is_desc) 20 216 236
610 {
611 20 ▶ if ( !$self->_in_para() )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_in_para) 20 0 20
612 {
613 20 $self->_start_para();
614 }
615 }
616  
617 236 return;
618 8 };
619  
620 211 ▶before '_handle_close_tag' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
621 211 my $self = shift;
622  
623 211 $self->_close_top_tags();
624 8 };
625  
626 sub _look_ahead_for_tag
627 1235 ▶{
Subroutine _look_ahead_for_tag: called CC=2 SCAR=6.9
628 1235 my $self = shift;
629  
630 1235 my $l = $self->curr_line_copy();
631  
632 1235 my $is_tag_cond = ( $$l =~ m{\G([<\[\]])} );
633  
634 1235 ▶ my $is_close = $is_tag_cond && ( $$l =~ m{\G(?:</|\])} );
Condition100%3/3
$is_tag_cond && $$l =~ m(\G(?:</|\]))
!ll&&!rl&&r
788236211
MC/DC100%2/2
$is_tag_cond && $$l =~ m(\G(?:</|\]))
$is_tag_cond $$l =~ m(\G(?:</|\]))
Truth table100%3/3
A && B
A= $is_tag_condB= $$l =~ m(\G(?:</|\]))
ABresult
0X0
100
111
635  
636 1235 return ( $is_tag_cond, $is_close );
637 }
638  
639 sub _main_loop_iter_on_empty_line
640 414 ▶{
Subroutine _main_loop_iter_on_empty_line: called CC=2 SCAR=6.9
641 414 my $self = shift;
642  
643 414 ▶ if ( $self->_top_is_para() )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_top_is_para) 215 199 414
644 {
645 215 $self->_close_para();
646 }
647  
648 413 $self->next_line_ref();
649  
650 413 return;
651 }
652  
653 sub _main_loop_iter_on_whitepsace
654 0 ▶{
Subroutine _main_loop_iter_on_whitepsace: not called CC=1 SCAR=6.9
655 0 my $self = shift;
656  
657 0 $self->_add_to_top_tag( $self->_new_text( [" "] ) );
658  
659 0 $self->next_line_ref();
660  
661 0 return;
662 }
663  
664 sub _main_loop_iter_body_prelude
665 1649 ▶{
Subroutine _main_loop_iter_body_prelude: called CC=3 SCAR=11.1
666 1649 my $self = shift;
667  
668 1649 my $l = $self->curr_line_ref();
669  
670 return (
671 1649 ▶ ( $$l eq "\n" ) ? $self->_main_loop_iter_on_empty_line
Branch: 2 branches
BranchTrueFalseTotal
$$l eq "\n" ? : 414 1235 1649
$$l =~ /\G[ \t]+\n?\z/ ? : 0 1235 1235
672 : ( $$l =~ m{\G[ \t]+\n?\z} ) ? $self->_main_loop_iter_on_whitepsace
673 : 1
674 );
675 }
676  
677  
678 8 1;
679  
680 __END__
« blib/lib/XML/Grammar/FictionBase/TagsTree2XML.pm ↑ Summary blib/lib/XML/Grammar/Fiction/FromProto.pm »