views:

163

answers:

5

I've come into ownership of a bunch of code that's held together with various Perl scripts. There's some documentation in the form of comments (not Pod) embedded in these scripts that I'd like to be able to extract and browse in an HTML format.

Basically, I'm looking for something like javadoc or rubydoc, but for Perl. "perldoc" seemed like an obvious search string, but I guess that's just the documentation for Perl itself. "perlpod" also came up, but I'm looking for something that extracts comments that already exist in the code without much special formatting. (Having to add extra bits would seem to be counterproductive.)

Whatever tool I choose, I'd like to point it to the code and have it recursively find Perl files, generate documentation, and save it in a directory that I choose. It should also be cross-platform (Windows XP, 7, Mac OS X, and Ubuntu Linux). Something written in Perl itself would seem to qualify. It also should play nicely with other programming languages, if possible.

What are some options you'd recommend?

Sorry for my ignorance -- I've never done much beyond simple stuff with Perl before.

+1  A: 

Natural Docs is written in Perl and can document a number of languages. It's pretty flexible in terms of what it can document. I'm pretty sure it can do everything you've asked for here. Give it a look!

FrustratedWithFormsDesigner
While I like the idea of Natural Docs (and it's default is prettier than pod2html) if you use some tool that is different from what every other Perl programmer uses you will have problems.
mpeters
@mpeters: According to the Nautal Docs documentation, it is compatible with the Perl POD standards.see: http://www.naturaldocs.org/documenting/reference.html#Comments and look for Perl POD
FrustratedWithFormsDesigner
This looked really nice, but it doesn't pull out the comments and organize them. (Very easy to set up and pretty output, though.)
Benjamin Oakes
@Benjamin Oakes: Ok, I admit I've never used it for Perl. I use it for documenting PL/SQL. It has its problems, but it's by far the best PL/SQL documentation tool I've seen so far.
FrustratedWithFormsDesigner
Yeah, it's definitely good to know about. I'm kinda frustrated about documentation because this project I'm working on uses 5 or 6 programming languages. A unified documentation tool would be great.
Benjamin Oakes
@Benjamin Oakes: Multi-lang in one doc set, yeah a messy problem. The closest I've seen to solving that is Natural Docs, but for languages that don't have full language support, there's definitely a lot of tweaking to get things right. I think for PL/SQL it took a solid morning to get something respectable, and more fine tuning over time. But since all the source is there (and it sounds like your Perl is better than mine ;)) you can always modify NaturalDocs itself as you see fit ...as if you have the time, right? ;)
FrustratedWithFormsDesigner
@FrustratedWithFormsDesigner: yes NaturalDocs can recognize POD blocks but it doesn't do anything else with the POD. It treats ND POD blocks as just big sections that need to follow it's format. It ignores every other thing about POD like L<>, B<>, C<>, I<>, F<>, =head1, =head2, =head3, =over, =item, etc.
mpeters
+5  A: 

Look more into perldoc. It is a tool for viewing and generating module documentation as well as a command-line tool for reading the Perl documentation.

For example, you can create an HTML file of a module's pod with

perldoc -o html path/to/Module.pm
mobrule
It is also the de facto standard for Perl code documentation (try browsing some code on CPAN).
reinierpost
That command you gave me didn't work (default installation of `perl` on OS X 10.6).
Benjamin Oakes
Can you say more about "didn't work"?
brian d foy
Sorry, I should have been more specific. It was complaining about HTML not being a valid format. It turns out that I was specifying the wrong filename to process. Your command actually does work.
Benjamin Oakes
+11  A: 

If your Perl files contain Perl's Plain Old Documentation (POD), you can use pod2html to generate HTML.

Or, maybe you can adapt this to suit your needs: Comments to POD - com2pod.pl

toolic
That's helpful to know, but this seems like a lot of work just to spit out what's already there in a slightly more readable fashion, even with com2pod. (It feels like I'm writing a documentation system myself.) It seems hard to believe that this is the best option. Am I missing something?
Benjamin Oakes
Does your Perl code contain POD?
toolic
No, the existing code (which I didn't write) just has comments about subroutines, etc. above their definition. There are also descriptions about what the files are for before the code starts (e.g., right after the shebang).
Benjamin Oakes
I'd convert those comments to Pod first. Don't make a bad situation worst by making tools around a format you should be using. :)
brian d foy
Yeah, I try to act like a Roman when in Rome, but I'm also lazy/short on time. `autopod` seemed like a good compromise between using POD and not necessitating tons of menial formatting changes.
Benjamin Oakes
+2  A: 

Documentation in comments? These are two different concepts. Comments are for the maintenance programmer, documentation is for the user.

How very unlazy. What will the unvirtuous newbies think of next? °_°;

Convert the text from comment form to POD, meaning removing the # characters and tacking some appropriate =command paragraphs above and below. Then you can employ the whole POD toolchain for checking, converting etc.

daxim
Keeping the docs in the file next to the code, at least for libraries, means there is an easy way to tell some day that the docs don't match the code and no real excuse for letting the two diverge. Otherwise you are right that they are separate.
Paul
Since this is a question referring only to maintenance, the distinction seems irrelevant for this question.
Benjamin Oakes
Paul: You totally misunderstood that, it's a seperation of meaning, not location.Benjamin: It's not irrelevant. Realise that comments and docs have different semantics and therefore are expressed in different syntax. This is not an accident, as they are generally not exchangable. Making them so perverts the purpose.
daxim
I can appreciate that, but for the purposes of this question, I was only looking for a way to take what was already there and make it easy to browse.
Benjamin Oakes
+4  A: 

I do not have any experience with it, but Pod::Autopod looks interesting. It comes with a command line utility autopod.

autopod - using the Perl library Pod::Autopod to generate javadoc like documentation with pod syntax. It is designed to understand perl code in class style, so typically PM files.

It might be worth a look. Please let us know if you do try it out.

Sinan Ünür
While it hardly does everything perfectly, it does exactly what I had in mind in terms of processing comments, generating the POD, and spitting out the HTML.
Benjamin Oakes