#!perl

# PODNAME: pause-check-distro-perms

use strictures 2;
use PAUSE::Packages;
use Test::PAUSE::ConsistentPermissions::Check;

my $dist = shift;
my $module = shift;

my $verbose = 1;
my $quiet = 0;

# FIXME: use proper command line parsing.
# then we can have verbose/quiet etc.
# need pod.

unless($dist && $module)
{
    print STDERR "Usage $0 dist-name module::name\n";
    print STDERR "\n";
    print STDERR "This checks the permissions are consistent for dist-name\n";
    print STDERR "Using module::name as the module with the correct set of permissions\n";
    print STDERR "Note this downloads a couple of large files from cpan so it may be slow.\n";
    exit(1);
}

my $pp = PAUSE::Packages->new;
my $perms_test = Test::PAUSE::ConsistentPermissions::Check->new;

my $release_info = $pp->release($dist);
unless($release_info)
{
    print "Unable to find distro $dist\n";
    exit(2);
}
my @modules = map { $_->name } @{$release_info->modules};
my $report = $perms_test->report_problems(\@modules, $module);

my $problems = @{$report->{problems}};
if(!$quiet && ($verbose || $problems))
{
    # display module info.
    print "Distribution: $dist\n";
    $perms_test->module_info_to_fh($report, \*STDOUT);
}

if($problems && !$quiet)
{
    $perms_test->problems_to_fh($report, \*STDOUT);
}

exit($problems > 0);

__END__

=pod

=encoding UTF-8

=head1 NAME

pause-check-distro-perms

=head1 VERSION

version 0.002

=head1 AUTHOR

Colin Newell <colin.newell@gmail.com>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2016 by Colin Newell.

This is free software, licensed under:

  The MIT (X11) License

=cut
