Debian Codegraph @

etc/pod_links.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 File::Spec;
20 use File::Find::Rule;
21 use Pod::Simple::SimpleTree;
22 use Data::Dumper;
23 use autodie;
24
25 chdir('pod');
26 my @pod_files = File::Find::Rule->file()->name( '*.pod' )->in('.');
27 # die join " ", @pod_files;
28
29 my %headers = ();
30
31 for my $pod_file (@pod_files) {
32 my (undef, $dir, $file) = File::Spec->splitpath($pod_file);
33 my @dirs = grep { $_; } File::Spec->splitdir($dir);
34 my ($base, $ext) = split m/[.]/xms, $file;
35 my $pod_name = join '::', qw(Marpa R2), @dirs, $base;
36 # say $pod_name;
37 my $tree = Pod::Simple::SimpleTree->new->parse_file($pod_file)->root;
38 find_header($tree, $pod_name);
39 }
40
41 sub find_header {
42 my ($subtree, $pod_name) = @_;
43 if (ref $subtree eq 'ARRAY') {
44 if (substr($subtree->[0], 0, 4) eq 'head') {
45 $headers{join ' ', $pod_name, $subtree->[2]} = 1;
46 # say $subtree->[2];
47 }
48 if ($subtree->[0] eq 'L') {
49 my $hash = $subtree->[1];
50 return if not $hash->{type} eq 'pod';
51 $to_name = $hash->{to} // $pod_name;
52 return if not exists $hash->{section};
53 $links{join ' ', $to_name, $hash->{section}} = $pod_name;
54 }
55 find_header($_, $pod_name) for @{$subtree};
56 }
57 return;
58 }
59
60 # say Dumper($tree);
61
62 # say "$_ H" for keys %headers;
63 # say "$_ L" for keys %links;
64 # exit 0;
65
66 for my $link (keys %links) {
67 if (not exists $headers{$link})
68 {
69 my $pod_name = $links{$link};
70 say "$pod_name unresolved link: $link"
71 }
72 }