App-Critique

 view release on metacpan or  search on metacpan

lib/App/Critique/Command/collect.pm  view on Meta::CPAN

package App::Critique::Command::collect;

use strict;
use warnings;

our $VERSION   = '0.05';
our $AUTHORITY = 'cpan:STEVAN';

use Path::Tiny            ();
use Term::ANSIColor       ':constants';
use Parallel::ForkManager ();

use App::Critique::Session;

use App::Critique -command;

sub opt_spec {
    my ($class) = @_;
    return (
        [ 'root=s',        'directory to start traversal from (default is root of git work tree)' ],
        [],
        [ 'no-violation',  'filter files that contain no Perl::Critic violations ' ],
        [],
        [ 'filter|f=s',    'filter files to remove with this regular expression' ],
        [ 'match|m=s',     'match files to keep with this regular expression' ],
        [],
        [ 'n=i',           'number of concurrent processes across which to partition the filtering job', { default => 0 } ],
        [],
        [ 'dry-run',       'display list of files, but do not store them' ],
        [],
        $class->SUPER::opt_spec,
    );
}

our $PAUSE_PROCESSING = 0;

sub execute {
    my ($self, $opt, $args) = @_;

    local $Term::ANSIColor::AUTORESET = 1;

    my $session = $self->cautiously_load_session( $opt, $args );

    info('Session file loaded.');

    my $root = $opt->root
        ? Path::Tiny::path( $opt->root )
        : $session->git_work_tree;

    my $git_root       = $session->git_work_tree_root;
    my $file_predicate = generate_file_predicate(
        $session => (
            filter       => $opt->filter,
            match        => $opt->match,
            no_violation => $opt->no_violation
        )
    );

    my @all;
    eval {
        find_all_perl_files(
            root        => $git_root,
            path        => $root,
            accumulator => \@all,
        );
        my $unfiltered_count = scalar @all;
        info('Accumulated %d files, now processing', $unfiltered_count);

        filter_files(
            root      => $git_root,
            files     => \@all,
            filter    => $file_predicate,
            num_procs => $opt->n
        );
        my $filtered_count = scalar @all;
        info('Filtered %d files, left with %d', $unfiltered_count - $filtered_count, $filtered_count);

        1;
    } or do {
        my $e = $@;
        die $e;
    };

    my $num_files = scalar @all;
    info('Collected %d perl file(s) for critique.', $num_files);

    foreach my $file ( @all ) {
        info(
            ITALIC('Including %s'),
            Path::Tiny::path( $file )->relative( $git_root )
        );



( run in 2.116 seconds using v1.01-cache-2.11-cpan-364913b4093 )