Debian Codegraph @

lib/Analizo/Metric/LinesOfCode.pm

raw
1 package Analizo::Metric::LinesOfCode;
2 use strict;
3 use parent qw(Class::Accessor::Fast Analizo::ModuleMetric);
4 use Statistics::Descriptive;
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 __PACKAGE__->mk_accessors(qw( model ));
29
30 sub new {
31 my ($package, %args) = @_;
32 my @instance_variables = (
33 model => $args{model}
34 );
35 return bless { @instance_variables }, $package;
36 }
37
38 sub description {
39 return "Lines of Code";
40 }
41
42 sub calculate {
43 my ($self, $module) = @_;
44
45 my @functions = $self->model->functions($module);
46 if (scalar(@functions) == 0) {
47 return 0;
48 }
49
50 my $statisticalCalculator = Statistics::Descriptive::Full->new();
51
52 for my $function (@functions) {
53 $statisticalCalculator->add_data($self->model->{lines}->{$function} || 0);
54 }
55
56 return $statisticalCalculator->sum();
57 }
58
59 1;
60