p5-p5u / lib / P5U / Command / Reprove.pm

package P5U::Command::Reprove;

use 5.010;
use strict;
use utf8;
use P5U-command;

use PerlX::Maybe 0 'maybe';

BEGIN {
	$P5U::Command::Reprove::AUTHORITY = 'cpan:TOBYINK';
	$P5U::Command::Reprove::VERSION   = '0.007';
};

use constant {
	abstract    => q[download a distribution test suite and run it],
	usage_desc  => q[%c reprove %o],
};

sub command_names
{
	qw(
		reprove
		rp
	);
}

sub description
{
<<'DESCRIPTION'
This command downloads a distribution's test suite from CPAN, and runs it
locally.

This command can be called using two different conventions; named arguments:

	p5u reprove --release=JSON --version=2.53

Or positional arguments:

	p5u reprove JSON 2.53

The first argument is the distribution name or module name; the second 
argument is the version; and the third argument is the CPAN ID of the
author. The presence of "::" is used to disambiguate between distribution
and module names; in the case of something like "JSON" which is ambiguous,
use a trailing "::" to force it to be interpreted as a module name.

When given a distribution name, the version is required. When given a
module name, the version can usually be automatically detected. The author
can usually be automatically detected.
DESCRIPTION
}

sub opt_spec
{
	return (
		["author|a=s",   "author of distribution to test"],
		["version=s",    "version to test"],
		["module|m=s",   "identify distribution via a module it provides"],
		["release|r=s",  "name of distribution to test"],
		["verbose|v",    "verbose output"],
	)
}

sub execute
{
	require P5U::Lib::Reprove;
	
	my ($self, $opt, $args) = @_;

	foreach my $a (qw< release version author >)
	{
		my $val = shift @$args;
		defined $val or last;
		$self->usage_error("Do not provide $a as a named and ordinal argument.")
			if defined $opt->{$a};
		
		if ($a eq 'release' and $val =~ /::/)
		{
			$val =~ s{::$}{};
			$opt->{module} = $val;
			next;
		}
		
		$opt->{$a} = $val;
	}
	
	$self->usage_error("You must provide a distribution or module name.")
		unless $opt->{release} || $opt->{module};
		
	P5U::Lib::Reprove::
		-> new(
			maybe author      => $opt->{author},
			maybe module      => $opt->{module},
			maybe release     => $opt->{release},
			maybe version     => $opt->{version},
			maybe verbose     => $opt->{verbose},
			      working_dir => $self->get_tempdir,
		)
		-> run;
}

1;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.