in reply to check pod and insert missing sections

I haven't completely figured it out, but I have determined that you can add a head1 with code like this:
use Pod::POM; my $parser = Pod::POM->new(); my $pom = $parser->parse_file(...); my $h1 = $pom->add($parser, 'head1', 'This is a new head1');
and the new head1 will appear at the end of the POD. However, I don't think it will be easy to add a a head1 section in the middle of the document (in case you want your sections to follow a uniform ordering). In that case, something like this might work for you:
my @SECTIONS = qw(name synopsis ...); my $pom = $parser->parse_file(...); my %found; for my $h1 ($pom->head1()) { $found{lc($h1->title)} = $h1; } for my $title (@SECTIONS) { my $h1; if ($h1 = $found{$title}) { print $h1; } else { print "=head1 ", uc($title), "\n\n"; } }
Of course, this code silently discards sections that are not listed in @SECTIONS which is probably not what you want to do, but it at least is a start.

Replies are listed 'Best First'.
Re^2: check pod and insert missing sections
by leocharre (Priest) on May 02, 2008 at 14:12 UTC

    If I want to insert in middle, I could have an 'inject()' method, or override 'add()' to accept a possible index attrib.. or.. who knows.

    And I don't mind rebuilding the entire doctree every time there is an edit either.

    Seems this could be of use to others? If I find out anything good or make something worthy, I'll update.

    Thank you!