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

use Getopt::Long qw/GetOptions/;
use PAR::Dist::FromCPAN;

=pod

=head1 NAME

cpan2par - Create PAR distributions from CPAN

=head1 SYNOPSIS

cpan2par --help

cpan2par [-v -f -t -o DIR] -p MODULEPATTERN

=head1 DESCRIPTION

This script creates PAR distributions from any number of modules
from CPAN. The only mandatory parameter is a pattern matching the
modules you wish to create PAR distributions from. This works the
same way as, for example C<cpan install MODULEPATTERN>.

=head2 Parameters

  -v --verbose
    Sets the verbose mode.
  -o --out
    Sets the output directory. (default: .)
  -f --follow
    Follow dependencies and recusrively generate PAR distributions.
  -t --test
    Indicates whether the modules' tests will be run before the PAR
    distribution is created.

=head1 SEE ALSO

This tool is implemented using the L<PAR::Dist::FromCPAN> module. Please
refer to that module's documentation for details on how this all works.

PAR has a mailing list, <par@perl.org>, that you can write to; send
an empty mail to <par-subscribe@perl.org> to join the list and
participate in the discussion.

Please send bug reports to <bug-par-dist-fromcpan@rt.cpan.org>.

The official PAR website may be of help, too: http://par.perl.org

=head1 AUTHOR

Steffen Mueller, E<lt>smueller at cpan dot orgE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2006 by Steffen Mueller

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.6 or,
at your option, any later version of Perl 5 you may have available.

=cut

my $usage = <<"HERE";
$0 --help          # for help

$0 [-v -f -t -o DIR] -p MODULEPATTERN

This script creates PAR distributions from any number of modules
from CPAN. The only mandatory parameter is a pattern matching the
modules you wish to create PAR distributions from. This works the
same way as, for example "cpan install MODULEPATTERN".

-v --verbose
  Sets the verbose mode.
-o --out
  Sets the output directory. (default: .)
-f --follow
  Follow dependencies and recusrively generate PAR distributions.
-t --test
  Indicates whether the modules' tests will be run before the PAR
  distribution is created.
HERE

my $pattern;
my $outdir = '.';
my $follow = 0;
my $run_tests = 0;
my $v = 0;
GetOptions(
	'h|help' => sub { print $usage; exit(1) },
	'o|out=s' => \$outdir,
	'p|pattern=s' => \$pattern,
	'f|follow' => \$follow,
	'v|verbose' => \$v,
	't|test' => \$run_tests,
);

cpan_to_par(
	pattern => $pattern,
	($follow       ? (follow  => 1   ) : ()),
	($verbose      ? (verbose => 1   ) : ()),
	($test         ? (test    => 1   ) : ()),
	(defined($out) ? (out     => $out) : ()),
);

