-
Notifications
You must be signed in to change notification settings - Fork 24
/
cpanfile-dump
executable file
·130 lines (87 loc) · 3.42 KB
/
cpanfile-dump
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!perl
use strict;
use warnings;
use CPAN::Meta::Requirements;
use Module::CPANfile;
use Getopt::Long qw(:config posix_default no_ignore_case gnu_compat);
my @phases = qw(configure build test develop runtime);
my @types = qw(requires recommends suggests conflicts);
my %o = map { $_ => 1 } qw/configure build test runtime requires recommends/;
GetOptions(
"h|help", \$o{help},
"with-feature=s@", \$o{with},
"without-feature=s@", \$o{without},
"with-all-features", \$o{with_all},
map { ("$_!", \$o{$_}) } (@phases, @types),
);
if ($o{conflicts}) {
delete $o{$_} for qw/requires recommends suggests/;
}
if ($o{help}) {
if (eval { require Pod::Usage; 1 }) {
Pod::Usage::pod2usage(1);
} else {
die "Usage: cpanfile-dump\n\nSee perldoc cpanfile-dump for more details.\n";
}
}
my $file = Module::CPANfile->load("cpanfile");
my %excludes = map { $_ => 1 } @{$o{without}};
my @features = grep { !$excludes{$_} } $o{with_all}
? ( map { $_->identifier } $file->features )
: @{$o{with}};
my $prereqs = $file->prereqs_with( @features ); # CPAN::Meta::Prereqs object
my $merged = CPAN::Meta::Requirements->new;
for my $phase ( @phases ) {
next unless $o{$phase};
for my $type ( @types ) {
next unless $o{$type};
$merged->add_requirements( $prereqs->requirements_for( $phase, $type ) );
}
}
print "$_\n" for sort $merged->required_modules;
__END__
=head1 NAME
cpanfile-dump - Dump prerequisites from a cpanfile
=head1 SYNOPSIS
# Install typical required and recommended modules
cpan `cpanfile-dump`
# Skip configures phase
cpan `cpanfile-dump --no-configure`
# Also include develop phase and suggests type
cpan `cpanfile-dump --develop --suggests`
# Include a feature
cpan `cpanfile-dump --with-feature=sqlite`
=head1 DESCRIPTION
This script reads prereqs from a F<cpanfile> and dumps a raw list of
them to standard output. This is useful for piping these as input to
another program such as C<cpan>, C<cpanm> or C<cpanp>.
By default, it prints configure, build, test and runtime requirements and
recommendations. Command line options can be used to modify the default
choices.
This script is distributed with L<Module::CPANfile> since version 1.0002.
=head1 OPTIONS
=over 4
=item --configure, --build, --test, --runtime, --develop
Specify the phase to include/exclude. Defaults to include all but
C<--develop> but you can exclude some phases by specifying the options with
C<--no-> prefix, like C<--no-configure>.
=item --requires, --recommends, --suggests, --conflicts
Specify the type to include/exclude. Defaults to include only C<--requires> and
C<--recommends> but you can exclude some types by specifying the options with
C<--no-> prefix, like C<--no-recommends>.
Specifying C<--conflicts> will turn off all other types (even if specified
on the command line).
=item --with-feature, --with-all-features, --without-feature
cpanfile-dump --with-feature=sqlite
cpanfile-dump --with-all-features --without-feature=yaml
Specify features to include in the dump. C<--with-feature> and C<--without-feature>
may be used more than once.
=back
=head1 NOTES
Because C<cpanm> supports reading cpanfile directly, instead of piping the output of this
program, you're recommended to use C<cpanm --installdeps .> to install modules from cpanfile.
=head1 AUTHOR
David Golden
=head1 SEE ALSO
L<Module::CPANfile> L<cpanfile> L<App::mymeta_requires>
=cut