App-CPANTS-Lint
view release on metacpan or search on metacpan
lib/App/CPANTS/Lint.pm view on Meta::CPAN
? {pass => 'o', fail => 'x'}
: {pass => "\x{2713}", fail => "\x{2717}"};
my $report = Term::ANSIColor::colored("Distribution: ", "bold $scheme->{heading}")
. Term::ANSIColor::colored($self->result->{dist}, "bold $scheme->{title}")
. "\n";
my %failed;
for my $arr (values %{$self->result->{fails}}) {
for my $fail (@$arr) {
$failed{$fail->{name}} = $fail;
}
}
my $core_fails = 0;
for my $type (qw/ Core Optional Experimental /) {
$report .= Term::ANSIColor::colored("\n$type\n", "bold $scheme->{heading}");
my @inds = $self->{mca}->mck->get_indicators(lc $type);
my @fails;
for my $ind (@inds) {
if ($failed{ $ind->{name} }) {
push @fails, $ind;
$core_fails++ if $type eq 'Core';
$report .= Term::ANSIColor::colored(" $icon->{fail} ", $scheme->{fail}) . $ind->{name};
$report .= ": " . Term::ANSIColor::colored($failed{ $ind->{name} }{error}, $scheme->{error})
if $failed{ $ind->{name} }{error};
} else {
$report .= Term::ANSIColor::colored(" $icon->{pass} ", $scheme->{pass}) . $ind->{name};
}
$report .= "\n";
}
for my $fail (@fails) {
$report .= "\n"
. Term::ANSIColor::colored("Name: ", "bold $scheme->{summary}")
. Term::ANSIColor::colored("$fail->{name}\n", $scheme->{summary})
. Term::ANSIColor::colored("Remedy: ", "bold $scheme->{summary}")
. Term::ANSIColor::colored("$fail->{remedy}\n", $scheme->{summary});
}
}
my $scorecolour = $scheme->{pass};
$scorecolour = $scheme->{warn} if keys %failed;
$scorecolour = $scheme->{fail} if $core_fails;
$report .= "\n"
. Term::ANSIColor::colored("Score: ", "bold $scheme->{heading}")
. Term::ANSIColor::colored($self->result->{score}, "bold $scorecolour")
. "\n";
$report;
}
sub output_report {
my $self = shift;
if ($self->{opts}{save}) {
my $file = $self->report_file;
open my $fh, '>:utf8', $file or croak "Cannot write to $file: $!";
print $fh $self->report;
} else {
binmode(STDOUT, ':utf8');
print $self->report;
}
}
sub report_file {
my $self = shift;
my $dir = $self->{opts}{dir} || '.';
my $vname = $self->{mca}->d->{vname};
if (!$vname) {
require File::Basename;
$vname = File::Basename::basename($self->{res}{dist});
}
my $extension =
$self->{opts}{yaml} ? '.yml' :
$self->{opts}{json} ? '.json' :
$self->{opts}{dump} ? '.dmp' :
'.txt';
require File::Spec;
File::Spec->catfile($dir, "$vname$extension");
}
1;
__END__
=encoding utf-8
=head1 NAME
App::CPANTS::Lint - front-end to Module::CPANTS::Analyse
=head1 SYNOPSIS
use App::CPANTS::Lint;
my $app = App::CPANTS::Lint->new(verbose => 1);
$app->lint('path/to/Foo-Dist-1.42.tgz') or print $app->report;
# if you need raw data
$app->lint('path/to/Foo-Dist-1.42.tgz') or return $app->result;
# if you need to look at the details of analysis
$app->lint('path/to/Foo-Dist-1.42.tgz');
print Data::Dumper::Dumper($app->stash);
=head1 DESCRIPTION
L<App::CPANTS::Lint> is a core of C<cpants_lint.pl> script to check the Kwalitee of a distribution. See the script for casual usage. You can also use this from other modules for finer control.
=head1 METHODS
=head2 new
Takes an optional hash (which will be passed into L<Module::CPANTS::Analyse> internally) and creates a linter object.
Available options are:
=over 4
( run in 0.818 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )