Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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: $
+!\n";
    $_ = 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: 
+$!\n";
        print $readme $_;
    }
}
Comment on Auto-document prerequisites in README
Download Code

Back to Snippets Section

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (14)
As of 2015-07-29 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls