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 $_;
}
}