Debian Codegraph @

lib/Analizo/Metric/NumberOfMethods.pm

raw
1 package Analizo::Metric::NumberOfMethods;
2 use strict;
3 use parent qw(Class::Accessor::Fast Analizo::ModuleMetric);
4
5 =head1 NAME
6
7 Analizo::Metric::NumberOfMethods - Number of Methods (NOM) metric
8
9 =head1 DESCRIPTION
10
11 The metric calculation is based on the following article and calculates the
12 number of methods per class to measure the size of the classes in terms of its
13 implemented operations.
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 Number of Methods in the article:
19
20 ... This metric is used to help to identify the potential reuse of a class. In
21 general, the classes with a large number of methods are harder to be reused,
22 because they are more likely to be less cohesive (Lorenz and Kidd, 1994). Thus,
23 it's recommended that a class don't have a excessive number of methods (Beck,
24 1997).
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 "Number of Methods";
40 }
41
42 sub calculate {
43 my ($self, $module) = @_;
44 my @functions = $self->model->functions($module);
45 return scalar(@functions);
46 }
47
48 1;
49