Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

In reply to Re: Mixing documentation and data by tobyink
in thread Mixing documentation and data by coolmichael

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-23 07:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found