#!/usr/bin/perl

use strict;
# use warnings;
use Getopt::Long qw(:config no_ignore_case);
use PPM::Make;
my %opts = ();
my @files = ();
my %progs = ();
my $result = GetOptions(\%opts, 
			'version|v',
			'help|h',
			'ignore|i',
			'remove|r',
		       );
if ($opts{v}) {
  print <<"END";

This is ppm_install, running PPM::Make version $PPM::Make::VERSION.

Copyright 2002, Randy Kobes <randy\@theoryx5.uwinnipeg.ca>.
This program is distributed under the same terms as Perl itself.

END
  exit;
}


if ($opts{h} or not $result) {
  print <<"END";

Usage: $0 [options] [Module | Distribution]

Options:
 [-v | --version]          : print version information and exit
 [-h | --help]             : print this help screen
 [-r | --remove]           : remove the build directory after installation
 [-i | --ignore]           : ignore any failing test results

Additional Arguments:
   Module       : specify a module to fetch (requires CPAN.pm)
   Distribution : specify a distribution to fetch

With no arguments, ppm_install will install a distribution
inside the current directory. See 'perldoc ppm_install'.

END
  exit;
}

my $dist = shift;
$opts{dist} = $dist if $dist;

my $ppm = PPM::Make->new(%opts, install => 1);
$ppm->make_ppm();

__END__

=head1 NAME

ppm_install - script to build and install a distribution via ppm

=head1 SYNOPSIS

   ppm_install [options] [Module | Distribution]

   # install from within an already unpacked source distribution
   C:\.cpan\build\package_src> ppm_install

   # fetch from CPAN a module distribution and build a PPM
   C:\.cpan\build> ppm_install Net::FTP

   # fetch a distribution and build a PPM
   C:\.cpan\build> ppm_install ftp://wherever.com/package.tar.gz

=head1 DESCRIPTION

C<ppm_install> is an interface to the C<PPM::Make> module,
and is used to build a PPM (Perl Package Manager) distribution
from a CPAN source distribution and then install it with 
the C<ppm> utility. See L<PPM::Make> for a discussion.

Apart from the options described below, without any arguments 
C<ppm_install> will assume it is inside an unpacked source
distribution and make the corresponding PPM distribution.
If it is given an argument of what looks like a module
name (eg, I<Net::FTP>), it will use C<CPAN.pm> to look up the 
corresponding distribution and fetch and build it. Otherwise, 
additional arguments (eg, F<package.tar.gz>, or
I<http://someplace.org/package.tar.gz>) will be interpreted
as distributions to fetch and build.

=over

=item [-i | --ignore]

By default, C<ppm_install>, if it is building the distribution,
will die if all tests do not pass. Turning on this option
instructs C<ppm_install> to ignore any test failures.

=item [-r | --remove]

If specified, the directory used to build the ppm distribution
given on the command line will be removed after a successful install.

=item [-h | --help]

This prints out a short help screen and exits.

=item [-v | --version]

This prints out some version information and exits.

=back

=head1 COPYRIGHT

This program is copyright, 2003, by Randy Kobes <randy@theoryx5.uwinnipeg.ca>.
It is distributed under the same terms as Perl itself.

=head1 SEE ALSO

L<PPM::Make>, and L<PPM>.

=cut
