aboutsummaryrefslogtreecommitdiffstats
path: root/perl-external/bin
diff options
context:
space:
mode:
Diffstat (limited to 'perl-external/bin')
-rw-r--r--perl-external/bin/add_module.pl52
-rw-r--r--perl-external/bin/build_all_modules.pl40
-rwxr-xr-x[-rw-r--r--]perl-external/bin/cpanm0
-rwxr-xr-xperl-external/bin/module-manage.pl142
4 files changed, 142 insertions, 92 deletions
diff --git a/perl-external/bin/add_module.pl b/perl-external/bin/add_module.pl
deleted file mode 100644
index 6c9be8df2..000000000
--- a/perl-external/bin/add_module.pl
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/usr/bin/env perl
-
-use strict;
-use warnings;
-
-use IPC::Run3;
-use LWP::Simple;
-use File::Slurp;
-use Path::Class;
-
-my $root_dir = file(__FILE__)->dir->parent->absolute->stringify;
-my $module_list = "$root_dir/modules.txt";
-my $url_list = "$root_dir/urls.txt";
-my $minicpan = "$root_dir/minicpan";
-my $local_lib = "$root_dir/../local-lib5";
-my $cpanm_cmd = "perl $root_dir/bin/cpanm -l $local_lib --reinstall";
-
-my $module = $ARGV[0] || die "Usage: $0 Dist::To::Add";
-
-# try to install the distribution using cpanm
-my $out = '';
-my $cmd = "$cpanm_cmd $module";
-print " running '$cmd'\n";
-run3( $cmd, undef, \$out, \$out )
- || die "Error running '$cmd'";
-
-my @fetched_urls =
- map { s{.*(http://\S+).*}{$1}; $_ }
- grep { m{^Fetching http://search.cpan.org} }
- split /\n/, $out;
-
-write_file( $module_list, { append => 1 }, "$module\n" );
-write_file( $url_list, { append => 1 }, map { "$_\n" } @fetched_urls );
-
-foreach my $url ( read_file($url_list) ) {
-
- my ($filename) = $url =~ m{/(authors/.+)$};
-
- my $destination = file("$minicpan/$filename");
- $destination->dir->mkpath;
-
- next if -e $destination;
-
- print " $url\n -> $destination\n";
-
- is_success( getstore( $url, "$destination" ) )
- || die "Error saving $url to $destination";
-}
-
-# go to the minicpan dir and run dpan there
-chdir $minicpan;
-exec 'dpan -f ../dpan_config';
diff --git a/perl-external/bin/build_all_modules.pl b/perl-external/bin/build_all_modules.pl
deleted file mode 100644
index 81f3d2e63..000000000
--- a/perl-external/bin/build_all_modules.pl
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/env perl
-
-use strict;
-use warnings;
-
-use IPC::Run3;
-use LWP::Simple;
-use YAML;
-use File::Slurp;
-use Path::Class;
-
-my $root_dir = file(__FILE__)->dir->parent->absolute->stringify;
-my $module_list = "$root_dir/modules.txt";
-my $minicpan = "$root_dir/minicpan";
-my $local_lib = "$root_dir/../local-lib5";
-my $cpanm_cmd =
- "perl $root_dir/bin/cpanm --mirror $minicpan --mirror-only -l $local_lib";
-
-my @modules = map { s{\s+$}{}; $_; } read_file($module_list);
-
-foreach my $module (@modules) {
- print " --- installing $module ---\n";
-
- my $out = '';
- my $cmd = "$cpanm_cmd $module";
-
- print " running '$cmd'\n";
-
- run3( $cmd, undef, \$out, \$out )
- || die "Error running '$cmd'";
-
- my @lines =
- grep { m{\S} }
- split /\n+/, $out;
- my $last_line = $lines[-1];
-
- die "Error building '$module':\n\n$out\n\n"
- unless $last_line =~ m{Successfully installed }
- || $last_line =~ m{is up to date};
-}
diff --git a/perl-external/bin/cpanm b/perl-external/bin/cpanm
index 1c552fac2..1c552fac2 100644..100755
--- a/perl-external/bin/cpanm
+++ b/perl-external/bin/cpanm
diff --git a/perl-external/bin/module-manage.pl b/perl-external/bin/module-manage.pl
new file mode 100755
index 000000000..c6b741b32
--- /dev/null
+++ b/perl-external/bin/module-manage.pl
@@ -0,0 +1,142 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use IPC::Run3;
+use LWP::Simple;
+use File::Slurp;
+use Path::Class;
+use List::MoreUtils 'uniq';
+
+my $root_dir = file(__FILE__)->dir->parent->absolute->stringify;
+my $module_list = "$root_dir/modules.txt";
+my $url_list = "$root_dir/urls.txt";
+my $minicpan = "$root_dir/minicpan";
+
+my %actions = (
+ add => \&add,
+ build_all => \&build_all,
+ fetch_all => \&fetch_all,
+ index_minicpan => \&index_minicpan,
+ init => \&init,
+ setup => \&setup,
+ sort_files => \&sort_files,
+ zap => \&zap,
+);
+
+# work out what to run
+my ( $action, @args ) = @ARGV;
+$actions{$action}
+ ? $actions{$action}->(@args)
+ : die "Usage: $0 action [args ...]\n";
+
+exit;
+
+############################################################################
+
+sub init {
+ add('App::cpanminus');
+ add('MyCPAN::App::DPAN');
+ index_minicpan();
+}
+
+sub setup {
+ fetch_all();
+ init();
+ build_all();
+}
+
+sub add {
+ my $module = shift || die "Usage: $0 add Dist::To::Add";
+
+ # try to install the distribution using cpanm
+ my $out = '';
+ my $cmd = "cpanm --reinstall $module";
+ print " running '$cmd'\n";
+ run3( $cmd, undef, \$out, \$out )
+ || die "Error running '$cmd'";
+
+ my @fetched_urls =
+ map { s{.*(http://\S+).*}{$1}; $_ }
+ grep { m{^Fetching http://search.cpan.org} }
+ split /\n/, $out;
+
+ write_file( $module_list, { append => 1 }, "$module\n" );
+ write_file( $url_list, { append => 1 }, map { "$_\n" } @fetched_urls );
+ sort_files();
+
+ fetch_all();
+}
+
+sub index_minicpan {
+
+ # go to the minicpan dir and run dpan there
+ chdir $minicpan;
+ system "dpan -f ../dpan_config";
+}
+
+sub build_all {
+ my @modules = sort uniq read_file($module_list);
+ build($_) for @modules;
+}
+
+sub build {
+ my $module = shift #
+ || die "Usage: $0 build Module::To::Build\n";
+
+ print " --- installing $module ---\n";
+
+ my $out = '';
+ my $cmd = "cpanm --mirror $minicpan --mirror-only $module";
+
+ print " running '$cmd'\n";
+
+ run3( $cmd, undef, \$out, \$out )
+ || die "Error running '$cmd'";
+
+ my @lines =
+ grep { m{\S} }
+ split /\n+/, $out;
+ my $last_line = $lines[-1];
+
+ die "Error building '$module':\n\n$out\n\n"
+ unless $last_line =~ m{Successfully installed }
+ || $last_line =~ m{is up to date};
+}
+
+sub fetch_all {
+ my @urls = sort uniq read_file($url_list);
+ fetch($_) for @urls;
+}
+
+sub fetch {
+ my $url = shift;
+ my ($filename) = $url =~ m{/(authors/.+)$};
+
+ my $destination = file("$minicpan/$filename");
+ $destination->dir->mkpath;
+
+ return if -e $destination;
+
+ print " $url\n -> $destination\n";
+
+ is_success( getstore( $url, "$destination" ) )
+ || die "Error saving $url to $destination";
+}
+
+sub zap {
+
+ # delete all the bits that are generated
+ my $local_lib_root = $ENV{PERL_LOCAL_LIB_ROOT} || die;
+ dir($local_lib_root)->rmtree(1);
+ dir($minicpan)->subdir('authors')->rmtree(1);
+}
+
+sub sort_files {
+ foreach my $file ( $url_list, $module_list ) {
+ my @entries = read_file($file);
+ @entries = uniq sort @entries;
+ write_file( $file, @entries );
+ }
+}