in reply to Re^3: CPANPLUS broken custom sources
in thread CPANPLUS broken custom sources
Here is a script which automates the cpanp steps to update a custom source dir, which I find tedious and error prone. It assumes that there is a writeable directory (so it can do /cs --write /dir), which is also readable through URI file:///dir. Just Build your .tar.gz files, drop them in your custom source dir, and execute this script prior to running cpanp.
The script is a little unfinished in places (I didn't complete the part to read from ~/.xxx/config, and so $custom_src_dir is currently hardcoded).
One thing I think could be better is reload_indices takes a long time. If we could selectively reload the index on a single custom source, this would be very fast.
cpanp's scriptability is extremely well done. Great API.
#!/usr/bin/perl
use Getopt::Long;
use Pod::Usage;
use Data::Dumper;
use CPANPLUS::Backend;
sub main
{
my %options;
GetOptions
(\%options,
'help|?',
'man') or pod2usage (2);
pod2usage (1) if $options{help};
pod2usage (-exitstatus => 0, -verbose => 2)
if $options{man};
# TODO - get this from ~/.qws/devel_config custom_src_dir
# this assumes that we have a custom source that is a file:/// which is also a writeable directory.
my $custom_src_dir = "/Applications/MAMP/svn/deploy";
# TODO - make sure this is an absolute path
# Remove optional end / on $custom_src_dir
if ($custom_src_dir =~ /^(.+)\/$/)
{
$custom_src_dir = $1;
}
my $custom_src_uri = "file://$custom_src_dir";
my $cb = new CPANPLUS::Backend ();
my %files = $cb->list_custom_sources ();
my $found = 0;
while (my ($n, $v) = each %files)
{
# match on URI => file:///fn
if ($v =~ /^file:\/\/(.*)$/)
{
my $filename = $1;
$found = 1 if ($filename eq $custom_src_dir);
}
}
# If we don't have the source, add it.
if ( ! $found)
{
# $cb->add_custom_source ($custom_src_uri);
print STDERR "Added custom source '$custom_src_uri' to cpanp " .
"from your '~/.qws/devel_config' file.\n";
}
print STDERR "Writing custom source index\n";
my $file = $cb->write_custom_source_index (path => $custom_src_dir);
print STDERR "Updating custom source\n";
my $updated = $cb->update_custom_source (remote => $custom_src_uri);
print STDERR "Reloading indices\n";
my $reloaded = $cb->reload_indices ();
}
|
|---|