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 ();
}

In reply to Re^4: CPANPLUS broken custom sources by zerohero
in thread CPANPLUS broken custom sources by zerohero

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.