Debian Codegraph @

etc/pod_inlinks.pl

raw
1 #!/usr/bin/perl
2 # Copyright 2022 Jeffrey Kegler
3 # This file is part of Marpa::R2. Marpa::R2 is free software: you can
4 # redistribute it and/or modify it under the terms of the GNU Lesser
5 # General Public License as published by the Free Software Foundation,
6 # either version 3 of the License, or (at your option) any later version.
7 #
8 # Marpa::R2 is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser
14 # General Public License along with Marpa::R2. If not, see
15 # http://www.gnu.org/licenses/.
16
17 use 5.010001;
18
19 use Pod::Simple::SimpleTree;
20 use Data::Dumper;
21
22 my $filename = shift;
23 my $tree = Pod::Simple::SimpleTree->new->parse_file($filename)->root;
24
25 my %headers = ();
26
27 sub find_header {
28 my ($subtree) = @_;
29 if (ref $subtree eq 'ARRAY') {
30 if (substr($subtree->[0], 0, 4) eq 'head') {
31 $headers{$subtree->[2]} = 1;
32 # say $subtree->[2];
33 }
34 if ($subtree->[0] eq 'L') {
35 my $hash = $subtree->[1];
36 return if not $hash->{type} eq 'pod';
37 return if exists $hash->{to};
38 return if not exists $hash->{section};
39 push @section_ref, $hash->{section};
40 }
41 find_header($_) for @{$subtree};
42 }
43 return;
44 }
45
46 # say Dumper($tree);
47 find_header($tree);
48 for my $section_ref (@section_ref) {
49 if (not exists $headers{$section_ref})
50 {
51 say STDERR "Unresolved internal section reference: $section_ref"
52 }
53 }