Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Auto-document prerequisites in README

by liz (Monsignor)
on Dec 24, 2003 at 11:06 UTC ( #316828=snippet: print w/replies, xml ) Need Help??
Description: * UPDATE * Please see How the CB created another CPAN module: Devel::Required for further developments.

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.

Of course, as an author of a CPAN module, you put the prerequisites in the Makefile.PL script.

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!

open( my $makefile, '<', $0) or die "Could not open $0: $!\n";
$_ = do {local $/; <$makefile>};

if (($_) = m#PREREQ_PM\s*=>\s*{([^}]+)}#) {
    my @module = map {s#['"]##g; $_} m#(\S+)\s*=>#sg;
    open( my $readme, '<', 'README' ) or die "Could not open README: $
    $_ = do {local $/; <$readme>};
    if (s#(\nRequired Modules:\n)(?:.*?)(\n\n)#"$1  ".(do {local $"="\
+n  ","@module"}).$2#se) {
        open( $readme, '>', 'README' ) or die "Could not open README: 
        print $readme $_;
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://316828]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2018-04-22 01:15 GMT
Find Nodes?
    Voting Booth?