moderated >> [BUG?] Documenting self-documenting Perl code

by Ilya Zakharevich » Mon, 21 Feb 2005 08:54:25 GMT

If your perl code is self-documenting, it makes sense to embed it into
POD; so one needs to have a section of the program which is
simultaneously code *and* POD. Perl parser was designed with this
functionality in mind (its parsing rules for recognition of POD are
made slightly different from POD formatters); however, I do not recall
this being mentioned before (tested to run with Perl 5.00466..5.8.2; I
tested perldoc of 5.8.2; do not know how to test with older versions,
but I see no reason why it should not work):

#!perl -wl
use strict;
use Data::Dumper;

=head1 NAME

self-documenting - Try self-documenting code

=head1 SYNOPSIS

perl self-documenting
perldoc self-documenting

=head1 DESCRIPTION

This package defines the following hash:

=cut

my %h = do { # POD starts where statement can start...

=for POD-and-code
=cut

key1 => 'value1',
key2 => 'value2';

=cut # Perl reads this as begin-POD (preceeding ; is needed)

=cut # Thus one =cut is NOT enough...

};

print Dumper \%h;
print 11;
__END__

Hope this helps,
Ilya

Similar Threads

1. Seperating Perl code and HTML using Here Documents...

Hi,
 I have a Perl cgi program which can return a number of different HTML 
pages based on input.
I am using Here Documents to hold the HTML pages with $variables to 
output dynamic content.
The way I'm doing it is becoming very sloppy and unmanageable.

Can someone suggest a better/cleaner way of seperating dynamic HTML 
and perl code?

Here's an example of what I'm doing (shame on me):

my $webpage;
my $var1;
my $var2;
...
if( ...) {
 open (FILE, 'good-page.pl') or die "blah...";
 my @code = <FILE>;
 eval join("\n", @code);

} else {
 open (FILE, 'bad-page.pl') or die "blah...";
 my @code = <FILE>;
 eval join("\n", @code);
}
...
print "http headers...";
print $webpage;

############################################

# good-page.pl

$webpage = <<PAGE;
<html>
...
Good Page $var1
...
</html>
PAGE

############################################

# bad-page.pl

$webpage = <<PAGE;
<html>
...
Bad Page $var2
...
</html>
PAGE

2. highlight perl code in html document - Perl

3. looking for tools/methods to document source code (non-PERL)

Howdy,

I am trying to find some tools to facilitate writing design/overview
documents
describing a proprietary language source. The language is used for
modeling
real life situation and typical development tasks consist of writing
either completely
new logic or using/extending current structures to model new parts/
behaviours.

It would be helpful to have documentation that would be an overview of
certain
typical tasks (modeling new part - properties and behaviours), flow of
logic, relevant
class attributes or methods etc - that would written as eg. Word file
with frequent links
to source code. My question is mostly about maintaining those links -
since code
constantly evolves and language does not support access restriction so
anybody on
the team can modify any file at any time. So if I write a doc and it
refers to some
specific method and somebody makes modification to that method I would
like to
know about it so I can possibly update the documentation. Likewise
person that
modifies/enhances the code should be warned that there is certain
documentation
dependent on that code.

I am looking for sth fairly lightweight - not Literate Programming
type - maybe as
simple as sth to maintain some image of code tagged with unique tags
that can
be referenced in Word documents - and links to proper parts of the
source code.
Maybe with checksums for the methods/classes formed on preprocessed/
decompiled
code stored in parallel so if any area of the code that has a tag that
is part of any
documents is modified then we can alert developer and document
author.

Thanks for any pointer/keywords/ideas.

JT

4. Hyperlinks from one document to another document on a different dr - MS Excel Charts

5. email excel document with hyperlinks to mutliple documents

I need to send several people an excel document that hyperlinks to many other 
documents. The recipients need to get all the information from the other 
documents.  How can I make this happen?

6. Hyperlinks work when document not locked, don't work when document is locked

7. hyperlink from office-document to lotus notes document?

Hi all,

how can I create a hyperlink from word or excel, that targets to a
specific lotus notes document? How would that look like?
If I copy the lotus notes document as link, and paste that into word,
I only get some plain-text xml code ...
can anybody help me?

Thanks!
Johanna

8. Hyperlinking elements in document 1 to document 2 in Pages