| 1 |
package Analizo::Metric::AverageMethodLinesOfCode; |
| 2 |
use strict; |
| 3 |
use parent qw(Class::Accessor::Fast Analizo::ModuleMetric); |
| 4 |
use Statistics::Descriptive; |
| 5 |
|
| 6 |
=head1 NAME |
| 7 |
|
| 8 |
Analizo::Metric::AverageMethodLinesOfCode - Average Method Lines of Code (AMLOC) metric |
| 9 |
|
| 10 |
=head1 DESCRIPTION |
| 11 |
|
| 12 |
The metric calculation is based on the following article and calculates the |
| 13 |
average number of lines of code per method. |
| 14 |
|
| 15 |
Article: I<Monitoring of source code metrics in open source projects> by Paulo |
| 16 |
Roberto Miranda Meirelles. |
| 17 |
|
| 18 |
See the adaptation of the paragraph about Average Method Lines of Code metric: |
| 19 |
|
| 20 |
This metric indicates if the code is well distributed between the methods. How |
| 21 |
bigger, "heavier" are the methods. It's preferable to have a lot of small and |
| 22 |
of easy understanding operations than few large and complex operations. |
| 23 |
|
| 24 |
=cut |
| 25 |
|
| 26 |
__PACKAGE__->mk_accessors(qw( model )); |
| 27 |
|
| 28 |
sub new { |
| 29 |
my ($package, %args) = @_; |
| 30 |
my @instance_variables = ( |
| 31 |
model => $args{model} |
| 32 |
); |
| 33 |
return bless { @instance_variables }, $package; |
| 34 |
} |
| 35 |
|
| 36 |
sub description { |
| 37 |
return "Average Method Lines of Code"; |
| 38 |
} |
| 39 |
|
| 40 |
sub calculate { |
| 41 |
my ($self, $module) = @_; |
| 42 |
|
| 43 |
my @functions = $self->model->functions($module); |
| 44 |
if (scalar(@functions) == 0) { |
| 45 |
return 0; |
| 46 |
} |
| 47 |
|
| 48 |
my $statisticalCalculator = Statistics::Descriptive::Full->new(); |
| 49 |
for my $function (@functions) { |
| 50 |
$statisticalCalculator->add_data($self->model->{lines}->{$function} || 0); |
| 51 |
} |
| 52 |
return $statisticalCalculator->mean(); |
| 53 |
} |
| 54 |
|
| 55 |
1; |
| 56 |
|