blib/lib/XML/Grammar/FictionBase/FromProto/Parser/LineIterator.pm

filter: Statementstmt 100% 90 / 90 Branchbran 87.5% 14 / 16 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 21 / 21 Podpod 100% 15 / 15 totaltotal 96.0% 146 / 152 CC 11 SCAR 7.4
CC
11
Cov
96%
consume
5.0
consume_up_to
3.0
_next_line_ref_wo_leading_space
2.0
CRAP 2.1
« blib/lib/XML/Grammar/Screenplay/App/FromProto.pm ↑ Summary blib/lib/XML/Grammar/Fiction/FromProto/Node/WithContent.pm »
1 package XML::Grammar::FictionBase::FromProto::Parser::LineIterator;
2 23 $XML::Grammar::FictionBase::FromProto::Parser::LineIterator::VERSION = '0.32.0';
3 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 23 ▶use MooX 'late';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 23 ▶use XML::Grammar::Fiction::Err ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 23 extends("XML::Grammar::Fiction::FromProto::Parser");
11  
12 23 has "_curr_line_idx" => ( isa => "Int", is => "rw", reader => "line_idx", );
13 23 has "_lines" => ( isa => "ArrayRef", is => "rw" );
14  
15  
16 sub setup_text
17 64 ▶{
Subroutine setup_text: called CC=1 SCAR=0.0
Pod documented
18 64 my ( $self, $text ) = @_;
19  
20 # We include the lines trailing newlines for safety.
21 64 $self->_lines( [ split( /^/, $text ) ] );
22  
23 64 $self->_curr_line_idx(0);
24  
25 64 ${ $self->curr_line_ref() } =~ m{\A}g;
26  
27 64 return;
28 }
29  
30  
31 sub curr_line_ref
32 31754 ▶{
Subroutine curr_line_ref: called CC=1 SCAR=0.0
Pod documented
33 31754 my $self = shift;
34  
35 31754 return \( $self->_lines()->[ $self->_curr_line_idx() ] );
36 }
37  
38  
39 sub curr_pos
40 5081 ▶{
Subroutine curr_pos: called CC=1 SCAR=0.0
Pod documented
41 5081 my $self = shift;
42  
43 5081 return pos( ${ $self->curr_line_ref() } );
44 }
45  
46  
47 sub at_line_start
48 2527 ▶{
Subroutine at_line_start: called CC=1 SCAR=0.0
Pod documented
49 2527 my $self = shift;
50  
51 2527 return ( $self->curr_pos == 0 );
52 }
53  
54  
55 sub curr_line_and_pos
56 1 ▶{
Subroutine curr_line_and_pos: called CC=1 SCAR=0.0
Pod documented
57 1 my $self = shift;
58  
59 1 return ( $self->curr_line_ref(), $self->curr_pos() );
60 }
61  
62  
63 sub curr_line_copy
64 2175 ▶{
Subroutine curr_line_copy: called CC=1 SCAR=0.0
Pod documented
65 2175 my $self = shift;
66  
67 2175 my $l = ${ $self->curr_line_ref() } . "";
68  
69 2175 pos($l) = $self->curr_pos();
70  
71 2175 return \$l;
72 }
73  
74  
75 sub next_line_ref
76 1738 ▶{
Subroutine next_line_ref: called CC=2 SCAR=6.9
Pod documented
77 1738 my $self = shift;
78  
79 1738 $self->_curr_line_idx( $self->_curr_line_idx() + 1 );
80  
81 1738 ▶ if ( !$self->eof() )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->eof) 1737 1 1738
82 {
83 1737 pos( ${ $self->curr_line_ref() } ) = 0;
84 }
85  
86 1738 return $self->curr_line_ref();
87 }
88  
89  
90 # Skip the whitespace.
91 sub skip_space
92 225 ▶{
Subroutine skip_space: called CC=1 SCAR=0.0
Pod documented
93 225 my $self = shift;
94  
95 225 $self->consume(qr{[ \t]});
96  
97 225 return;
98 }
99  
100  
101 sub skip_multiline_space
102 627 ▶{
Subroutine skip_multiline_space: called CC=2 SCAR=6.9
Pod documented
103 627 my $self = shift;
104  
105 627 ▶ if ( ${ $self->curr_line_ref() } =~ m{\G.*?\S} )
Branch: 1 branch
BranchTrueFalseTotal
if (${$self->curr_line_ref;} =~ /\G.*?\S/) 235 392 627
106 {
107 235 return;
108 }
109  
110 392 $self->consume(qr{\s});
111  
112 391 return;
113 }
114  
115  
116 sub curr_line_continues_with
117 2611 ▶{
Subroutine curr_line_continues_with: called CC=1 SCAR=0.0
Pod documented
118 2611 my ( $self, $re ) = @_;
119  
120 2611 my $l = $self->curr_line_ref();
121  
122 2611 return $$l =~ m{\G$re}cg;
123 }
124  
125  
126 sub line_num
127 1382 ▶{
Subroutine line_num: called CC=1 SCAR=0.0
Pod documented
128 1382 my $self = shift;
129  
130 1382 return $self->_curr_line_idx() + 1;
131 }
132  
133  
134 sub _next_line_ref_wo_leading_space
135 1325 ▶{
Subroutine _next_line_ref_wo_leading_space: called CC=2 SCAR=7.0
136 1325 my $self = shift;
137  
138 1325 my $l = $self->next_line_ref();
139  
140 1325 ▶ if ( defined($$l) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$l) 1325 0 1325
141 {
142 1325 $self->_check_if_line_starts_with_whitespace();
143 }
144  
145 1323 return $l;
146 }
147  
148 sub consume
149 621 ▶{
Subroutine consume: called CC=5 SCAR=16.2
Pod documented
150 621 my ( $self, $match_regex ) = @_;
151  
152 621 my $return_value = "";
153 621 my $l = $self->curr_line_ref();
154  
155 621 ▶ while ( defined($$l) && ( $$l =~ m[\G(${match_regex}*)\z]cgms ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$l and $$l =~ /\G($match_regex*)\z/cgms) 670 620 1290
Condition66%2/3
defined $$l and $$l =~ /\G($match_regex*)\z/cgms
!ll&&!rl&&r
0620670
MC/DC50%1/2
defined $$l and $$l =~ /\G($match_regex*)\z/cgms
defined $$l $$l =~ /\G($match_regex*)\z/cgms
Truth table66%2/3
A and B
A= defined $$lB= $$l =~ /\G($match_regex*)\z/cgms
ABresult
0X0
100
111
156 {
157 670 $return_value .= $$l;
158 }
159 continue
160 {
161 670 $l = $self->_next_line_ref_wo_leading_space();
162 }
163  
164 620 ▶ if ( defined($$l) && ( $$l =~ m[\G(${match_regex}*)]cg ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$l and $$l =~ /\G($match_regex*)/cg) 597 23 620
Condition66%2/3
defined $$l and $$l =~ /\G($match_regex*)/cg
!ll&&!rl&&r
023597
MC/DC50%1/2
defined $$l and $$l =~ /\G($match_regex*)/cg
defined $$l $$l =~ /\G($match_regex*)/cg
Truth table66%2/3
A and B
A= defined $$lB= $$l =~ /\G($match_regex*)/cg
ABresult
0X0
100
111
165 {
166 597 $return_value .= $1;
167 }
168  
169 620 return $return_value;
170 }
171  
172  
173 # TODO : copied and pasted from _consume - abstract
174 sub consume_up_to
175 1079 ▶{
Subroutine consume_up_to: called CC=3 SCAR=11.0
Pod documented
176 1079 my ( $self, $match_regex ) = @_;
177  
178 1079 my $return_value = "";
179 1079 my $l = $self->curr_line_ref();
180  
181 LINE_LOOP:
182 1079 ▶ while ( defined($$l) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$l) 1733 0 1733
183 {
184 # We assign to a scalar for scalar context, but we're not making
185 # use of the variable.
186 1733 my $verdict = ( $$l =~ m[\G(.*?)((?:${match_regex})|\z)]cgms );
187 1733 $return_value .= $1;
188  
189 # Find if it matched the regex.
190 1733 ▶ if ( length($2) > 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (length $2 > 0) 1078 655 1733
191 {
192 1078 last LINE_LOOP;
193 }
194 }
195 continue
196 {
197 655 $l = $self->_next_line_ref_wo_leading_space();
198 }
199  
200 1078 return $return_value;
201 }
202  
203  
204 sub throw_text_error
205 5 ▶{
Subroutine throw_text_error: called CC=1 SCAR=0.0
Pod documented
206 5 my ( $self, $error_class, $text ) = @_;
207  
208 5 return $error_class->throw(
209 error => $text,
210 line => $self->line_num(),
211 );
212 }
213  
214 sub _check_if_line_starts_with_whitespace
215 1325 ▶{
Subroutine _check_if_line_starts_with_whitespace: called CC=2 SCAR=6.9
216 1325 my $self = shift;
217  
218 1325 ▶ if ( ${ $self->curr_line_ref() } =~ m{\A[ \t]} )
Branch: 1 branch
BranchTrueFalseTotal
if (${$self->curr_line_ref;} =~ /\A[ \t]/) 2 1323 1325
219 {
220 2 $self->throw_text_error(
221 'XML::Grammar::Fiction::Err::Parse::LeadingSpace',
222 "Leading space detected in the text.",
223 );
224 }
225 }
226  
227  
228 sub eof
229 4726 ▶{
Subroutine eof: called CC=1 SCAR=0.0
Pod documented
230 4726 my $self = shift;
231  
232 4726 return ( !defined( ${ $self->curr_line_ref() } ) );
233 }
234  
235  
236 23 1;
237  
238 __END__
« blib/lib/XML/Grammar/Screenplay/App/FromProto.pm ↑ Summary blib/lib/XML/Grammar/Fiction/FromProto/Node/WithContent.pm »