Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Mixing documentation and data

by tobyink (Abbot)
on Feb 01, 2013 at 10:20 UTC ( #1016501=note: print w/ replies, xml ) Need Help??

in reply to Mixing documentation and data

I'm assuming you mean that you have a list of error codes and want this list to be included in the running source code for the program (as a hash or array or whatever), and also in the program's documentation, but without duplicating the list of error codes.

There are three real options...

  1. Define your messages in your pod, and then make your module parse its own documentation at run-time to extract those messages.

  2. Define your messages in your code, and then generate your documentation from that at install time, using something like Pod Weaver.

  3. Perl and Pod are two different syntaxes. It is possible (usually using heredocs) to write text which can be executed as Perl and is also seen as Pod. Here's an example:

    use 5.010; use strict; use warnings; use Data::Dumper; our %messages = map /^\s+(.+?):(.+)$/?($1=>$2):(), split "\n", <<'=cut +'; =head1 MESSAGES The following messages are defined... eof:Unexpected end of file bad_tag:Syntax error in tag =cut print Dumper \%messages;

    View that file with perldoc and you'll see the list of messages. Execute it, and you'll see they get dumped.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Comment on Re: Mixing documentation and data
Download Code
Re^2: Mixing documentation and data
by coolmichael (Deacon) on Feb 01, 2013 at 18:15 UTC
    This is exactly the idea I was looking for. Thanks!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016501]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2014-08-01 01:13 GMT
Find Nodes?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:

    Results (256 votes), past polls