| 1 | package Analizo::Command::metrics; | ||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use Analizo -command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use parent qw(Analizo::Command); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use Analizo::Metrics; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Analizo::Batch::Job::Directories; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # ABSTRACT: analizo's metric reporting tool | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | analizo-metrics - analizo's metric reporting tool | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 USAGE | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | analizo metrics [OPTIONS] [<input>] | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | sub usage_desc { "%c metrics %o [<input>]" } | ||||||||||||||||||||||||||
|
Subroutine
usage_desc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | sub opt_spec { | ||||||||||||||||||||||||||
|
Subroutine
opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 2 | my ($class, $app) = @_; | |||||||||||||||||||||||||||
| 26 | return ( | ||||||||||||||||||||||||||||
| 27 | 2 | [ 'list|l', 'displays metric list' ], | |||||||||||||||||||||||||||
| 28 | [ 'extractor=s', 'which extractor method use to parse the source code' ], | ||||||||||||||||||||||||||||
| 29 | [ 'globalonly|global-only|g', 'only output global (project-wide) metrics' ], | ||||||||||||||||||||||||||||
| 30 | [ 'output|o=s', 'output file name' ], | ||||||||||||||||||||||||||||
| 31 | [ 'language=s', 'process only filenames matching known extensions for the <lang>> programming' ], | ||||||||||||||||||||||||||||
| 32 | [ 'exclude|x=s', 'exclude <dirs> (a colon-separated list of directories) from the analysis' ], | ||||||||||||||||||||||||||||
| 33 | [ 'includedirs|I=s', 'include <dirs> (a colon-separated list of directories) with C/C++ header files', { default => '.' } ], | ||||||||||||||||||||||||||||
| 34 | [ 'libdirs|L=s', 'include <dirs> (a colon-separated list of directories) with C/C++ static and dynamic libraries files', { default => '.' } ], | ||||||||||||||||||||||||||||
| 35 | [ 'libs=s', 'include <dirs> (a colon-separated list of directories) with C/C++ linked libraries files', { default => '.' } ], | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub validate { | ||||||||||||||||||||||||||
|
Subroutine
validate: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 40 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | if (@$args > 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | $self->usage_error('No more than one <input> is suported'); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my @unreadable = grep { ! -r $_ || ! -e $_ } @$args; | ||||||||||||||||||||||||||
|
Condition0%0/3
-r $_ && -e $_
MC/DC0%0/2
-r $_ && -e $_
-r $_
-e $_
Truth table0%0/3
A && B
A= -r $_B= -e $_
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if (@unreadable) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | foreach my $file (@unreadable) { | |||||||||||||||||||||||||||
| 47 | 0 | $self->usage_error("Input '$file' is not readable"); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ($opt->output && ! -w dirname($opt->output)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opt->output and not -w dirname($opt->output)
MC/DC0%0/2
$opt->output and not -w dirname($opt->output)
$opt->output
not -w dirname($opt->output)
Truth table0%0/3
A and not(B)
A= $opt->outputB= not -w dirname($opt->output)
| |||||||||||||||||||||||||||||
| 51 | 0 | $self->usage_error("No such file or directory"); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | if($opt->list){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | my $metrics_handler = Analizo::Metrics->new(model => Analizo::Model->new); | |||||||||||||||||||||||||||
| 59 | 0 | my %metrics = $metrics_handler->list_of_metrics(); | |||||||||||||||||||||||||||
| 60 | 0 | my %global_metrics = $metrics_handler->list_of_global_metrics(); | |||||||||||||||||||||||||||
| 61 | 0 | print "Global Metrics:\n"; | |||||||||||||||||||||||||||
| 62 | 0 | foreach my $key (sort keys %global_metrics){ | |||||||||||||||||||||||||||
| 63 | 0 | print "$key - $global_metrics{$key}\n"; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | 0 | print "\nModule Metrics:\n"; | |||||||||||||||||||||||||||
| 66 | 0 | foreach my $key (sort keys %metrics){ | |||||||||||||||||||||||||||
| 67 | 0 | print "$key - $metrics{$key}\n"; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 0 | exit 0; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $tree = $args->[0] || '.'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args->[0] || '.'
MC/DC0%0/1
$args->[0] || '.'
$args->[0]
Truth table0%0/2
A
A= $args->[0]
| |||||||||||||||||||||||||||||
| 72 | 0 | my $job = Analizo::Batch::Job::Directories->new($tree); | |||||||||||||||||||||||||||
| 73 | 0 | $job->extractor($opt->extractor); | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($opt->language) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | require Analizo::LanguageFilter; | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($opt->language eq 'list') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | my @language_list = Analizo::LanguageFilter->list; | |||||||||||||||||||||||||||
| 78 | 0 | print "Languages:\n"; | |||||||||||||||||||||||||||
| 79 | 0 | $" = "\n"; | |||||||||||||||||||||||||||
| 80 | 0 | print "@language_list\n"; | |||||||||||||||||||||||||||
| 81 | 0 | exit 0; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 0 | my $language_filter = Analizo::LanguageFilter->new($opt->language); | |||||||||||||||||||||||||||
| 84 | 0 | $job->filters($language_filter); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ($opt->exclude) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | my @excluded_directories = split(':', $opt->exclude); | |||||||||||||||||||||||||||
| 88 | 0 | $job->exclude(@excluded_directories); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | $job->includedirs($opt->includedirs); | |||||||||||||||||||||||||||
| 91 | 0 | $job->libdirs($opt->libdirs); | |||||||||||||||||||||||||||
| 92 | 0 | $job->libs($opt->libs); | |||||||||||||||||||||||||||
| 93 | 0 | $job->execute(); | |||||||||||||||||||||||||||
| 94 | 0 | my $metrics = $job->metrics; | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($opt->output) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | open STDOUT, '>', $opt->output or die "$!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ($opt->globalonly) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | print $metrics->report_global_metrics_only; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | else { | ||||||||||||||||||||||||||||
| 102 | 0 | print $metrics->report; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | 0 | close STDOUT; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | analizo metrics analyzes source code in I<input> and produces a metrics | ||||||||||||||||||||||||||||
| 110 | report. If I<input> is omitted, the current directory (I<.>) is assumed. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | The produced report is written to the standard output, or to a file using the | ||||||||||||||||||||||||||||
| 113 | I<--output> option, using the YAML format (see I<http://www.yaml.org/>) | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | analizo metrics is part of the analizo suite. | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =head1 OPTIONS | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =over | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =item <input> | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | Tells analizo which source code directory you want to parse. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =item --extractor <extractor> | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | Define which extractor method use to parse the source code. Default is Doxyparse. | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | When using the Doxyparse extractor (default), all files matching the languages | ||||||||||||||||||||||||||||
| 130 | supported by doxyparse are processed, unless I<--language> is used. | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =item --list, -l | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | Displays metric list. | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | =item --output <file>, -o <file> | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | Writes the output to <file> instead of standard output. | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =item --globalonly, --global-only, -g | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | Don't output the details about modules: only output global (project-wide) metrics. | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =item --language <lang> | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | Process only filenames matching known extensions for the <I<lang>> programming | ||||||||||||||||||||||||||||
| 147 | language. To see which languages are supported, pass B<--language list>. | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =item --exclude <dirs>, -x <dirs> | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | Exclude <I<dirs>> (a colon-separated list of directories) from the analysis. | ||||||||||||||||||||||||||||
| 152 | This is useful, for example, when you want to focus on production code and | ||||||||||||||||||||||||||||
| 153 | exclude test code from the analysis. You could do that by passing something | ||||||||||||||||||||||||||||
| 154 | like pass B<--exclude test>. | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | =back | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =head1 OUTPUT FORMAT | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | The output is a stream of YAML documents. The first one presents metrics for | ||||||||||||||||||||||||||||
| 161 | the project as a whole. The subsequent ones present per-module metrics, and thus | ||||||||||||||||||||||||||||
| 162 | there will be as many of them as there are modules in your project. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | =head1 COPYRIGHT AND AUTHORS | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | See B<analizo(1)>. | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =cut | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 9 | 1; | |||||||||||||||||||||||||||