#!/usr/bin/perl -w
use strict;
use warnings;

=head1 NAME

minicpan - uses CPAN::Mini to create or update a local mirror

=head1 SYNOPSIS

 user@host$ minicpan

=head1 DESCRIPTION

This simple shell script just updates (or creates) a miniature CPAN mirror as
described in CPAN::Mini.  See also the original article here: 

 http://www.stonehenge.com/merlyn/LinuxMag/col42.html

The local and remote mirror locations are (for now) hardcoded and should be
updated before running this script for the first time.

=cut

use CPAN::Mini;
use Getopt::Long qw(GetOptions);

sub usage {
	print <<END;
usage: minicpan [options]
  -l LOCAL       - where is the local minicpan?
  -r REMOTE      - where is the remote cpan mirror?
  -q             - run in quiet mode (don't print status)
  -f             - unless given, exit if indices are unchanged
END
}

GetOptions(
           "l|local=s"  => \ (my $local  = ''),
           "r|remote=s" => \ (my $remote = ''),
           "q+" => \ (my $quiet = 0),
           "f+" => \ (my $force = 0),
#           "<>" => sub { $Getopt::Long::error = $Getopt::Long::error + 1;
#                         warn "Unknown arg: $_[0]\n";
#                       },
          ) or usage() and exit;

usage() and exit
	unless $local and $remote;

$|++;

CPAN::Mini->update_mirror(
	remote => $remote,
	local  => $local,
	trace  => (not $quiet),
	force  => $force
);

=head1 TO DO

Add a configuration file.

Improve command-line options...

...including usage instructions.

=head1 AUTHORS

Randal Schwartz <F<merlyn@stonehenge.com>> did all the work.  His original
article can be found here:

	http://www.stonehenge.com/merlyn/LinuxMag/col42.html

Ricardo SIGNES <F<rjbs@cpan.org>> made a module and distribution.

This code was copyrighted in 2004, and is released under the same terms as Perl
itself.

=cut
