#!perl

use strict;
use warnings;

use autodie;

use Git::CPAN::Patch::Import;
use Pod::Usage;
use Getopt::Long;
use File::Path;

sub say (@) { print @_, "\n" }

my %opt;
GetOptions( \%opt, 
    'help' => sub { pod2usage(1) },
    'man'  => sub { pod2usage( verbose => 2 ) },
    'mkdir:s', 
    'force!',
    'backpan=s',
) or pod2usage( "for a list of all valid options, do 'git backpan-init --help'" );

my $distribution = shift or pod2usage( 'distribution name required' );

Git::CPAN::Patch::Import::import_from_backpan(
    $distribution,
    \%opt
);
  

__END__

=pod

=head1 NAME

git-backpan-init - Initialize a repository for a CPAN module with full history
from the backpan.

=head1 SYNOPSIS

    git backpan-init [ --help | --man ] [ --mkdir <directory> ]
                     [ --force ] [ --backpan <url> ] Module::Name

=head1 DESCRIPTION

This command is like C<cpan-init> except it imports all the historical versions
of a module as well, allowing you to run C<git bisect> or to browse history.

The name of the module can be written with double-colons or dashes (i.e.,
I<Foo::Bar> or I<Foo-Bar>).

Unless the I<-force> option is used, the command will abort if a git repository
is found to be already present in the directory.

=head1 OPTIONS

=over

=item --mkdir I<directory>

Creates a sub-directory and create the git repository there instead 
than in the current directory.  If no directory name is given,
figures one out based on the name of the module.

=item --backpan I<url>

URL to BackPAN.  If none is given L<http://backpan.perl.org/> will be used.

=item --force, -f

Forces the imports, even if a git repository was
already present in the directory.

=item --help, -h

Prints the synopsis and valid options and exits.

=item --man

Prints the man page and exits.

=back

=head1 EXAMPLES

Most of the time, you want to use I<git backpan-init> like this:

    % cd ~/work/
    % git backpan-init --mkdir foo-bar Foo::Bar

=head1 BUGS AND LIMITATIONS

When importing a package history with git-backpan-init, version
checking will be automatically turned off.  This is to
circumvent the cases where, e.g., version 0.38.1 (morphed into 0.038001 by the 
module I<version>) follows version
0.38.  We are making the (hopefully reasonable) assumption that the
chronological order reported by the Backpan trumps all.

If a version of the package can't be extracted, I<git-backpan-init>
will issue a warning and skip to the next version.


Please report any bugs or feature requests to
C<bug-git-cpan-patch@rt.cpan.org>, or through the web 
interface at L<http://rt.cpan.org>.
  
=head1 AUTHORS

Yanick Champoux C<< <yanick@cpan.org> >>

Yuval Kogman C<< <nothingmuch@woobling.org> >>

=head1 LICENCE

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.

=head1 SEE ALSO

L<Git::CPAN::Patch>

=cut
