Analizo/Metrics.pm

filter: Statementstmt 98.1% 54 / 55 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 16 / 16 Podpod 12.5% 1 / 8 totaltotal 88.8% 72 / 81 CC 3 SCAR 3.0
CC
3
Cov
96%
_collect_and_combine_module_metrics
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« Analizo/Batch/Runner/Sequential.pm ↑ Summary Analizo/Batch/Runner.pm »
1 package Analizo::Metrics;
2 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 19 ▶use parent qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use YAML::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 ▶use Analizo::ModuleMetrics;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use Analizo::GlobalMetrics;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Analizo::Metrics - reporting project-level and module-level metrics
12  
13 =head1 DESCRIPTION
14  
15 Analizo reports both project-level metrics, which are calculated for the entire
16 project, and module-level metrics, which are calculated individually for each
17 module. On the project-level, Analizo also provides basic descriptive
18 statistics for each of the module-level metrics: sum, mean, median, mode,
19 standard deviation, variance, skewness and kurtosis of the distribution,
20 minimum, and maximum value.
21  
22 =head2 Null values
23  
24 As a project decision, Analizo consider metrics with 0 (zero) value as the same
25 meaning of "null value", in other words, 0 (zero) has no meaning in the
26 context of Analizo metrics calculation, both to project-level metrics as to
27 module-level metrics. You can see a discussion on the
28 L<issue #60|https://github.com/analizo/analizo/issues/60>
29 about this decision.
30  
31 =cut
32  
33 19 __PACKAGE__->mk_accessors(qw(
34 model
35 module_metrics
36 global_metrics
37 module_data
38 by_module
39 ));
40  
41 8 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
42 8 my ($package, %args) = @_;
43 my @instance_variables = (
44 model => $args{model},
45 global_metrics => Analizo::GlobalMetrics->new(model => $args{model}),
46 8 module_metrics => Analizo::ModuleMetrics->new(model => $args{model}),
47 module_data => [],
48 by_module => {},
49 );
50 8 return bless { @instance_variables }, $package;
51 }
52  
53 1 ▶sub list_of_global_metrics {
Subroutine list_of_global_metrics: called CC=1 SCAR=0.0
Pod undocumented
54 1 my ($self) = @_;
55 1 return $self->global_metrics->list;
56 }
57  
58 2 ▶sub list_of_metrics {
Subroutine list_of_metrics: called CC=1 SCAR=0.0
Pod undocumented
59 2 my ($self) = @_;
60 2 return $self->module_metrics->list;
61 }
62  
63 2 ▶sub report {
Subroutine report: called CC=1 SCAR=0.0
Pod undocumented
64 2 my ($self) = @_;
65 2 return $self->report_global_metrics_only() . $self->report_module_metrics();
66 }
67  
68 3 ▶sub report_global_metrics_only {
Subroutine report_global_metrics_only: called CC=1 SCAR=0.0
Pod undocumented
69 3 my ($self) = @_;
70 3 my ($global_metrics, $module_metrics) = $self->data();
71 3 return Dump($global_metrics);
72 }
73  
74 2 ▶sub report_module_metrics {
Subroutine report_module_metrics: called CC=1 SCAR=0.0
Pod undocumented
75 2 my ($self) = @_;
76 2 return join('', map { Dump($_) } @{$self->module_data()});
77 }
78  
79 4 ▶sub data {
Subroutine data: called CC=1 SCAR=0.0
Pod undocumented
80 4 my ($self) = @_;
81 4 $self->_collect_and_combine_module_metrics;
82 4 return ($self->global_metrics->report, $self->module_data());
83 }
84  
85 4 ▶sub _collect_and_combine_module_metrics {
Subroutine _collect_and_combine_module_metrics: called CC=3 SCAR=11.3
86 4 my ($self) = @_;
87 4 ▶ if (defined $self->{_collect_and_combine_module_metrics}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"_collect_and_combine_module_metrics"}) 0 4 4
88 0 return;
89 }
90  
91 4 for my $module ($self->model->module_names) {
92 6 my $module_metrics = $self->_collect($module);
93 6 $self->_combine($module_metrics);
94 }
95  
96 4 $self->{_collect_and_combine_module_metrics} = 1;
97 }
98  
99 6 ▶sub _collect {
Subroutine _collect: called CC=1 SCAR=0.0
100 6 my ($self, $module) = @_;
101 6 return $self->module_metrics->report($module);
102 }
103  
104 6 ▶sub _combine {
Subroutine _combine: called CC=1 SCAR=0.0
105 6 my ($self, $module_metrics) = @_;
106 6 my $module = $module_metrics->{_module};
107  
108 6 $module_metrics->{_filename} = $self->model->files($module);
109 6 push(@{$self->module_data()}, $module_metrics);
110 6 $self->{by_module}->{$module} = $module_metrics;
111  
112  
113 6 $self->global_metrics->add_module_values($module_metrics);
114 }
115  
116 1 ▶sub metrics_for {
Subroutine metrics_for: called CC=1 SCAR=0.0
Pod undocumented
117 1 my ($self, $module) = @_;
118 1 $self->data(); # FIXME shouldn't be needed
119 1 return $self->{by_module}->{$module};
120 }
121  
122 19 1;
« Analizo/Batch/Runner/Sequential.pm ↑ Summary Analizo/Batch/Runner.pm »