Split pod documentation from a Perl module
This Perl script splits the file name on its command line into .pm and
.pod parts. The files are given a temporary name using the process
number ($$
).
#!/home/ben/software/install/bin/perl use warnings; use strict; use utf8; use FindBin '$Bin'; use File::Slurper qw/read_text write_text/; if (! @ARGV) { usage (); } for my $file (@ARGV) { if (! -f $file) { warn "No such file '$file'"; next; } my $text = read_text ($file); my $pod = ''; while ($text =~ s!(^=(head|encoding|pod).*?)=cut$!!sm) { $pod .= "$1\n"; } my $podout = "$file.pod.$$"; my $pmout = "$file.pm.$$"; write_text ($pmout, $text); write_text ($podout, $pod); } exit; sub usage { print <<EOF; $0 - split a Perl module into Perl and Pod files Usage: $0 <file1> <file2> The output is the name of the files with a random number attached. EOF }
At my blog post about this topic, commentators note that
-
One can use
perldoc -u
to extract the pod; - There are many more keywords than in this script;
- The CPAN modules Test::Pod::Snippets turns the synopsis into tests, and Dist::Zilla::Plugin::CoalescePod merges related .pm and .pod files together.
Copyright © Ben Bullock 2009-2024. All
rights reserved.
For comments, questions, and corrections, please email
Ben Bullock
(benkasminbullock@gmail.com).
/
Privacy /
Disclaimer