#!/usr/bin/perl

use Module::CheckDeps qw(alldeps checkdeps);

use Getopt::Long;

use warnings;
use strict;

=head1 NAME

checkdeps - Check for code dependencies

=head1 VERSION

version 0.08

=head1 SYNOPSIS

  checkdeps [OPTIONS] file.pl

  Options:
    --all    - show every dependencies (even if installed)
    --format - set output format (optional)

=cut

my ($format, $all) = "multiline";

my $getopt  = Getopt::Long::GetOptions(
	'all'       => \$all,
	'format=s'  => \$format
);

my $file = $ARGV[0];

die "Specify a valid file.\n" if !$file;

open SCRIPT, $file or die "$!\n";
my $code = join "", <SCRIPT>;
close SCRIPT;

my $missing = defined $all ? alldeps($code) : checkdeps($code);

foreach my $module(@$missing) {

	if ($format eq 'oneline') {

		print "$module ";

	} elsif ($format eq 'multiline') {

		print "$module\n";

	}
}

print "\n" if $format eq 'oneline';

=head1 OPTIONS

=over 4

=item B<--all>, B<-a>

Make C<checkdeps> list every dependencies of the code, even if already installed.

=item B<--format>, B<-f> FORMAT

Specifies the format of the output.
Must be:

=over 8

=item B<oneline>

Print every module in the same line.

=item B<multiline>

Print every module on a different line (default).

=back

=back

=head1 AUTHOR

Alessandro Ghedini <alexbio@cpan.org>

=head1 SEE ALSO

L<scandeps.pl>

=head1 LICENSE AND COPYRIGHT

Copyright 2010 Alessandro Ghedini.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

=cut