summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2014-08-29 04:48:18 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2014-08-29 04:48:18 +0000
commit6b1d736955543538c54f1d8033ce3bdcb175da91 (patch)
treef7f7e23929d493647c0e2f9b1a556d3101194538 /script
downloadModule-CPANfile-tarball-master.tar.gz
Module-CPANfile-1.1000HEADModule-CPANfile-1.1000master
Diffstat (limited to 'script')
-rwxr-xr-xscript/cpanfile-dump131
-rwxr-xr-xscript/mymeta-cpanfile115
2 files changed, 246 insertions, 0 deletions
diff --git a/script/cpanfile-dump b/script/cpanfile-dump
new file mode 100755
index 0000000..04e1736
--- /dev/null
+++ b/script/cpanfile-dump
@@ -0,0 +1,131 @@
+#!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 that doesn't support reading cpanfile directly,
+i.e. C<cpan> 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
+
diff --git a/script/mymeta-cpanfile b/script/mymeta-cpanfile
new file mode 100755
index 0000000..66c4916
--- /dev/null
+++ b/script/mymeta-cpanfile
@@ -0,0 +1,115 @@
+#!perl
+use strict;
+use warnings;
+use CPAN::Meta;
+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 } @phases, @types; # default all
+
+GetOptions(
+ "include-empty!", \$o{include_empty},
+ "h|help", \$o{help},
+ map { ("$_!", \$o{$_}) } (@phases, @types),
+);
+
+if ($o{help}) {
+ if (eval { require Pod::Usage; 1 }) {
+ Pod::Usage::pod2usage(1);
+ } else {
+ die "Usage: mymeta-cpanfile\n\nSee perldoc mymeta-cpanfile for more details.\n";
+ }
+}
+
+sub get_mymeta {
+ for my $file (qw( MYMETA.json MYMETA.yml META.json META.yml )) {
+ next unless -r $file;
+ my $meta = eval { CPAN::Meta->load_file($file) };
+ return $meta if $meta;
+ }
+}
+
+my $meta = get_mymeta or die "Could not locate any META files\n";
+
+my $prereqs = $meta->prereqs;
+my $filtered = {};
+
+while (my($phase, $types) = each %$prereqs) {
+ next unless $o{$phase};
+ while (my($type, $reqs) = each %$types) {
+ next unless $o{$type};
+ $filtered->{$phase}{$type} = $reqs;
+ }
+}
+
+my $cpanfile = Module::CPANfile->from_prereqs($filtered);
+print $cpanfile->to_string($o{include_empty});
+
+__END__
+
+=head1 NAME
+
+mymeta-cpanfile - Dump cpanfile out of (MY)META files
+
+=head1 SYNOPSIS
+
+ perl Makefile.PL # or Build.PL
+ mymeta-cpanfile
+
+ # Skip configures phase and suggests type
+ mymeta-cpanfile --no-configure --no-suggests
+
+ # Include empty blcok for phases without prereqs
+ mymeta-cpanfile --include-empty
+
+=head1 DESCRIPTION
+
+This script reads prereqs metadata from MYMETA files in the current
+directory and prints C<cpanfile> that represents the prereqs. Useful
+when you want to migrate to using L<cpanfile> from existing
+C<Makefile.PL> or C<Build.PL> with dependency specification.
+
+This script is distributed with L<Module::CPANfile> since version 0.9021.
+
+=head1 OPTIONS
+
+=over 4
+
+=item --configure, --build, --test, --runtime, --develop
+
+Specify the phase to include/exclude. Defaults to include all phases,
+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 all types,
+but you can exclude some types by specifying the options with C<--no->
+prefix, like C<--no-conflicts>.
+
+=item --include-empty
+
+By default, phases without any prereqs are not dumped, By giving this
+option, cpanfile will have an empty block such as:
+
+ on test => sub {
+
+ };
+
+Defaults to false.
+
+=back
+
+=head1 AUTHOR
+
+Tatsuhiko Miyagawa
+
+=head1 SEE ALSO
+
+L<Module::CPANfile> L<cpanfile> L<App::mymeta_requires>
+
+=cut
+