<?xml version="1.0" encoding="windows-1252"?>
<node id="316828" title="Auto-document prerequisites in README" created="2003-12-24 06:06:22" updated="2005-07-29 16:10:56">
<type id="1980">
snippet</type>
<author id="272239">
liz</author>
<data>
<field name="doctext">
</field>
<field name="snippetdesc">
&lt;B&gt;* UPDATE * Please see [id://317309] for further developments.&lt;/B&gt;
&lt;P&gt;
This came from a discussion in the CB with [castaway], who wished that direct module prerequisites would have to be at least listed in the README file.
&lt;P&gt;
Of course, as an author of a CPAN module, you put the prerequisites in the Makefile.PL script.
&lt;P&gt;
This code needs to be added to that Makefile.PL script by the author.  It scans its own source for PREREQ_PM and extracts the module names from there.  It then places those modules names inside the README file wherever the string "Required Modules:" and two empty lines are found.  Voila, instant documentation!</field>
<field name="snippetcode">
&lt;CODE&gt;
open( my $makefile, '&lt;', $0) or die "Could not open $0: $!\n";
$_ = do {local $/; &lt;$makefile&gt;};

if (($_) = m#PREREQ_PM\s*=&gt;\s*{([^}]+)}#) {
    my @module = map {s#['"]##g; $_} m#(\S+)\s*=&gt;#sg;
    open( my $readme, '&lt;', 'README' ) or die "Could not open README: $!\n";
    $_ = do {local $/; &lt;$readme&gt;};
    if (s#(\nRequired Modules:\n)(?:.*?)(\n\n)#"$1  ".(do {local $"="\n  ","@module"}).$2#se) {
        open( $readme, '&gt;', 'README' ) or die "Could not open README: $!\n";
        print $readme $_;
    }
}
&lt;/CODE&gt;</field>
</data>
</node>
