« Analizo/Metric/MaximumMethodLinesOfCode.pm
↑ Summary
Analizo/Metric/AverageNumberOfParameters.pm »
| 1 | package Analizo::Metric::AverageMethodLinesOfCode; | ||||||||||||
| 2 | 21 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 21 | ▶ | use parent qw(Class::Accessor::Fast Analizo::ModuleMetric); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 21 | ▶ | use Statistics::Descriptive; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 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 | 21 | __PACKAGE__->mk_accessors(qw( model )); | |||||||||||
| 27 | |||||||||||||
| 28 | 15 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 29 | 15 | my ($package, %args) = @_; | |||||||||||
| 30 | my @instance_variables = ( | ||||||||||||
| 31 | model => $args{model} | ||||||||||||
| 32 | 15 | ); | |||||||||||
| 33 | 15 | return bless { @instance_variables }, $package; | |||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | 4 | ▶ | sub description { | ||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 37 | 4 | return "Average Method Lines of Code"; | |||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | 10 | ▶ | sub calculate { | ||||||||||
|
Subroutine
calculate: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||
| 41 | 10 | my ($self, $module) = @_; | |||||||||||
| 42 | |||||||||||||
| 43 | 10 | my @functions = $self->model->functions($module); | |||||||||||
| 44 | 10 | ▶ | if (scalar(@functions) == 0) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | 1 | return 0; | |||||||||||
| 46 | } | ||||||||||||
| 47 | |||||||||||||
| 48 | 9 | my $statisticalCalculator = Statistics::Descriptive::Full->new(); | |||||||||||
| 49 | 9 | for my $function (@functions) { | |||||||||||
| 50 | 14 | ▶ | $statisticalCalculator->add_data($self->model->{lines}->{$function} || 0); | ||||||||||
|
Condition100%2/2
$self->model->{'lines'}{$function} || 0
MC/DC100%1/1
$self->model->{'lines'}{$function} || 0
$self->model->{'lines'}{$function}
Truth table100%2/2
A
A= $self->model->{'lines'}{$function}
| |||||||||||||
| 51 | } | ||||||||||||
| 52 | 9 | return $statisticalCalculator->mean(); | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | 21 | 1; | |||||||||||
| 56 | |||||||||||||