Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to document Perl code? [closed]

People also ask

What is head1 in Perl?

Using an =head1 indicates something important, =head2 means something less important. The tool that is used to display the POD will usually use bigger characters to display the text of a head1 than that of a head2 which in turn will be displayed using bigger fonts than the regular text.

What is POD documentation Perl?

Pod is a simple-to-use markup language used for writing documentation for Perl, Perl programs, and Perl modules. Translators are available for converting Pod to various formats like plain text, HTML, man pages, and more. Pod markup consists of three basic kinds of paragraphs: ordinary, verbatim, and command.


Look inside almost any Perl module and you'll see the Plain Old Documentation (POD) format. On CPAN Search, when looking at a module you have the option of viewing the raw source, so that's one way you can look at the raw pod, but you can also use perldoc from the command line. The -m switch shows you the file

perldoc -m Foo::Bar

Or, if you want to find the file so you can look at it in your favorite editor, use the -l switch to find it:

perldoc -l Foo::Bar

Once you start documenting your program, you put the Pod in the file right with the code, either interwoven with the code so the documentation is next to the relevant parts, or at the beginning, middle, or end as one big chunk.

Pod is easily translated to several other formats, such as LaTeX, Postscript, HTML, and so on with translators that come with Perl (pod2latex, pod2ps, pod2html). I even have a pod translator that goes to InDesign. Writing your own Pod translator is easy with Pod::Simple, so if you don't find a translator to your favorite final form, just make it yourself.

There are also several tools that you can add to your test suite to check your Pod. The Test::Pod module checks for format errors, the Test::Pod::Coverage module checks the you've documented each subroutine, and so on. You also might be interested in my Perl documentation documentation.


I definitely recommend POD.

POD can also be used in-line with code but I prefer to put at bottom of program after __END__ (as recommended by Damian Conway in Perl Best Practices).

Look at POD::Server & POD::Webserver, which provides a web front-end to all your PODs.


Perl pod.

This is how Mozilla documents their Perl.


Not to be overly flip, but the best way to document Perl code is the same way as you would document code in any other language.

As for specific tools, I use a mix of standard inline comments, pod for larger chunks of documentation where a format similar to man is appropriate, and TeX as a final fallback for documents that need to be more freeform. (And, in the spirit of "same as any other language", yes, I do use pod for documenting non-Perl code as well.)


Which module do you use to convert pod to html?

Check out Pod::ProjectDocs - you get a simple command-line utility that will convert all the POD in your Perl project into a set of HTML pages that look just like what you see on search.cpan.org.


No one mentioned Smart::Comments? It's not always what you want but good if you need more power to comments.