#!perl

# ABSTRACT: Report packages required by a distribution
# PODNAME: dist-requires

use strict;
use warnings;

use Pod::Usage;
use Getopt::Long;
use Dist::Requires;

#------------------------------------------------------------------------------

our $VERSION = '0.003'; # VERSION

#------------------------------------------------------------------------------

GetOptions(\my %opts, qw(perl=s all help|?)) || pod2usage();
pod2usage(-verbose => 1) if $opts{help};
my $dist = shift || pod2usage();
pod2usage() if @ARGV;


my %filter_attr = $opts{all} ? (filter => {}) : ();
my %perl_attr = $opts{perl} ? (target_perl_version => $opts{perl}) : ();
my $dr = Dist::Requires->new(%perl_attr, %filter_attr);
my %requires = $dr->requires(dist => $dist);
my $longest = ( sort {$b <=> $a} map {length} keys %requires )[0];
printf "%-${longest}s => %s\n", $_, $requires{$_} for sort keys %requires;
exit;

#------------------------------------------------------------------------------



__END__
=pod

=for :stopwords Jeffrey Ryan Thalhammer Imaginative Software Systems

=head1 NAME

dist-requires - Report packages required by a distribution

=head1 VERSION

version 0.003

=head1 SYNOPSIS

   dist-requires [-perl VERSION] [-all] { DIST_ARCHIVE_FILE | DIST_DIRECTORY }
   dist-requires -help

=head1 DESCRIPTION

L<dist-requires> will tell you which versions of which packages are
required to build/test/run a distribution with a given version of
perl.  By default, all packages that were provided in that version
of perl will be excluded from the output, unless the distribution
requires a version newer than the one provided by that perl.

=head1 ARGUMENTS

The only argument is the path to a distribution archive file
(e.g. F<*.tar.gz> file) or the path to a directory containing an
unpacked distribution.

=head1 OPTIONS

=head2 -perl PERL_VERSION

Specifies which version of perl to consider when evaluating which
packages would be necessary.  Version numbers can be represented
as floating point numbers, or 'version strings'.  So the following
are all equivalent:

  v5.12.3
  5.12.3
  5.012003

=head2 -all

List all required packages, not just those that are not provided in
the perl core.  Setting the C<-all> switch effectively makes the
C<-perl> option meaningless.

=head2 -help

Display usage information.

=head1 AUTHOR

Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Imaginative Software Systems.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

