lib/TUI/Help/HelpFile.pm

filter: Statementstmt 20.5% 73 / 356 Branchbran 0.0% 0 / 176 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 39.0% 16 / 41 Podpod 87.5% 7 / 8 totaltotal 15.2% 96 / 631 CC 100 SCAR 49.8
CC
100
Cov
13%
__ANON__
462.0
__ANON__
240.0
__ANON__
156.0
CRAP 145.8
« lib/TUI/StdDlg/SortedListBox.pm ↑ Summary lib/TUI/Dialogs/StaticText.pm »
1 package TUI::Help::HelpFile;
2 # ABSTRACT: help-source indexing and topic parsing
3
4 7 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 7 our $VERSION = '2.000003';
9 7 $VERSION =~ tr/_//d;
10 7 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 7 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 our @EXPORT = qw(
14 THelpFile
15 new_THelpFile
16 );
17
18 7 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
21 :is
22 :types
23 7 );
24
25 7 ▶use TUI::Help::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
26 MAXHELPTOPICID
27 :wrapXXXX
28 7 );
29 7 ▶use TUI::Help::HelpBase;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 7 ▶use TUI::Help::HelpIndex;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 7 ▶use TUI::Help::HelpTopic;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 7 ▶use TUI::Help::RefTable;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 7 ▶use TUI::Help::TopicDefinition;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 7 ▶use TUI::MsgBox::Const qw( mfError mfOKButton );
Subroutine BEGIN: called CC=1 SCAR=0.0
35 7 ▶use TUI::MsgBox::MsgBoxText qw( messageBox );
Subroutine BEGIN: called CC=1 SCAR=0.0
36 7 ▶use TUI::Objects::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
37
38 sub THelpFile() { __PACKAGE__ }
39 0 ▶sub new_THelpFile { __PACKAGE__->from(@_) }
Subroutine new_THelpFile: not called CC=1 SCAR=6.9
Pod documented
40
41 # global variables
42 7 our $invalidContext = "\n No help available in this context.";
43
44 7 extends TObject;
45
46 # public attributes
47 7 has stream => ( is => 'rw', default => undef );
48 7 has modified => ( is => 'rw', default => false );
49 7 has index => ( is => 'rw', default => undef );
50 7 has indexPos => ( is => 'rw', default => 0 );
51
52 # private attributes
53 7 has references => ( is => 'bare' );
54 7 has helpCounter => ( is => 'bare', default => 2 ); # 1 is hcDragging.
55 7 has parseError => ( is => 'bare' );
56
57 # private methods
58 my (
59 7 $error,
60 $readLine,
61 $processText,
62 $readTopic,
63 $topicDefinition,
64 $topicDefinitionList,
65 $topicHeader,
66 $scanForCrossRefs,
67 $isEndParagraph,
68 $readParagraph
69 );
70
71 7 my $commandChar = '.';
72
73 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
74 0 state $sig = signature(
75 method => 1,
76 named => [
77 stream => FileHandle,
78 ],
79 caller_level => +1,
80 );
81 0 my ( $class, $args ) = $sig->( @_ );
82 0 return { %$args };
83 }
84
85 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=4 SCAR=30.0
Pod documented
86 0 my ( $self, $args ) = @_;
87 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
88 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
89 0 $self->{index} = THelpIndex->new();
90 0 $self->{references} = TRefTable->new( limit => 5, delta => 5 );
91 0 ▶ unless ( seek( $self->{stream}, 0, 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $self->{"stream"}, 0, 0) 0 0 0
92 0 $self->$error( "Cannot seek to start of help source: $!" );
93 0 return;
94 }
95 0 $self->$processText();
96 0 return;
97 }
98
99 0 ▶sub from { # $helpFile ($s)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
100 0 state $sig = signature(
101 method => 1,
102 pos => [FileHandle],
103 );
104 0 my ( $class, $s ) = $sig->( @_ );
105 0 return $class->new( stream => $s );
106 }
107
108 0 ▶sub getTopic { # $topic ($context)
Subroutine getTopic: not called CC=3 SCAR=24.8
Pod documented
109 0 state $sig = signature(
110 method => Object,
111 pos => [Int],
112 );
113 0 my ( $self, $context ) = $sig->( @_ );
114 0 ▶ return $self->invalidTopic()
Branch: 1 branch
BranchTrueFalseTotal
if $context < 0 0 0 0
115 if $context < 0;
116 0 my $position = $self->{index}->position( $context );
117 0 ▶ return $self->invalidTopic()
Branch: 1 branch
BranchTrueFalseTotal
if $position < 0 0 0 0
118 if $position < 0;
119 0 return $self->$readTopic( $position );
120 }
121
122 0 ▶sub invalidTopic { # $topic ()
Subroutine invalidTopic: not called CC=1 SCAR=6.9
Pod documented
123 0 state $sig = signature(
124 method => Object,
125 pos => [],
126 );
127 0 my ( $self ) = $sig->( @_ );
128 0 my $topic = THelpTopic->new();
129 0 $topic->addParagraph(
130 TParagraph->new(
131 text => $invalidContext,
132 size => length( $invalidContext ),
133 wrap => false,
134 next => undef,
135 ),
136 );
137 0 return $topic;
138 }
139
140 0 ▶sub recordPositionInIndex { # void ($context)
Subroutine recordPositionInIndex: not called CC=1 SCAR=6.9
Pod documented
141 0 state $sig = signature(
142 method => Object,
143 pos => [Int],
144 );
145 0 my ( $self, $context ) = $sig->( @_ );
146 ...
147 0 }
148
149 0 ▶sub putTopic { # void ($topic)
Subroutine putTopic: not called CC=1 SCAR=6.9
Pod documented
150 0 state $sig = signature(
151 method => Object,
152 pos => [Object],
153 );
154 0 my ( $self, $topic ) = $sig->( @_ );
155 0 ...;
156 0 return;
157 }
158
159 0 ▶$error = sub { # void ($self, $text)
Subroutine __ANON__: not called CC=4 SCAR=30.0
160 0 my ( $self, $text ) = @_;
161 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
162 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
163 0 ▶ assert ( is_Str $text );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($text) 0 0 0
164 0 $self->{parseError} = $text;
165 0 messageBox( $text, mfError | mfOKButton );
166 0 return;
167 7 };
168
169 0 ▶$readLine = sub { # $line|undef ($self, $textFile)
Subroutine __ANON__: not called CC=6 SCAR=37.4
170 0 my ( $self, $textFile ) = @_;
171 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
172 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
173 0 ▶ assert ( is_FileHandle $textFile );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_FileHandle($textFile) 0 0 0
174
175 0 local $/ = "\n";
176 0 local $! = 0;
177 0 my $line = readline( $textFile );
178 0 ▶ unless ( defined $line ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line) 0 0 0
179 0 ▶ $self->$error( "Cannot read help source: $!" ) if $!;
Branch: 1 branch
BranchTrueFalseTotal
if $! 0 0 0
180 0 return undef;
181 }
182 0 $line =~ s/(?:\r?\n|\r)\z//;
183 0 return $line;
184 7 };
185
186 #
187 # Help source format, adapted from the Turbo Vision help compiler:
188 #
189 # THelpFile indexes a seekable text source and reads topics on demand. It
190 # does not generate a compiled help file or a separate context file.
191 #
192 # A topic begins with a header of the form:
193 #
194 # .topic symbol[=number][, symbol[=number]...]
195 #
196 # Multiple symbols give the same topic different numeric contexts. The first
197 # automatic number is 3; after an explicit number, automatic numbering
198 # continues from that number. For example:
199 #
200 # .topic FileOpen=3, OpenFile, FFileOpen
201 #
202 # assigns contexts 3, 4, and 5 to the three names. Later topic headers
203 # must start at the beginning of a line.
204 #
205 # Text following a header forms the topic body. Adjacent lines beginning
206 # without a space form a wrapped paragraph. Lines beginning with a space
207 # retain their line breaks and are not wrapped. Blank lines and a change
208 # between these modes separate paragraphs. Lines beginning with ';' are
209 # skipped.
210 #
211 # .topic FileOpen
212 # File|Open
213 # ---------
214 # This text is wrapped to fit the help window.
215 #
216 # Cross-references use {text} or {text:alias}; text is displayed and the
217 # optional alias names the destination topic. For example:
218 #
219 # See the {file open dialog:FileOpen} or {ChDir}.
220 #
221 # Outside a reference, '{{' produces a literal '{'. Inside a reference,
222 # double ':' or '}' to produce a literal character. References can point
223 # forward: all topic names are indexed before a topic is read. An unknown
224 # name produces a warning when the topic is read and uses context -1;
225 # requesting that context returns the invalid-topic message.
226 #
227 0 ▶$processText = sub { # $bool ($self)
Subroutine __ANON__: not called CC=15 SCAR=54.8
228 0 my ( $self ) = @_;
229 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
230 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
231
232 0 my $stream = $self->{stream};
233 0 my $index = THelpIndex->new();
234 0 my $references = TRefTable->new( limit => 5, delta => 5 );
235 0 my $counter = $self->{helpCounter};
236 0 $self->{parseError} = undef;
237 {
238 0 local $self->{helpCounter} = $counter;
239 0 my $seenTopic = false;
240 0 ▶ while ( defined( my $line = $self->$readLine( $stream ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = $self->$readLine($stream))) 0 0 0
241 0 ▶ last if $line =~ /\A[\0\cZ]/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A[\0\cZ]/ 0 0 0
242 0 ▶ next if $line eq '' || $line =~ /\A;/;
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "" or $line =~ /\A;/ 0 0 0
Condition0%0/3
$line eq "" or $line =~ /\A;/
l!l&&r!l&&!r
000
MC/DC0%0/2
$line eq "" or $line =~ /\A;/
$line eq "" $line =~ /\A;/
Truth table0%0/3
A or B
A= $line eq ""B= $line =~ /\A;/
ABresult
1X1
011
000
243 0 ▶ if ( $seenTopic ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($seenTopic) { } 0 0 0
elsif (not $line =~ /\A[ \t]*\Q$commandChar\E/) { } 0 0 0
244 0 ▶ next unless $line =~ /\A\Q$commandChar\E/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\A\Q$commandChar\E/ 0 0 0
245 }
246 elsif ( $line !~ /\A[ \t]*\Q$commandChar\E/ ) {
247 0 $self->$error( 'TOPIC expected' );
248 0 return false;
249 }
250
251 0 my $definitions = $self->$topicHeader( $line );
252 0 ▶ return false unless $definitions;
Branch: 1 branch
BranchTrueFalseTotal
unless $definitions 0 0 0
253 0 my $position = tell( $stream );
254 0 ▶ if ( $position < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($position < 0) 0 0 0
255 0 $self->$error( "Cannot tell help source position: $!" );
256 0 return false;
257 }
258 0 ▶ for ( my $p = $definitions; $p; $p = $p->next ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p) 0 0 0
259 0 my $reference = $references->getReference( $p->topic );
260 0 ▶ if ( $reference->resolved ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reference->resolved) 0 0 0
261 0 $self->$error( 'Redefinition of ' . $p->topic );
262 0 return false;
263 }
264 0 $reference->val( $p->value );
265 0 $reference->resolved( true );
266 0 $index->add( $p->value, $position );
267 }
268 0 $seenTopic = true;
269 }
270 0 ▶ return false if defined $self->{parseError};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"parseError"} 0 0 0
271 0 $counter = $self->{helpCounter};
272 }
273 0 $self->{index} = $index;
274 0 $self->{references} = $references;
275 0 $self->{helpCounter} = $counter;
276 0 return true;
277 7 };
278
279 # Read a topic's paragraphs at an indexed position and resolve its references.
280 0 ▶sub _readTopic { goto $readTopic }
Subroutine _readTopic: not called CC=1 SCAR=6.9
281 0 ▶$readTopic = sub { # $topic|undef ($self, $position)
Subroutine __ANON__: not called CC=9 SCAR=45.0
282 0 my ( $self, $position ) = @_;
283 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
284 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
285 0 ▶ assert ( is_PositiveOrZeroInt $position );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_PositiveOrZeroInt($position) 0 0 0
286
287 0 my $stream = $self->{stream};
288 0 $self->{parseError} = undef;
289 0 ▶ unless ( seek( $stream, $position, 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $stream, $position, 0) 0 0 0
290 0 $self->$error( "Cannot seek to help topic: $!" );
291 0 return undef;
292 }
293 0 my $topic = THelpTopic->new();
294 0 my $offset = 0;
295 0 my @refs;
296 0 ▶ while ( my $paragraph =
Branch: 1 branch
BranchTrueFalseTotal
if (my $paragraph = $self->$readParagraph($stream, \$offset, \@refs)) 0 0 0
297 $self->$readParagraph( $stream, \$offset, \@refs ) ) {
298 0 $topic->addParagraph( $paragraph );
299 }
300 0 ▶ return undef if defined $self->{parseError};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"parseError"} 0 0 0
301
302 0 for my $entry ( @refs ) {
303 0 my $reference = $self->{references}->getReference( $entry->{topic} );
304 0 ▶ if ( $reference->resolved ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reference->resolved) { } 0 0 0
305 0 $entry->{crossRef}->ref( $reference->val );
306 }
307 else {
308 0 Carp::carp( 'Unresolved forward reference "' . $entry->{topic} . '"' );
309 0 $entry->{crossRef}->ref( -1 );
310 }
311 0 $topic->addCrossRef( $entry->{crossRef} );
312 }
313 0 return $topic;
314 7 };
315
316 # Extracts the next topic definition from the given line at i.
317 0 ▶sub _topicDefinition { goto $topicDefinition }
Subroutine _topicDefinition: not called CC=1 SCAR=6.9
318 0 ▶$topicDefinition = sub { # $definition|undef ($self, $line, \$i)
Subroutine __ANON__: not called CC=12 SCAR=50.5
319 0 my ( $self, $line, $i ) = @_;
320 0 ▶ assert ( @_ == 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
321 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
322 0 ▶ assert ( is_Str $line );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($line) 0 0 0
323 0 ▶ assert ( is_ScalarRef $i and is_PositiveOrZeroInt $$i );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_ScalarRef($i) and &is_PositiveOrZeroInt($$i) 0 0 0
Condition0%0/3
&is_ScalarRef($i) and &is_PositiveOrZeroInt($$i)
!ll&&!rl&&r
000
MC/DC0%0/2
&is_ScalarRef($i) and &is_PositiveOrZeroInt($$i)
&is_ScalarRef($i) &is_PositiveOrZeroInt($$i)
Truth table0%0/3
A and B
A= &is_ScalarRef($i)B= &is_PositiveOrZeroInt($$i)
ABresult
0X0
100
111
324
325 0 pos( $line ) = $$i;
326 0 ▶ unless ( $line =~ /
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ / \G[ \t]*+([A-Za-z0-9_]+|[^\0]) (?:[ \t]*(=)[ \t]*+([A-Za-z0-9_]+|[^\0])?)? /cgx) 0 0 0
327 \G[ \t]*+([A-Za-z0-9_]+|[^\0])
328 (?:[ \t]*(=)[ \t]*+([A-Za-z0-9_]+|[^\0])?)?
329 /gcx ) {
330 0 ▶ $$i = length( $line ) if $$i < length( $line );
Branch: 1 branch
BranchTrueFalseTotal
if $$i < length $line 0 0 0
331 0 $self->$error( 'Expected topic definition' );
332 0 return undef;
333 }
334
335 0 my ( $topic, $equals, $value ) = ( $1, $2, $3 );
336 0 $$i = pos( $line );
337 0 ▶ if ( defined $equals ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $equals) { } 0 0 0
338 0 ▶ if ( !defined $value || $value !~ /\A[0-9]+\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value and $value =~ /\A[0-9]+\z/) 0 0 0
Condition0%0/3
defined $value and $value =~ /\A[0-9]+\z/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and $value =~ /\A[0-9]+\z/
defined $value $value =~ /\A[0-9]+\z/
Truth table0%0/3
A and B
A= defined $valueB= $value =~ /\A[0-9]+\z/
ABresult
0X0
100
111
339 0 $self->$error( 'Expected numeric' );
340 0 return undef;
341 }
342 0 $self->{helpCounter} = 0 + $value;
343 }
344 else {
345 0 ++$self->{helpCounter};
346 }
347
348 0 ▶ if ( $self->{helpCounter} > MAXHELPTOPICID ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"helpCounter"} > 1073414144) 0 0 0
349 0 $self->$error(
350 "Topic id for topic '$topic' exceeds limit of " . MAXHELPTOPICID,
351 );
352 0 return undef;
353 }
354
355 return TTopicDefinition->new(
356 topic => $topic, value => $self->{helpCounter},
357 0 );
358 7 };
359
360 # Extracts a list of topic definitions from the given line at i.
361 0 ▶sub _topicDefinitionList { goto $topicDefinitionList }
Subroutine _topicDefinitionList: not called CC=1 SCAR=6.9
362 0 ▶$topicDefinitionList = sub { # $topicList|undef ($self, $line, \$i)
Subroutine __ANON__: not called CC=8 SCAR=42.8
363 0 my ( $self, $line, $i ) = @_;
364 0 ▶ assert ( @_ == 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
365 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
366 0 ▶ assert ( is_Str $line );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($line) 0 0 0
367 0 ▶ assert ( is_ScalarRef $i and is_PositiveOrZeroInt $$i );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_ScalarRef($i) and &is_PositiveOrZeroInt($$i) 0 0 0
Condition0%0/3
&is_ScalarRef($i) and &is_PositiveOrZeroInt($$i)
!ll&&!rl&&r
000
MC/DC0%0/2
&is_ScalarRef($i) and &is_PositiveOrZeroInt($$i)
&is_ScalarRef($i) &is_PositiveOrZeroInt($$i)
Truth table0%0/3
A and B
A= &is_ScalarRef($i)B= &is_PositiveOrZeroInt($$i)
ABresult
0X0
100
111
368
369 0 my $topicList;
370 0 while ( true ) {
371 0 my $p = $self->$topicDefinition( $line, $i );
372 0 ▶ return undef unless $p;
Branch: 1 branch
BranchTrueFalseTotal
unless $p 0 0 0
373 0 $p->next( $topicList );
374 0 $topicList = $p;
375 0 pos( $line ) = $$i;
376 0 ▶ last unless $line =~ /\G[ \t]*,/gc;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\G[ \t]*,/cg 0 0 0
377 0 $$i = pos( $line );
378 }
379 0 return $topicList;
380 7 };
381
382 # Parse a topic header.
383 0 ▶sub _topicHeader { goto $topicHeader }
Subroutine _topicHeader: not called CC=1 SCAR=6.9
384 0 ▶$topicHeader = sub { # $topicList|undef ($self, $line)
Subroutine __ANON__: not called CC=7 SCAR=40.3
385 0 my ( $self, $line ) = @_;
386 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
387 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
388 0 ▶ assert ( is_Str $line );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($line) 0 0 0
389
390 0 ▶ return undef unless $line =~ /\A[ \t]*\Q$commandChar\E/gc;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /\A[ \t]*\Q$commandChar\E/cg 0 0 0
391 0 ▶ unless ( $line =~ /\G[ \t]*([A-Za-z0-9_]+)/gc
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /\G[ \t]*([A-Za-z0-9_]+)/cg and uc $1 eq "TOPIC") 0 0 0
Condition0%0/3
$line =~ /\G[ \t]*([A-Za-z0-9_]+)/cg and uc $1 eq "TOPIC"
!ll&&!rl&&r
000
MC/DC0%0/2
$line =~ /\G[ \t]*([A-Za-z0-9_]+)/cg and uc $1 eq "TOPIC"
$line =~ /\G[ \t]*([A-Za-z0-9_]+)/cg uc $1 eq "TOPIC"
Truth table0%0/3
A and B
A= $line =~ /\G[ \t]*([A-Za-z0-9_]+)/cgB= uc $1 eq "TOPIC"
ABresult
0X0
100
111
392 && uc( $1 ) eq 'TOPIC' ) {
393 0 $self->$error( 'TOPIC expected' );
394 0 return undef;
395 }
396 0 my $i = pos( $line );
397 0 return $self->$topicDefinitionList( $line, \$i );
398 7 };
399
400 0 ▶sub _scanForCrossRefs { goto $scanForCrossRefs }
Subroutine _scanForCrossRefs: not called CC=1 SCAR=6.9
401 0 ▶$scanForCrossRefs = sub { # $bool ($self, \$line, $offset, $xRefs)
Subroutine __ANON__: not called CC=12 SCAR=50.5
402 0 my ( $self, $line, $offset, $xRefs ) = @_;
403 0 ▶ assert ( @_ == 4 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 4 0 0 0
404 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
405 0 ▶ assert ( is_ScalarRef $line and is_Str $$line );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_ScalarRef($line) and &is_Str($$line) 0 0 0
Condition0%0/3
&is_ScalarRef($line) and &is_Str($$line)
!ll&&!rl&&r
000
MC/DC0%0/2
&is_ScalarRef($line) and &is_Str($$line)
&is_ScalarRef($line) &is_Str($$line)
Truth table0%0/3
A and B
A= &is_ScalarRef($line)B= &is_Str($$line)
ABresult
0X0
100
111
406 0 ▶ assert ( is_PositiveOrZeroInt $offset );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_PositiveOrZeroInt($offset) 0 0 0
407 0 ▶ assert ( is_ArrayRef $xRefs );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_ArrayRef($xRefs) 0 0 0
408
409 # The base offset includes text buffered earlier in this paragraph.
410 0 my $text = $$line;
411 0 my $result = '';
412 0 pos( $text ) = 0;
413 0 ▶ while ( $text =~ /\G([^{]*)(\{\{|\{|\z)/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /\G([^{]*)(\{\{|\{|\z)/cg) 0 0 0
414 0 my ( $plain, $opening ) = ( $1, $2 );
415 0 $result .= $plain;
416 0 ▶ last if $opening eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $opening eq "" 0 0 0
417 0 ▶ if ( $opening eq '{{' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opening eq "{{") 0 0 0
418 0 $result .= '{';
419 0 next;
420 }
421
422 0 my $start = pos( $text ) - 1;
423 0 ▶ unless ( $text =~ /\G((?:[^}]|\}\})*+)\}/gc ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($text =~ /\G((?:[^}]|\}\})*+)\}/cg) 0 0 0
424 0 $$line = $result . substr( $text, $start );
425 0 $self->$error( 'Unterminated topic reference.' );
426 0 return false;
427 }
428 0 my $reference = $1;
429 0 $reference =~ s/\}\}/}/g;
430
431 0 my ( $display, $topic );
432 0 ▶ if ( $reference =~ /\A((?:[^:]|::)*+):(.*)\z/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reference =~ /\A((?:[^:]|::)*+):(.*)\z/s) { } 0 0 0
433 0 ( $display, $topic ) = ( $1, $2 );
434 0 $display =~ s/::/:/g;
435 }
436 else {
437 0 $reference =~ s/::/:/g;
438 0 ( $display, $topic ) = ( $reference, $reference );
439 }
440
441 0 push @$xRefs, {
442 topic => $topic,
443 crossRef => TCrossRef->new(
444 ref => scalar @$xRefs,
445 offset => $offset + length( $result ) + 1,
446 length => length( $display ),
447 ),
448 };
449 0 $display =~ tr/ /\xFF/;
450 0 $result .= $display;
451 }
452 0 $$line = $result;
453 0 return true;
454 7 };
455
456 0 ▶sub _isEndParagraph { goto $isEndParagraph }
Subroutine _isEndParagraph: not called CC=1 SCAR=6.9
457 0 ▶$isEndParagraph = sub { # $bool ($self, $line, $state)
Subroutine __ANON__: not called CC=10 SCAR=47.0
458 0 my ( $self, $line, $state ) = @_;
459 0 ▶ assert ( @_ == 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
460 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
461 0 ▶ assert ( is_Str $line );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($line) 0 0 0
462 0 ▶ assert ( is_Int $state );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Int($state) 0 0 0
463
464 0 ▶ return true if $line =~ /\A(?:\z|[\0\cZ]|\Q$commandChar\E)/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A(?:\z|[\0\cZ]|\Q$commandChar\E)/ 0 0 0
465 0 ▶ return true if $state == wrapping && $line =~ /\A /;
Branch: 1 branch
BranchTrueFalseTotal
if $state == 1 and $line =~ /\A / 0 0 0
Condition0%0/3
$state == 1 and $line =~ /\A /
!ll&&!rl&&r
000
MC/DC0%0/2
$state == 1 and $line =~ /\A /
$state == 1 $line =~ /\A /
Truth table0%0/3
A and B
A= $state == 1B= $line =~ /\A /
ABresult
0X0
100
111
466 0 ▶ return true if $state == notWrapping && $line !~ /\A /;
Branch: 1 branch
BranchTrueFalseTotal
if $state == 2 and not $line =~ /\A / 0 0 0
Condition0%0/3
$state == 2 and not $line =~ /\A /
!ll&&!rl&&r
000
MC/DC0%0/2
$state == 2 and not $line =~ /\A /
$state == 2 not $line =~ /\A /
Truth table0%0/3
A and not(B)
A= $state == 2B= not $line =~ /\A /
ABresult
0X0
100
111
467 0 return false;
468 7 };
469
470 # Read a paragraph from a seekable source, collecting cross-references.
471 # Returns undef when no paragraph is found; leaves the boundary line unread.
472 0 ▶sub _readParagraph { goto $readParagraph }
Subroutine _readParagraph: not called CC=1 SCAR=6.9
473 0 ▶$readParagraph = sub { # $paragraph|undef ($self, $textFile, \$offset, $xRefs)
Subroutine __ANON__: not called CC=21 SCAR=61.4
474 0 my ( $self, $textFile, $offset, $xRefs ) = @_;
475 0 ▶ assert ( @_ == 4 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 4 0 0 0
476 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
477 0 ▶ assert ( is_FileHandle $textFile );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_FileHandle($textFile) 0 0 0
478 0 ▶ assert ( is_ScalarRef $offset and is_PositiveOrZeroInt $$offset );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_ScalarRef($offset) and &is_PositiveOrZeroInt($$offset) 0 0 0
Condition0%0/3
&is_ScalarRef($offset) and &is_PositiveOrZeroInt($$offset)
!ll&&!rl&&r
000
MC/DC0%0/2
&is_ScalarRef($offset) and &is_PositiveOrZeroInt($$offset)
&is_ScalarRef($offset) &is_PositiveOrZeroInt($$offset)
Truth table0%0/3
A and B
A= &is_ScalarRef($offset)B= &is_PositiveOrZeroInt($$offset)
ABresult
0X0
100
111
479 0 ▶ assert ( is_ArrayRef $xRefs );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_ArrayRef($xRefs) 0 0 0
480
481 0 my $text = '';
482 0 my $state = undefined;
483 0 while ( true ) {
484 0 my $position = tell( $textFile );
485 0 ▶ if ( $position < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($position < 0) 0 0 0
486 0 $self->$error( "Cannot tell help source position: $!" );
487 0 return undef;
488 }
489 0 my $line = $self->$readLine( $textFile );
490 0 ▶ unless ( defined $line ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line) 0 0 0
491 0 ▶ return undef if defined $self->{parseError};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"parseError"} 0 0 0
492 0 last;
493 }
494 0 ▶ next if $line =~ /\A;/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A;/ 0 0 0
495 0 ▶ if ( $state == undefined && $line eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state == 0 and $line eq "") 0 0 0
Condition0%0/3
$state == 0 and $line eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
$state == 0 and $line eq ""
$state == 0 $line eq ""
Truth table0%0/3
A and B
A= $state == 0B= $line eq ""
ABresult
0X0
100
111
496 0 $text .= "\n";
497 0 next;
498 }
499 0 ▶ if ( $self->$isEndParagraph( $line, $state ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->$isEndParagraph($line, $state)) 0 0 0
500 0 ▶ unless ( seek( $textFile, $position, 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek $textFile, $position, 0) 0 0 0
501 0 $self->$error( "Cannot restore help source position: $!" );
502 0 return undef;
503 }
504 0 last;
505 }
506 0 ▶ $state = $line =~ /\A / ? notWrapping : wrapping
Branch: 2 branches
BranchTrueFalseTotal
if $state == 0 0 0 0
$line =~ /\A / ? : 0 0 0
507 if $state == undefined;
508 0 ▶ return undef unless $self->$scanForCrossRefs(
Branch: 1 branch
BranchTrueFalseTotal
unless $self->$scanForCrossRefs(\$line, $$offset + length($text), $xRefs) 0 0 0
509 \$line, $$offset + length( $text ), $xRefs,
510 );
511 0 ▶ $text .= $line . ( $state == wrapping ? ' ' : "\n" );
Branch: 1 branch
BranchTrueFalseTotal
$state == 1 ? : 0 0 0
512 }
513 0 ▶ return undef if $state == undefined;
Branch: 1 branch
BranchTrueFalseTotal
if $state == 0 0 0 0
514
515 0 $$offset += length( $text );
516 0 ▶ return TParagraph->new(
Branch: 1 branch
BranchTrueFalseTotal
$state == 1 ? : 0 0 0
517 text => $text,
518 size => length( $text ),
519 wrap => $state == wrapping ? true : false,
520 next => undef,
521 );
522 7 };
523
524 7 1
525
526 __END__
« lib/TUI/StdDlg/SortedListBox.pm ↑ Summary lib/TUI/Dialogs/StaticText.pm »