Self-adaption from Dist::Zilla method applied to Marpa in attachment.
Usage: /usr/bin/perl /home/jdurand/Documents/scanprereqs.pl path1 [...
[pathn]]
Example: /usr/bin/perl /home/jdurand/Documents/scanprereqs.pl
~/git/Marpa--R2/cpan
Output:
$VAR1 = {
'URI::URL' => '0',
'XSLoader' => '0',
'File::Spec::Functions' => '0',
'CPAN::Version' => '0',
'autodie' => '0',
'Fatal' => '0',
'overload' => '0',
'CPAN' => '0',
'HTML::Entities' => '0',
'charnames' => '0',
'List::Util' => '0',
'CPAN::Meta' => '0',
'Data::Dumper' => '0',
'Test::More' => '0.94',
'WWW::Mechanize' => '0',
'Pod::Simple' => '0',
'feature' => '0',
'File::Copy' => '0',
'warnings' => '0',
'Perl::Tidy' => '0',
'perl' => '5.010',
'sort' => '0',
'Test::CPAN::Meta' => '0',
'HTML::Parser' => '3.69',
'HTML::LinkExtor' => '0',
'ExtUtils::Mkbootstrap' => '0',
'ExtUtils::Manifest' => '0',
'Text::Wrap' => '0',
'base' => '0',
'Module::Build' => '0',
'Time::Piece' => '0',
'PPI' => '0',
'Test::Pod' => '0',
'YAML::XS' => '0',
'IPC::Cmd' => '0',
'vars' => '0',
'Getopt::Long' => '0',
'Module::Load' => '0',
'Perl::Critic' => '0',
'Carp' => '0',
'Test::Perl::Critic' => '0',
'Cwd' => '0',
'lib' => '0',
'File::Path' => '0',
'POSIX' => '0',
'File::Spec' => '0.82',
'Text::Diff' => '0',
'English' => '0',
'utf8' => '0',
'constant' => '0',
'Scalar::Util' => '0',
'Exporter' => '0',
'DynaLoader' => '0',
'LWP::UserAgent' => '0',
'open' => '0',
'File::Temp' => '0',
'File::Slurp' => '0',
'GetOpt::Long' => '0',
'strict' => '0'
};
JD.
--
You received this message because you are subscribed to the Google Groups
"marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
#!env perl
#
# Inspired by Dist::Zilla::Plugin::AutoPrereqs.pm
#
use strict;
use diagnostics;
use List::AllUtils 'uniq';
use Perl::PrereqScanner 1.016; # don't skip "lib"
use PPI;
use CPAN::Meta::Requirements;
use version;
use File::Find;
use File::Basename;
use File::Slurp;
use Data::Dumper;
use POSIX qw/EXIT_SUCCESS/;
use File::Spec;
use IO::Handle;
autoflush STDOUT 1;
if (! @ARGV) {
print STDERR "Usage: $^X $0 path1 [... [pathn]]\n";
print STDERR "\n";
print STDERR "Example: $^X $0 ~/git/Marpa--R2/cpan\n";
exit(EXIT_SUCCESS);
}
our @sets = (
[ configure => 'found_configure_files' ], # must come before runtime
[ runtime => 'found_files' ],
[ test => 'found_test_files' ],
);
my @modules;
my $scanner = Perl::PrereqScanner->new();
my $req = CPAN::Meta::Requirements->new;
find({ wanted => \&wanted, no_chdir => 1 }, @ARGV);
# remove prereqs shipped with current dist
$req->clear_requirement($_) for @modules;
$req->clear_requirement($_) for qw(Config Errno); # never indexed
# we're done, return what we've found
my %got = %{ $req->as_string_hash };
my %without_Marpa = map {$_ => $got{$_}} grep {! /\bMarpa\b/} keys %got;
print Dumper(\%without_Marpa);
exit(EXIT_SUCCESS);
sub wanted {
my $filename = File::Spec->canonpath($_);
return if (! -f $filename);
my $content = read_file($filename);
# parse only perl files
return unless ($filename =~ /\.(?:pm|pl|t|psgi)$/i
|| $content =~ /^#!(?:.*)perl(?:$|\s)/);
# RT#76305 skip extra tests produced by ExtraTests plugin
return if $filename =~ m{^t/(?:author|release)-[^/]*\.t$};
print "Scanning $filename\n";
# store module name, to trim it from require list later on
my @this_thing = $filename;
if ($this_thing[0] =~ /^t/) {
push @this_thing, ($this_thing[0]) x 2;
$this_thing[1] =~ s{^t/}{};
$this_thing[2] =~ s{^t/lib/}{};
} else {
$this_thing[0] =~ s{^lib/}{};
}
@this_thing = uniq @this_thing;
s{\.pm$}{} for @this_thing;
s{/}{::}g for @this_thing;
push @modules, @this_thing;
# parse a file, and merge with existing prereqs
my $file_req = $scanner->scan_string($content);
$req->add_requirements($file_req);
}