Analizo
view release on metacpan or search on metacpan
lib/Analizo/Command/metrics_batch.pm view on Meta::CPAN
package Analizo::Command::metrics_batch;
use Analizo -command;
use parent qw(Analizo::Command);
use strict;
use warnings;
use Analizo::Batch::Directories;
use Analizo::Batch::Output::CSV;
use File::Basename;
# ABSTRACT: processes several source code directories in batch
=head1 NAME
analizo-metrics-batch - processes several source code directories in batch
=head1 USAGE
analizo metrics-batch [OPTIONS] [<input> [<input> ...]]
=cut
sub usage_desc { "%c metrics-batch %o [<input> [<input> ...]]" }
sub command_names { qw/metrics-batch/ }
sub opt_spec {
return (
[ 'output|o=s', 'output file name', { default => 'metrics.csv' } ],
[ 'quiet|q', 'supresses messages to standard output' ],
[ 'parallel|p=i', 'activates support for parallel processing' ],
);
}
sub validate {
my ($self, $opt, $args) = @_;
if ($opt->output && ! -w dirname($opt->output)) {
$self->usage_error("Output is not writable!");
}
}
sub execute {
my ($self, $opt, $args) = @_;
my $runner = undef;
if ($opt->parallel) {
require Analizo::Batch::Runner::Parallel;
$runner = Analizo::Batch::Runner::Parallel->new($opt->parallel);
} else {
require Analizo::Batch::Runner::Sequential;
$runner = Analizo::Batch::Runner::Sequential->new;
}
unless ($opt->quiet) {
$runner->progress(
sub {
my ($job, $done, $total) = @_;
printf("I: Processed %s.\n", $job->id);
}
);
}
my $batch = Analizo::Batch::Directories->new(@$args);
my $output = Analizo::Batch::Output::CSV->new;
$output->file($opt->output);
$runner->run($batch, $output);
}
=head1 DESCRIPTION
Processes several source code directories in batch running B<analizo metrics>
for each and optionally consolidating the results in a single data file.
B<analizo metrics-batch> is useful when you want to analyze several projects at
once, or several different versions of the same project. You pass a list of
directories in the command line and each one will be analyzed as a separate
project. If no directories are passed in the command line, all of the
subdirectories of the current directory will be analized.
For example, suppose you want to process 5 consecutive releases of
I<myproject>, from version 0.1.0 to 0.5.0.
=over
=item
First you unpack the release tarballs for those versions in a directory, say
/tmp/analysis:
$ ls -1 /tmp/analysis
myproject-0.1.0
myproject-0.2.0
myproject-0.3.0
myproject-0.4.0
myproject-0.5.0
=item
( run in 1.694 second using v1.01-cache-2.11-cpan-99c4e6809bf )