| 1 | package Analizo::Metric::LinesOfCode; | ||||||||||||
| 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::LinesOfCode - Lines of Code (LOC) metric | ||||||||||||
| 9 | |||||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||||
| 11 | |||||||||||||
| 12 | The metric calculation is based on the following article and calculates the | ||||||||||||
| 13 | program size in lines of code, excluding blank lines and comments. | ||||||||||||
| 14 | |||||||||||||
| 15 | Article: I<The Lines of Code Metric as a Predictor of Program Faults: A | ||||||||||||
| 16 | Critical Analysis> by Taghi M. Khoshgoftaar and John C. Munson. | ||||||||||||
| 17 | |||||||||||||
| 18 | See the paragraph about Lines of Code in the article: | ||||||||||||
| 19 | |||||||||||||
| 20 | A description of the specific quantitative complexity data collected for | ||||||||||||
| 21 | each program is as follows: | ||||||||||||
| 22 | |||||||||||||
| 23 | ... program size in lines of code (non-comment, non-blank lines) in program | ||||||||||||
| 24 | (LOC). | ||||||||||||
| 25 | |||||||||||||
| 26 | =cut | ||||||||||||
| 27 | |||||||||||||
| 28 | 21 | __PACKAGE__->mk_accessors(qw( model )); | |||||||||||
| 29 | |||||||||||||
| 30 | 15 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 31 | 15 | my ($package, %args) = @_; | |||||||||||
| 32 | my @instance_variables = ( | ||||||||||||
| 33 | model => $args{model} | ||||||||||||
| 34 | 15 | ); | |||||||||||
| 35 | 15 | return bless { @instance_variables }, $package; | |||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | 4 | ▶ | sub description { | ||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 39 | 4 | return "Lines of Code"; | |||||||||||
| 40 | } | ||||||||||||
| 41 | |||||||||||||
| 42 | 10 | ▶ | sub calculate { | ||||||||||
|
Subroutine
calculate: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||
| 43 | 10 | my ($self, $module) = @_; | |||||||||||
| 44 | |||||||||||||
| 45 | 10 | my @functions = $self->model->functions($module); | |||||||||||
| 46 | 10 | ▶ | if (scalar(@functions) == 0) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | 1 | return 0; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | 9 | my $statisticalCalculator = Statistics::Descriptive::Full->new(); | |||||||||||
| 51 | |||||||||||||
| 52 | 9 | for my $function (@functions) { | |||||||||||
| 53 | 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}
| |||||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | 9 | return $statisticalCalculator->sum(); | |||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | 21 | 1; | |||||||||||
| 60 | |||||||||||||