lib/Pod/Tree/Node.pm

filter: Statementstmt 93.3% 364 / 390 Branchbran 89.2% 125 / 140 Conditioncond 91.6% 33 / 36 MC/DCmcdc 84.2% 16 / 19 Subroutinesub 89.6% 87 / 97 Podpod 41.4% 29 / 70 totaltotal 86.9% 654 / 752 CC 91 SCAR 13.8
CC
91
Cov
92%
_dump
12.0
consolidate
11.0
_parse_text
7.0
CRAP 4.0
« lib/Pod/Tree/Stream.pm ↑ Summary script/pods2html »
1 # Copyright (c) 1999-2004 by Steven McDougall. This module is free
2 # software; you can redistribute it and/or modify it under the same
3 # terms as Perl itself.
4  
5 package Pod::Tree::Node;
6  
7 34 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 34 ▶use Pod::Escapes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 34 our $VERSION = '1.31';
13  
14 sub root # ctor
15 194 ▶{
Subroutine root: called CC=1 SCAR=0.0
Pod documented
16 194 my ( $class, $children ) = @_;
17  
18 194 my $node = {
19 type => 'root',
20 children => $children
21 };
22  
23 194 bless $node, $class;
24 }
25  
26 sub code #ctor
27 74 ▶{
Subroutine code: called CC=1 SCAR=0.0
Pod documented
28 74 my ( $class, $paragraph ) = @_;
29  
30 74 my $node = {
31 type => 'code',
32 text => $paragraph
33 };
34  
35 74 bless $node, $class;
36 }
37  
38 sub verbatim # ctor
39 91 ▶{
Subroutine verbatim: called CC=1 SCAR=0.0
Pod documented
40 91 my ( $class, $paragraph ) = @_;
41  
42 91 my $node = {
43 type => 'verbatim',
44 raw => $paragraph,
45 text => $paragraph
46 };
47  
48 91 bless $node, $class;
49 }
50  
51 34 my %Argumentative = map { $_ => 1 } qw(=over
52 =for =begin =end);
53  
54 sub command # ctor
55 1724 ▶{
Subroutine command: called CC=2 SCAR=6.9
Pod documented
56 1724 my ( $class, $paragraph ) = @_;
57 1724 my ( $command, $arg, $text );
58  
59 1724 ($command) = split( /\s/, $paragraph );
60  
61 1724 ▶ if ( $Argumentative{$command} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Argumentative{$command}) { } 319 1405 1724
62 319 ( $command, $arg, $text ) = split( /\s+/, $paragraph, 3 );
63 }
64 else {
65 1405 ( $command, $text ) = split( /\s+/, $paragraph, 2 );
66 1405 $arg = '';
67 }
68  
69 1724 $command =~ s/^=//;
70  
71 1724 my $node = {
72 type => 'command',
73 raw => $paragraph,
74 command => $command,
75 arg => $arg,
76 text => $text
77 };
78  
79 1724 bless $node, $class;
80 }
81  
82 sub ordinary # ctor
83 1456 ▶{
Subroutine ordinary: called CC=1 SCAR=0.0
Pod documented
84 1456 my ( $class, $paragraph ) = @_;
85  
86 1456 my $node = {
87 type => 'ordinary',
88 raw => $paragraph,
89 text => $paragraph
90 };
91  
92 1456 bless $node, $class;
93 }
94  
95 sub letter # ctor
96 1699 ▶{
Subroutine letter: called CC=1 SCAR=0.0
Pod undocumented
97 1699 my ( $class, $token ) = @_;
98  
99 1699 my $node = {
100 type => 'letter',
101 letter => substr( $token, 0, 1 ),
102 width => $token =~ tr/</</
103 };
104  
105 1699 bless $node, $class;
106 }
107  
108 sub sequence # ctor
109 1699 ▶{
Subroutine sequence: called CC=1 SCAR=0.0
Pod documented
110 1699 my ( $class, $letter, $children ) = @_;
111  
112 my $node = {
113 type => 'sequence',
114 1699 'letter' => $letter->{'letter'},
115 children => $children
116 };
117  
118 1699 bless $node, $class;
119 }
120  
121 sub text # ctor
122 5644 ▶{
Subroutine text: called CC=1 SCAR=0.0
Pod documented
123 5644 my ( $class, $text ) = @_;
124  
125 5644 my $node = {
126 type => 'text',
127 text => $text
128 };
129  
130 5644 bless $node, $class;
131 }
132  
133 sub target # ctor
134 758 ▶{
Subroutine target: called CC=2 SCAR=6.9
Pod documented
135 758 my ( $class, $children ) = @_;
136  
137 758 my $node = bless {
138 type => 'target',
139 children => $children
140 }, $class;
141  
142 758 $node->unescape;
143 758 my $text = $node->get_deep_text;
144  
145 758 ▶ if ( $text =~ m(^[A-Za-z]+:(?!:)) ) # a URL
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^[A-Za-z]+:(?!:)/) { } 24 734 758
146 {
147 24 $node->{page} = $text;
148 24 $node->{section} = '';
149 24 $node->{domain} = 'HTTP';
150 }
151 else # a POD link
152 {
153 734 my ( $page, $section ) = SplitTarget($text);
154 734 $node->{page} = $page;
155 734 $node->{section} = $section;
156 734 $node->{domain} = 'POD';
157 }
158  
159 758 $node;
160 }
161  
162 734 ▶sub SplitTarget {
Subroutine SplitTarget: called CC=4 SCAR=13.9
Pod undocumented
163 734 my $text = shift;
164 734 my ( $page, $section );
165  
166 734 ▶ if ( $text =~ /^"(.*)"$/s ) # L<"sec">;
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^"(.*)"$/s) { } 67 667 734
167 {
168 67 $page = '';
169 67 $section = $1;
170 }
171 else # all other cases
172 {
173 667 ( $page, $section ) = ( split( m(/), $text, 2 ), '', '' );
174  
175 667 $page =~ s/\s*\(\d\)$//; # ls (1) -> ls
176 667 $section =~ s( ^" | "$ )()xg; # lose the quotes
177  
178 # L<section in this man page> (without quotes)
179 667 ▶ if ( $page !~ /^[\w.-]+(::[\w.-]+)*$/ and $section eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $page =~ /^[\w.-]+(::[\w.-]+)*$/ and $section eq "") 66 601 667
Condition100%3/3
not $page =~ /^[\w.-]+(::[\w.-]+)*$/ and $section eq ""
!ll&&!rl&&r
5376466
MC/DC100%2/2
not $page =~ /^[\w.-]+(::[\w.-]+)*$/ and $section eq ""
not $page =~ /^[\w.-]+(::[\w.-]+)*$/ $section eq ""
Truth table100%3/3
not(A) and B
A= not $page =~ /^[\w.-]+(::[\w.-]+)*$/B= $section eq ""
ABresult
0X0
100
111
180 66 $section = $page;
181 66 $page = '';
182 }
183 }
184  
185 734 $section =~ s( \s*\n\s* )( )xg; # close line breaks
186 734 $section =~ s( ^\s+ | \s+$ )()xg; # clip leading and trailing WS
187  
188 734 ( $page, $section );
189 }
190  
191 sub link # ctor
192 0 ▶{
Subroutine link: not called CC=1 SCAR=6.9
Pod documented
193 0 my ( $class, $node, $page, $section ) = @_;
194  
195 0 my $target = bless {
196 type => 'target',
197 domain => 'POD',
198 children => [$node],
199 page => $page,
200 section => $section
201 }, $class;
202  
203 0 my $link = bless {
204 type => 'sequence',
205 letter => 'L',
206 children => [$node],
207 target => $target
208 }, $class;
209  
210 0 $link;
211 }
212  
213 9032 ▶sub is_code { shift->{type} eq 'code' }
Subroutine is_code: called CC=1 SCAR=0.0
Pod undocumented
214 0 ▶sub is_command { shift->{type} eq 'command' }
Subroutine is_command: not called CC=1 SCAR=6.9
Pod undocumented
215 3147 ▶sub is_for { shift->{type} eq 'for' }
Subroutine is_for: called CC=1 SCAR=0.0
Pod undocumented
216 0 ▶sub is_item { shift->{type} eq 'item' }
Subroutine is_item: not called CC=1 SCAR=6.9
Pod undocumented
217 3903 ▶sub is_letter { shift->{type} eq 'letter' }
Subroutine is_letter: called CC=1 SCAR=0.0
Pod undocumented
218 0 ▶sub is_list { shift->{type} eq 'list' }
Subroutine is_list: not called CC=1 SCAR=6.9
Pod undocumented
219 0 ▶sub is_ordinary { shift->{type} eq 'ordinary' }
Subroutine is_ordinary: not called CC=1 SCAR=6.9
Pod undocumented
220 460 ▶sub is_root { shift->{type} eq 'root' }
Subroutine is_root: called CC=1 SCAR=0.0
Pod undocumented
221 22877 ▶sub is_sequence { shift->{type} eq 'sequence' }
Subroutine is_sequence: called CC=1 SCAR=0.0
Pod undocumented
222 8379 ▶sub is_text { shift->{type} eq 'text' }
Subroutine is_text: called CC=1 SCAR=0.0
Pod undocumented
223 8556 ▶sub is_verbatim { shift->{type} eq 'verbatim' }
Subroutine is_verbatim: called CC=1 SCAR=0.0
Pod undocumented
224  
225 10640 ▶sub is_link {
Subroutine is_link: called CC=2 SCAR=6.9
Pod undocumented
226 10640 my $node = shift;
227 10640 ▶ $node->is_sequence and $node->{'letter'} eq 'L';
Branch: 1 branch
BranchTrueFalseTotal
$node->is_sequence and $node->{"letter"} eq "L" 1783 8857 10640
228 }
229  
230 447 ▶sub is_pod {
Subroutine is_pod: called CC=3 SCAR=11.0
Pod undocumented
231 447 my $node = shift;
232 447 ▶ not $node->is_code and not $node->is_c_cut and not $node->is_c_pod;
Condition100%6/6
$node->is_code || $node->is_c_cut || $node->is_c_pod
l!l&&r!l&&!r
4118388
$node->is_code or $node->is_c_cut
l!l&&r!l&&!r
329406
MC/DC100%3/3
$node->is_code || $node->is_c_cut || $node->is_c_pod
$node->is_code $node->is_c_cut $node->is_c_pod
Truth table100%4/4
A or B || C
A= $node->is_codeB= $node->is_c_cutC= $node->is_c_pod
ABCresult
1XX1
01X1
0011
0000
233 }
234  
235 438 ▶sub is_c_head1 {
Subroutine is_c_head1: called CC=2 SCAR=6.9
Pod undocumented
236 438 my $node = shift;
237 438 ▶ $node->{type} eq 'command' and $node->{'command'} eq 'head1';
Branch: 1 branch
BranchTrueFalseTotal
$node->{"type"} eq "command" and $node->{"command"} eq "head1" 166 272 438
238 }
239  
240 447 ▶sub is_c_head2 {
Subroutine is_c_head2: called CC=2 SCAR=6.9
Pod undocumented
241 447 my $node = shift;
242 447 ▶ $node->{type} eq 'command' and $node->{'command'} eq 'head2';
Branch: 1 branch
BranchTrueFalseTotal
$node->{"type"} eq "command" and $node->{"command"} eq "head2" 175 272 447
243 }
244  
245 0 ▶sub is_c_head3 {
Subroutine is_c_head3: not called CC=2 SCAR=17.9
Pod undocumented
246 0 my $node = shift;
247 0 ▶ $node->{type} eq 'command' and $node->{'command'} eq 'head3';
Branch: 1 branch
BranchTrueFalseTotal
$node->{"type"} eq "command" and $node->{"command"} eq "head3" 0 0 0
248 }
249  
250 0 ▶sub is_c_head4 {
Subroutine is_c_head4: not called CC=2 SCAR=17.9
Pod undocumented
251 0 my $node = shift;
252 0 ▶ $node->{type} eq 'command' and $node->{'command'} eq 'head4';
Branch: 1 branch
BranchTrueFalseTotal
$node->{"type"} eq "command" and $node->{"command"} eq "head4" 0 0 0
253 }
254  
255 415 ▶sub is_c_cut {
Subroutine is_c_cut: called CC=2 SCAR=6.9
Pod undocumented
256 415 my $node = shift;
257 415 ▶ $node->{type} eq 'command' and $node->{'command'} eq 'cut';
Branch: 1 branch
BranchTrueFalseTotal
$node->{"type"} eq "command" and $node->{"command"} eq "cut" 221 194 415
258 }
259  
260 406 ▶sub is_c_pod {
Subroutine is_c_pod: called CC=2 SCAR=6.9
Pod undocumented
261 406 my $node = shift;
262 406 ▶ $node->{type} eq 'command' and $node->{'command'} eq 'pod';
Branch: 1 branch
BranchTrueFalseTotal
$node->{"type"} eq "command" and $node->{"command"} eq "pod" 212 194 406
263 }
264  
265 3243 ▶sub is_c_over {
Subroutine is_c_over: called CC=2 SCAR=6.9
Pod undocumented
266 3243 my $node = shift;
267 3243 ▶ $node->{type} eq 'command' and $node->{'command'} eq 'over';
Branch: 1 branch
BranchTrueFalseTotal
$node->{"type"} eq "command" and $node->{"command"} eq "over" 1660 1583 3243
268 }
269  
270 3467 ▶sub is_c_back {
Subroutine is_c_back: called CC=2 SCAR=6.9
Pod undocumented
271 3467 my $node = shift;
272 3467 ▶ $node->{type} eq 'command' and $node->{'command'} eq 'back';
Branch: 1 branch
BranchTrueFalseTotal
$node->{"type"} eq "command" and $node->{"command"} eq "back" 1100 2367 3467
273 }
274  
275 3817 ▶sub is_c_item {
Subroutine is_c_item: called CC=2 SCAR=6.9
Pod undocumented
276 3817 my $node = shift;
277 3817 ▶ $node->{type} eq 'command' and $node->{'command'} eq 'item';
Branch: 1 branch
BranchTrueFalseTotal
$node->{"type"} eq "command" and $node->{"command"} eq "item" 2038 1779 3817
278 }
279  
280 3301 ▶sub is_c_for {
Subroutine is_c_for: called CC=2 SCAR=6.9
Pod undocumented
281 3301 my $node = shift;
282 3301 ▶ $node->{type} eq 'command' and $node->{'command'} eq 'for';
Branch: 1 branch
BranchTrueFalseTotal
$node->{"type"} eq "command" and $node->{"command"} eq "for" 1702 1599 3301
283 }
284  
285 3301 ▶sub is_c_begin {
Subroutine is_c_begin: called CC=2 SCAR=6.9
Pod undocumented
286 3301 my $node = shift;
287 3301 ▶ $node->{type} eq 'command' and $node->{'command'} eq 'begin';
Branch: 1 branch
BranchTrueFalseTotal
$node->{"type"} eq "command" and $node->{"command"} eq "begin" 1671 1630 3301
288 }
289  
290 44 ▶sub is_c_end {
Subroutine is_c_end: called CC=2 SCAR=6.9
Pod undocumented
291 44 my $node = shift;
292 44 ▶ $node->{type} eq 'command' and $node->{'command'} eq 'end';
Branch: 1 branch
BranchTrueFalseTotal
$node->{"type"} eq "command" and $node->{"command"} eq "end" 22 22 44
293 }
294  
295 104 ▶sub get_arg { shift->{arg} }
Subroutine get_arg: called CC=1 SCAR=0.0
Pod documented
296 19 ▶sub get_back { shift->{back} }
Subroutine get_back: called CC=1 SCAR=0.0
Pod undocumented
297 5118 ▶sub get_children { shift->{children} }
Subroutine get_children: called CC=1 SCAR=0.0
Pod documented
298 444 ▶sub get_command { shift->{'command'} }
Subroutine get_command: called CC=1 SCAR=0.0
Pod documented
299 503 ▶sub get_domain { shift->{domain} }
Subroutine get_domain: called CC=1 SCAR=0.0
Pod documented
300 546 ▶sub get_item_type { shift->{item_type} }
Subroutine get_item_type: called CC=1 SCAR=0.0
Pod documented
301 1641 ▶sub get_letter { shift->{'letter'} }
Subroutine get_letter: called CC=1 SCAR=0.0
Pod documented
302 247 ▶sub get_list_type { shift->{list_type} }
Subroutine get_list_type: called CC=1 SCAR=0.0
Pod documented
303 503 ▶sub get_page { shift->{page} }
Subroutine get_page: called CC=1 SCAR=0.0
Pod documented
304 60 ▶sub get_raw { shift->{raw} }
Subroutine get_raw: called CC=1 SCAR=0.0
Pod documented
305 27 ▶sub get_raw_kids { shift->{raw_kids} }
Subroutine get_raw_kids: called CC=1 SCAR=0.0
Pod documented
306 481 ▶sub get_section { shift->{section} }
Subroutine get_section: called CC=1 SCAR=0.0
Pod documented
307 1686 ▶sub get_siblings { shift->{siblings} }
Subroutine get_siblings: called CC=1 SCAR=0.0
Pod documented
308 531 ▶sub get_target { shift->{'target'} }
Subroutine get_target: called CC=1 SCAR=0.0
Pod documented
309 4070 ▶sub get_text { shift->{'text'} }
Subroutine get_text: called CC=1 SCAR=0.0
Pod documented
310 6066 ▶sub get_type { shift->{'type'} }
Subroutine get_type: called CC=1 SCAR=0.0
Pod documented
311 0 ▶sub get_url { shift->{'url'} }
Subroutine get_url: not called CC=1 SCAR=6.9
Pod undocumented
312  
313 3 ▶sub get_brackets {
Subroutine get_brackets: called CC=1 SCAR=0.0
Pod documented
314 3 my $node = shift;
315 3 my $brackets = $node->{brackets};
316 3 $brackets;
317 }
318  
319 3534 ▶sub get_deep_text {
Subroutine get_deep_text: called CC=4 SCAR=13.9
Pod documented
320 3534 my $node = shift;
321  
322 3534 for ( $node->get_type ) {
323 3534 ▶ /text/ and return $node->{'text'};
Branch: 1 branch
BranchTrueFalseTotal
/text/ and return $node->{"text"} 1799 1735 3534
324 1735 ▶ /verbatim/ and return $node->{'text'};
Branch: 1 branch
BranchTrueFalseTotal
/verbatim/ and return $node->{"text"} 0 1735 1735
325 }
326  
327 1735 join '', map { $_->get_deep_text } @{ $node->{children} };
328 }
329  
330 324 ▶sub force_text {
Subroutine force_text: called CC=1 SCAR=0.0
Pod undocumented
331 324 my ( $node, $text ) = @_;
332 324 $node->{type} = 'text';
333 324 $node->{'text'} = $text;
334 324 undef $node->{children};
335 }
336  
337 31 ▶sub force_for {
Subroutine force_for: called CC=1 SCAR=0.0
Pod undocumented
338 31 my $node = shift;
339 31 $node->{type} = 'for';
340  
341 31 my ($bracket) = $node->{raw} =~ /^(=\w+\s+\w+\s+)/;
342  
343 31 $node->{brackets} = [$bracket];
344 }
345  
346 11 ▶sub parse_begin {
Subroutine parse_begin: called CC=5 SCAR=16.5
Pod undocumented
347 11 my ( $node, $nodes ) = @_;
348  
349 11 my $foreign;
350 my @raw;
351 11 ▶ while (@$nodes) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$nodes) 44 0 44
352 44 $foreign = shift @$nodes;
353 44 ▶ $foreign->is_c_end and last;
Branch: 1 branch
BranchTrueFalseTotal
$foreign->is_c_end and last 11 33 44
354 33 push @raw, $foreign->{'raw'};
355 }
356 11 $node->{'text'} = join '', @raw;
357  
358 11 my $interpreter = $foreign->{arg};
359 $interpreter
360 and $interpreter ne $node->{arg}
361 11 ▶ and $node->_warn("Mismatched =begin/=end tags around\n$node->{'text'}");
Branch: 1 branch
BranchTrueFalseTotal
$interpreter and $interpreter ne $node->{"arg"} and $node->_warn(qq[Mismatched =begin/=end tags around\n$node->{"text"}]) 0 11 11
Condition33%1/3
$interpreter and $interpreter ne $node->{"arg"}
!ll&&!rl&&r
0110
MC/DC0%0/2
$interpreter and $interpreter ne $node->{"arg"}
$interpreter $interpreter ne $node->{"arg"}
Truth table33%1/3
A and B
A= $interpreterB= $interpreter ne $node->{"arg"}
ABresult
0X0
100
111
362  
363 11 $node->{type} = 'for';
364 11 $node->{brackets} = [ $node->{raw}, $foreign->{raw} ];
365 }
366  
367 194 ▶sub set_children {
Subroutine set_children: called CC=1 SCAR=0.0
Pod undocumented
368 194 my ( $node, $children ) = @_;
369 194 $node->{children} = $children;
370 }
371  
372 3105 ▶sub make_sequences {
Subroutine make_sequences: called CC=1 SCAR=0.0
Pod undocumented
373 3105 my $node = shift;
374 3105 my $text = $node->{'text'};
375 3105 my @tokens = split /( [A-Z]<<+\s+ | [A-Z]< | \s+>>+ | > )/x, $text;
376 3105 my $sequences = _parse_text( \@tokens );
377 3105 $node->{children} = $sequences;
378 }
379  
380 3105 ▶sub _parse_text {
Subroutine _parse_text: called CC=7 SCAR=19.5
381 3105 my $tokens = shift;
382 3105 my ( @stack, @width );
383  
384 3105 ▶ while (@$tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$tokens) 9428 3105 12533
385 9428 my $token = shift @$tokens;
386 9428 ▶ length $token or next;
Branch: 1 branch
BranchTrueFalseTotal
length $token or next 8780 648 9428
387  
388 8780 ▶ $token =~ /^[A-Z]</ and do {
Branch: 1 branch
BranchTrueFalseTotal
$token =~ /^[A-Z]</ and do { my $width = $token =~ tr/<//; push @width, $width; my $node = "Pod::Tree::Node"->letter($token); push @stack, $node; next } 1699 7081 8780
389 1699 my $width = $token =~ tr/</</;
390 1699 push @width, $width;
391 1699 my $node = Pod::Tree::Node->letter($token);
392 1699 push @stack, $node;
393 1699 next;
394 };
395  
396 7081 ▶ @width and $token =~ />{$width[-1],}$/ and do {
Branch: 1 branch
BranchTrueFalseTotal
@width and $token =~ />{$width[-1],}$/ and do { my $width = pop @width; () = _pop_sequence(\@stack, $width); my $node = "Pod::Tree::Node"->sequence($letter, $interior); push @stack, $node; $token =~ s/^\s*>{$width}//; my @tokens = split(//, $token, 0); unshift @$tokens, @tokens; next } 1699 5382 7081
Condition100%3/3
@width and $token =~ />{$width[-1],}$/
!ll&&!rl&&r
351818641699
MC/DC100%2/2
@width and $token =~ />{$width[-1],}$/
@width $token =~ />{$width[-1],}$/
Truth table100%3/3
A and B
A= @widthB= $token =~ />{$width[-1],}$/
ABresult
0X0
100
111
397 1699 my $width = pop @width;
398 1699 my ( $letter, $interior ) = _pop_sequence( \@stack, $width );
399 1699 my $node = Pod::Tree::Node->sequence( $letter, $interior );
400 1699 push @stack, $node;
401 1699 $token =~ s/^\s*>{$width}//;
402 1699 my @tokens = split //, $token;
403 1699 unshift @$tokens, @tokens;
404 1699 next;
405 };
406  
407 5382 my $node = Pod::Tree::Node->text($token);
408 5382 push @stack, $node;
409 }
410  
411 3105 ▶ if (@width) {
Branch: 1 branch
BranchTrueFalseTotal
if (@width) 0 3105 3105
412 0 my @text = map { $_->get_deep_text } @stack;
413 0 Pod::Tree::Node->_warn("Missing '>' delimiter in\n@text");
414 }
415  
416 3105 \@stack;
417 }
418  
419 1699 ▶sub _pop_sequence {
Subroutine _pop_sequence: called CC=4 SCAR=16.0
420 1699 my ( $stack, $width ) = @_;
421 1699 my ( $node, @interior );
422  
423 1699 ▶ while (@$stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$stack) 3903 0 3903
424 3903 $node = pop @$stack;
425 $node->is_letter
426 3903 ▶ and $node->{width} == $width
Branch: 1 branch
BranchTrueFalseTotal
$node->is_letter and $node->{"width"} == $width and return $node, \@interior 1699 2204 3903
Condition66%2/3
$node->is_letter and $node->{"width"} == $width
!ll&&!rl&&r
220401699
MC/DC50%1/2
$node->is_letter and $node->{"width"} == $width
$node->is_letter $node->{"width"} == $width
Truth table66%2/3
A and B
A= $node->is_letterB= $node->{"width"} == $width
ABresult
0X0
100
111
427 and return ( $node, \@interior );
428 2204 unshift @interior, $node;
429 }
430  
431 0 my @text = map { $_->get_deep_text } @interior;
432 0 $node->_warn("Mismatched sequence delimiters around\n@text");
433  
434 0 $node = Pod::Tree::Node->letter(' ');
435 0 $node, \@interior;
436 }
437  
438 10546 ▶sub parse_links {
Subroutine parse_links: called CC=3 SCAR=11.0
Pod undocumented
439 10546 my $node = shift;
440  
441 10546 ▶ $node->is_link and $node->_parse_link;
Branch: 1 branch
BranchTrueFalseTotal
$node->is_link and $node->_parse_link 758 9788 10546
442  
443 10546 my $children = $node->{children};
444 10546 for my $child (@$children) {
445 10352 $child->parse_links;
446 }
447 }
448  
449 758 ▶sub _parse_link {
Subroutine _parse_link: called CC=1 SCAR=0.0
450 758 my $node = shift;
451  
452 758 $node->{raw_kids} = $node->clone->{children};
453  
454 758 my $children = $node->{children};
455 758 my ( $text_kids, $target_kids ) = SplitBar($children);
456  
457 758 $node->{children} = $text_kids;
458 758 $node->{'target'} = Pod::Tree::Node->target($target_kids);
459 }
460  
461 758 ▶sub SplitBar {
Subroutine SplitBar: called CC=5 SCAR=16.1
Pod undocumented
462 758 my $children = shift;
463 758 my ( @text, @link );
464  
465 758 ▶ while (@$children) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$children) 829 627 1456
466 829 my $child = shift @$children;
467  
468 829 ▶ $child->is_text or do {
Branch: 1 branch
BranchTrueFalseTotal
$child->is_text or do { push @text, $child; next } 763 66 829
469 66 push @text, $child;
470 66 next;
471 };
472  
473 763 my ( $text, $link ) = split m(\|), $child->{'text'}, 2;
474 763 ▶ $link and do {
Branch: 1 branch
BranchTrueFalseTotal
$link and do { push @text, "Pod::Tree::Node"->text($text) if $text; push @link, "Pod::Tree::Node"->text($link), @$children; return \@text, \@link } 131 632 763
475 131 ▶ push @text, Pod::Tree::Node->text($text) if $text;
Branch: 1 branch
BranchTrueFalseTotal
if $text 131 0 131
476 131 push @link, Pod::Tree::Node->text($link), @$children;
477 131 return ( \@text, \@link );
478 };
479  
480 632 push @text, $child;
481 }
482  
483 627 ( \@text, \@text );
484 }
485  
486 12237 ▶sub unescape {
Subroutine unescape: called CC=3 SCAR=11.0
Pod undocumented
487 12237 my $node = shift;
488  
489 12237 my $children = $node->{children};
490 12237 for my $child (@$children) {
491 11285 $child->unescape;
492 }
493  
494 12237 ▶ $node->is_sequence and $node->_unescape_sequence;
Branch: 1 branch
BranchTrueFalseTotal
$node->is_sequence and $node->_unescape_sequence 1761 10476 12237
495 }
496  
497 1761 ▶sub _unescape_sequence {
Subroutine _unescape_sequence: called CC=6 SCAR=18.0
498 1761 my $node = shift;
499  
500 1761 for ( $node->{'letter'} ) {
501 1761 ▶ /Z/ and $node->force_text(''), last;
Branch: 1 branch
BranchTrueFalseTotal
/Z/ and $node->force_text(""), last 21 1740 1761
502 1740 ▶ /E/ and do {
Branch: 1 branch
BranchTrueFalseTotal
/E/ and do { my $child = $node->{"children"}[0]; $child or last; my $text = $child->_unescape_text; $text and $node->force_text($text); last } 303 1437 1740
503 303 my $child = $node->{children}[0];
504 303 ▶ $child or last;
Branch: 1 branch
BranchTrueFalseTotal
$child or last 303 0 303
505 303 my $text = $child->_unescape_text;
506 303 ▶ $text and $node->force_text($text);
Branch: 1 branch
BranchTrueFalseTotal
$text and $node->force_text($text) 303 0 303
507 303 last;
508 };
509 }
510 }
511  
512 303 ▶sub _unescape_text {
Subroutine _unescape_text: called CC=2 SCAR=7.1
513 303 my $node = shift;
514 303 my $text = $node->{'text'};
515  
516 303 ▶ defined $text ? Pod::Escapes::e2char($text) : "E<UNDEF?!>";
Branch: 1 branch
BranchTrueFalseTotal
defined $text ? : 303 0 303
517 }
518  
519 9499 ▶sub consolidate {
Subroutine consolidate: called CC=11 SCAR=24.0
Pod undocumented
520 9499 my $node = shift;
521 9499 my $old = $node->{children};
522 9499 ▶ $old and @$old or return;
Branch: 1 branch
BranchTrueFalseTotal
$old and @$old or return 4106 5393 9499
Condition100%3/3
$old and @$old
!ll&&!rl&&r
48255684106
MC/DC100%2/2
$old and @$old
$old @$old
Truth table100%3/3
A and B
A= $oldB= @$old
ABresult
0X0
100
111
523  
524 4106 my $new = [];
525  
526 4106 push @$new, shift @$old;
527  
528 4106 ▶ while (@$old) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$old) 5953 4106 10059
529 5953 ▶ if ( $new->[-1]->is_text and $old->[0]->is_text
Branch: 1 branch
BranchTrueFalseTotal
if ($new->[-1]->is_text and $old->[0]->is_text or $new->[-1]->is_verbatim and $old->[0]->is_verbatim or $new->[-1]->is_code and $old->[0]->is_code) { } 754 5199 5953
Condition100%15/15
$new->[-1]->is_text and $old->[0]->is_text or $new->[-1]->is_verbatim and $old->[0]->is_verbatim or $new->[-1]->is_code and $old->[0]->is_code
l!l&&r!l&&!r
728265199
$new->[-1]->is_text and $old->[0]->is_text or $new->[-1]->is_verbatim and $old->[0]->is_verbatim
l!l&&r!l&&!r
696325225
$new->[-1]->is_text and $old->[0]->is_text
!ll&&!rl&&r
4356901696
$new->[-1]->is_verbatim and $old->[0]->is_verbatim
!ll&&!rl&&r
51854032
$new->[-1]->is_code and $old->[0]->is_code
!ll&&!rl&&r
51663326
MC/DC100%6/6
$new->[-1]->is_text and $old->[0]->is_text or $new->[-1]->is_verbatim and $old->[0]->is_verbatim or $new->[-1]->is_code and $old->[0]->is_code
$new->[-1]->is_text $old->[0]->is_text $new->[-1]->is_verbatim $old->[0]->is_verbatim $new->[-1]->is_code $old->[0]->is_code
Truth table46%7/15
A and B or C and D or E and F
A= $new->[-1]->is_textB= $old->[0]->is_textC= $new->[-1]->is_verbatimD= $old->[0]->is_verbatimE= $new->[-1]->is_codeF= $old->[0]->is_code
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
530 or $new->[-1]->is_verbatim and $old->[0]->is_verbatim
531 or $new->[-1]->is_code and $old->[0]->is_code )
532 {
533 754 $new->[-1]{'text'} .= $old->[0]{'text'};
534 754 shift @$old;
535 }
536 else {
537 5199 push @$new, shift @$old;
538 }
539 }
540  
541 4106 $node->{children} = $new;
542  
543 4106 for my $child (@$new) {
544 9305 $child->consolidate;
545 }
546 }
547  
548 194 ▶sub make_lists {
Subroutine make_lists: called CC=1 SCAR=0.0
Pod undocumented
549 194 my $root = shift;
550 194 my $nodes = $root->{children};
551  
552 194 $root->_make_lists($nodes);
553 }
554  
555 460 ▶sub _make_lists {
Subroutine _make_lists: called CC=6 SCAR=17.9
556 460 my ( $node, $old ) = @_;
557 460 my $new = [];
558 460 my $back;
559  
560 460 ▶ while (@$old) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$old) 2585 208 2793
561 2585 my $child = shift @$old;
562 2585 ▶ $child->is_c_over and $child->_make_lists($old);
Branch: 1 branch
BranchTrueFalseTotal
$child->is_c_over and $child->_make_lists($old) 196 2389 2585
563 2585 ▶ $child->is_c_item and $child->_make_item($old);
Branch: 1 branch
BranchTrueFalseTotal
$child->is_c_item and $child->_make_item($old) 588 1997 2585
564 2585 ▶ $child->is_c_back and $back = $child, last;
Branch: 1 branch
BranchTrueFalseTotal
$child->is_c_back and $back = $child, last 252 2333 2585
565 2333 push @$new, $child;
566 }
567  
568 460 $node->{children} = $new;
569  
570 460 ▶ $node->is_root and return;
Branch: 1 branch
BranchTrueFalseTotal
$node->is_root and return 194 266 460
571  
572 266 $node->{type} = 'list';
573 266 $node->{back} = $back;
574 266 $node->_set_list_type;
575 }
576  
577 266 ▶sub _set_list_type {
Subroutine _set_list_type: called CC=3 SCAR=11.0
578 266 my $list = shift;
579 266 my $children = $list->{children};
580  
581 266 $list->{list_type} = ''; # -w
582  
583 266 for my $child (@$children) {
584 252 ▶ $child->{type} eq 'item' or next;
Branch: 1 branch
BranchTrueFalseTotal
$child->{"type"} eq "item" or next 238 14 252
585 238 $list->{list_type} = $child->{item_type};
586 238 last;
587 }
588 }
589  
590 588 ▶sub _make_item {
Subroutine _make_item: called CC=5 SCAR=16.1
591 588 my ( $item, $old ) = @_;
592 588 my $siblings = [];
593  
594 588 ▶ while (@$old) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$old) 1232 14 1246
595 1232 my $sibling = $old->[0];
596 1232 ▶ $sibling->is_c_item and last;
Branch: 1 branch
BranchTrueFalseTotal
$sibling->is_c_item and last 350 882 1232
597 882 ▶ $sibling->is_c_back and last;
Branch: 1 branch
BranchTrueFalseTotal
$sibling->is_c_back and last 224 658 882
598  
599 658 shift @$old;
600 658 ▶ $sibling->is_c_over and do {
Branch: 1 branch
BranchTrueFalseTotal
$sibling->is_c_over and do { $sibling->_make_lists($old) } 70 588 658
601 70 $sibling->_make_lists($old);
602 };
603 658 push @$siblings, $sibling;
604 }
605  
606 588 $item->{type} = 'item';
607 588 $item->{siblings} = $siblings;
608 588 $item->_set_item_type;
609 }
610  
611 588 ▶sub _set_item_type {
Subroutine _set_item_type: called CC=4 SCAR=13.9
612 588 my $item = shift;
613 588 my $text = $item->{'text'};
614  
615 588 ▶ $text =~ m(^\s* \* \s*$ )x and $item->{item_type} = 'bullet';
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /^\s* \* \s*$ /x and $item->{"item_type"} = "bullet" 280 308 588
616 588 ▶ $text =~ m(^\s* \d+ \s*$ )x and $item->{item_type} = 'number';
Branch: 1 branch
BranchTrueFalseTotal
$text =~ /^\s* \d+ \s*$ /x and $item->{"item_type"} = "number" 112 476 588
617 588 ▶ $item->{item_type} or $item->{item_type} = 'text';
Branch: 1 branch
BranchTrueFalseTotal
$item->{"item_type"} or $item->{"item_type"} = "text" 392 196 588
618 }
619  
620 1703 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
621 1703 my $node = shift;
622 1703 my $clone = {%$node};
623  
624 1703 my $children = $node->{children};
625 1703 $clone->{children} = [ map { $_->clone } @$children ];
626  
627 1703 bless $clone, ref $node;
628 }
629  
630 34 my $Indent;
631 my $String;
632  
633 15 ▶sub dump {
Subroutine dump: called CC=1 SCAR=0.0
Pod documented
634 15 my $node = shift;
635  
636 15 $Indent = 0;
637 15 $String = '';
638 15 $node->_dump;
639 15 $String;
640 }
641  
642 1266 ▶sub _dump {
Subroutine _dump: called CC=12 SCAR=24.8
643 1266 my $node = shift;
644 1266 my $type = $node->get_type;
645  
646 1266 $String .= ' ' x $Indent . uc $type . " ";
647  
648 1266 for ($type) {
649 1266 ▶ /command/ and $String .= $node->_dump_command;
Branch: 1 branch
BranchTrueFalseTotal
/command/ and $String .= $node->_dump_command 65 1201 1266
650 1266 ▶ /code/ and $String .= $node->_dump_code;
Branch: 1 branch
BranchTrueFalseTotal
/code/ and $String .= $node->_dump_code 11 1255 1266
651 1266 ▶ /for/ and $String .= $node->_dump_for;
Branch: 1 branch
BranchTrueFalseTotal
/for/ and $String .= $node->_dump_for 3 1263 1266
652 1266 ▶ /item/ and $String .= $node->_dump_item;
Branch: 1 branch
BranchTrueFalseTotal
/item/ and $String .= $node->_dump_item 168 1098 1266
653 1266 ▶ /list/ and $String .= $node->_dump_list;
Branch: 1 branch
BranchTrueFalseTotal
/list/ and $String .= $node->_dump_list 76 1190 1266
654 1266 ▶ /ordinary/ and $String .= "\n";
Branch: 1 branch
BranchTrueFalseTotal
/ordinary/ and $String .= "\n" 240 1026 1266
655 1266 ▶ /root/ and $String .= "\n";
Branch: 1 branch
BranchTrueFalseTotal
/root/ and $String .= "\n" 15 1251 1266
656 1266 ▶ /sequence/ and $String .= $node->_dump_sequence;
Branch: 1 branch
BranchTrueFalseTotal
/sequence/ and $String .= $node->_dump_sequence 94 1172 1266
657 1266 ▶ /text/ and $String .= $node->_dump_text;
Branch: 1 branch
BranchTrueFalseTotal
/text/ and $String .= $node->_dump_text 588 678 1266
658 1266 ▶ /verbatim/ and $String .= $node->_dump_verbatim;
Branch: 1 branch
BranchTrueFalseTotal
/verbatim/ and $String .= $node->_dump_verbatim 6 1260 1266
659 }
660  
661 1266 $node->_dump_children;
662 1266 $node->_dump_siblings;
663 }
664  
665 65 ▶sub _dump_command {
Subroutine _dump_command: called CC=1 SCAR=0.0
666 65 my $node = shift;
667 65 my $command = $node->get_command;
668 65 my $arg = $node->get_arg;
669  
670 65 "$command $arg\n";
671 }
672  
673 11 ▶sub _dump_code {
Subroutine _dump_code: called CC=1 SCAR=0.0
674 11 my $node = shift;
675  
676 11 my $text = _indent( $node->get_text, 3 );
677 11 my $block = "\n{\n$text}\n";
678  
679 11 _indent( $block, $Indent );
680 }
681  
682 3 ▶sub _dump_for {
Subroutine _dump_for: called CC=1 SCAR=0.0
683 3 my $node = shift;
684 3 my $arg = $node->get_arg;
685 3 my $text = _indent( $node->get_text, $Indent + 3 );
686  
687 3 "$arg\n$text\n";
688 }
689  
690 168 ▶sub _dump_item {
Subroutine _dump_item: called CC=1 SCAR=0.0
691 168 my $node = shift;
692 168 uc $node->get_item_type . "\n";
693 }
694  
695 76 ▶sub _dump_list {
Subroutine _dump_list: called CC=1 SCAR=0.0
696 76 my $node = shift;
697 76 uc $node->get_list_type . "\n";
698 }
699  
700 94 ▶sub _dump_sequence {
Subroutine _dump_sequence: called CC=2 SCAR=6.9
701 94 my $node = shift;
702 94 my $letter = $node->get_letter;
703 94 ▶ my $link = $node->is_link ? $node->_dump_target : '';
Branch: 1 branch
BranchTrueFalseTotal
$node->is_link ? : 28 66 94
704  
705 94 "$letter$link\n";
706 }
707  
708 588 ▶sub _dump_text {
Subroutine _dump_text: called CC=1 SCAR=0.0
709 588 my $node = shift;
710 588 my $text = $node->get_text;
711  
712 588 $text =~ s/([\x80-\xff])/sprintf("\\x%02x", ord($1))/eg;
713  
714 588 my $indent = ' ' x ( $Indent + 5 );
715 588 $text =~ s( (?<=\n) (?=.) )($indent)xg;
716 588 "$text\n";
717 }
718  
719 6 ▶sub _dump_verbatim {
Subroutine _dump_verbatim: called CC=1 SCAR=0.0
720 6 my $node = shift;
721 6 "\n" . $node->get_text . "\n";
722 }
723  
724 28 ▶sub _dump_target {
Subroutine _dump_target: called CC=1 SCAR=0.0
725 28 my $node = shift;
726 28 my $target = $node->get_target;
727 28 my $page = $target->{page};
728 28 my $section = $target->{section};
729 28 " $page / $section";
730 }
731  
732 1266 ▶sub _dump_children {
Subroutine _dump_children: called CC=2 SCAR=6.9
733 1266 my $node = shift;
734 1266 my $children = $node->get_children;
735 1266 ▶ $children and DumpList( $children, '{', '}' );
Branch: 1 branch
BranchTrueFalseTotal
$children and DumpList($children, "{", "}") 658 608 1266
736 }
737  
738 1266 ▶sub _dump_siblings {
Subroutine _dump_siblings: called CC=2 SCAR=6.9
739 1266 my $node = shift;
740 1266 my $siblings = $node->get_siblings;
741 1266 ▶ $siblings and DumpList( $siblings, '[', ']' );
Branch: 1 branch
BranchTrueFalseTotal
$siblings and DumpList($siblings, "[", "]") 168 1098 1266
742 }
743  
744 826 ▶sub DumpList {
Subroutine DumpList: called CC=2 SCAR=6.9
Pod undocumented
745 826 my ( $nodes, $open, $close ) = @_;
746  
747 826 $String .= ' ' x $Indent . "$open\n";
748 826 $Indent += 3;
749  
750 826 for my $node (@$nodes) {
751 1251 $node->_dump;
752 }
753  
754 826 $Indent -= 3;
755 826 $String .= ' ' x $Indent . "$close\n";
756 }
757  
758 25 ▶sub _indent {
Subroutine _indent: called CC=1 SCAR=0.0
759 25 my ( $text, $spaces ) = @_;
760 25 my $indent = ' ' x $spaces;
761 25 $text =~ s( (?<=\n) (?=.) )($indent)xg;
762 25 $indent . $text;
763 }
764  
765 0 ▶sub _warn {
Subroutine _warn: not called CC=2 SCAR=17.9
766 0 my ( $node, $message ) = @_;
767  
768 0 my $filename = $node->get_filename;
769 0 ▶ my $tag = $filename ? "in $filename" : $filename;
Branch: 1 branch
BranchTrueFalseTotal
$filename ? : 0 0 0
770 0 warn "$message $tag\n";
771 }
772  
773 370 ▶sub set_filename {
Subroutine set_filename: called CC=1 SCAR=0.0
Pod documented
774 370 my ( $package, $filename ) = @_;
775  
776 370 $Pod::Tree::Node::filename = $filename;
777 }
778  
779 0 ▶sub get_filename {
Subroutine get_filename: not called CC=1 SCAR=6.9
Pod undocumented
780 0 $Pod::Tree::Node::filename;
781 }
782  
783 34 1
784  
785 __END__
« lib/Pod/Tree/Stream.pm ↑ Summary script/pods2html »