CPANPLUS with Local CPAN

In followup to the not about how to create a local cpan repository, I figured out how to get cpanplus to use this respository. Not nearly as simple as with cpan, but once it is setup, it is a breeze. The following script does all the work.

#!/usr/bin/env perl

use strict;
use warnings;

my $local = {
                path   => '/home/mgrimes/CPAN',
                scheme => 'file',
                host   => '',
            };

use vars '$VERSION';

use CPANPLUS;
use CPANPLUS::Shell qw[Default];
use CPANPLUS::Backend;

$VERSION = CPANPLUS->VERSION;

# my $cb = new CPANPLUS::Backend;
my $shell = CPANPLUS::Shell->new;
my $conf = $shell->backend->configure_object;

my $hosts = [ $local ];
$conf->set_conf('hosts' => $hosts);

### if we're given a command, run it; otherwise, open a shell.
if (@ARGV) {
    ### take the command line arguments as a command
    my $input = "@ARGV";
    ### if they said "--help", fix it up to work.
    $input = 'h' if $input =~ /^\s*--?h(?:elp)?\s*$/i;
    ### strip the leading dash
    $input =~ s/^\s*-//;
    ### pass the command line to the shell
    $shell->dispatch_on_input(input => $input, noninteractive => 1);
} else {
    ### open a shell for the user
    $shell->shell();
}

Published

June 28, 2007 8:26AM

Tags

License

The contents of this blog are licensed under the Creative Commons “Attribution-Noncommercial-Share Alike 3.0″ license.