13.4 Embedded DocumentationImmediately following the mandatory true value in the file, you'll find the _ _END_ _ marker: _ _END_ _ This marker tells Perl that there's no Perl code anywhere later in the file and that the Perl parser can stop now.[8][8] The data immediately following the _ _END_ _ marker is available by reading from the DATA filehandle, which is a great way to include a small amount of constant data with your program. However, that's not why we're doing that here. Following the _ _END_ _ marker, you'll find the embedded documentation for the module: # Below is stub documentation for your module. You'd better edit it! This documentation is in POD format. The perlpod manpage describes the POD format in detail. Like Perl itself, POD is said to mean various things, such as Perl Online Documentation or Plain Old Documentation, and so on. To most of us, it's just POD.As the template describes, you're expected to edit portions of this text to fit your particular module. In particular, leaving the blah blah blah is considered bad form.The POD information is extracted automatically by the installation process to create the native documentation format, such as Unix manpages or HTML. Also, the perldoc command can locate POD in the installed scripts and modules and format it for the screen.One nice thing about POD is that it can be interspersed with the Perl implementation code it describes. For example, from Chapter 12, you needed three subroutines for the Island::Plotting::Maps module. You can commingle the code and documentation. Each POD directive (a line beginning with an equal sign) switches from Perl mode (lines interpreted as Perl code) to POD mode (lines interpreted as documentation), and each line beginning with =cut switches back. Thus, the resulting file looks something like: package Island::Plotting::Maps; As you can see, the documentation for the subroutines is now very near the subroutine definition, in hope that as one gets updated, the other will be similarly changed. (Out-of-date documentation is often worse than no documentation at all because at least with no documentation at all, the user is forced to look at the source code.) Many modules in the CPAN do this. The penalty is a very slight increase in compile-time activity because the Perl parser has to skip over the embedded POD directives.Whether you place your POD at the end of the file (as the template suggests) or intertwined with your code (as presented in the preceding paragraphs) the important thing to remember is always document your code. Even if it's just for you, a few months later, when your brain has been 42,000 other places before you look at the code again, you'll be glad to have those notes. Documentation is important. |
•
Table of Contents
•
Index
•
Reviews
•
Reader Reviews
•
Errata
Learning Perl Objects, References & Modules
By
Randal L. Schwartz