#!/usr/bin/perl use strict; use warnings; use PPI; foreach my $filename (@ARGV) { print "Opening up $filename...\n"; my $doc = PPI::Document->new($filename); foreach my $sub (@{$doc->find('PPI::Statement::Sub')}) { my $subname = $sub->name; my $previous = $sub->previous_sibling; $previous = $previous->previous_sibling while $previous && !$previous->isa('PPI::Token::Pod'); if($previous && $previous->isa('PPI::Token::Pod') && $previous->{'content'} =~ /=(?:head\d|item)\s+$subname/i) { print "skipping $subname; already documented\n"; next; } my $pod = PPI::Token::Pod->new; print "Enter documentation for $subname (ctrl+D when done, leave blank to skip):\n"; my $text = join '', ; $text =~ s/^\n+|\n+$//g; unless($text) {print "skipping $subname; no text provided"; next} $pod->{'content'} = "=head2 $subname()\n\n$text\n\n=cut\n\n"; $sub->insert_before($pod); } print "Writing code to $filename...\n"; $doc->save($filename); # print $doc->serialize; }