Debian Codegraph @

lib/Analizo/Metric/NumberOfPublicMethods.pm

raw
1 package Analizo::Metric::NumberOfPublicMethods;
2 use strict;
3 use parent qw(Class::Accessor::Fast Analizo::ModuleMetric);
4
5 =head1 NAME
6
7 Analizo::Metric::NumerOfPublicMethods - Number of Public Methods (NPM) metric
8
9 =head1 DESCRIPTION
10
11 The metric calculation is based on the following article and calculates the
12 number of public methods of a class.
13
14 Article: I<Monitoring of source code metrics in open source projects> by Paulo
15 Roberto Miranda Meirelles.
16
17 See the adaptation of the paragraph about Number of Public Methods in the
18 article:
19
20 Represents the size of the "interface" of the class. Methods are directly
21 related to the operations provided in the respective class. High values for
22 this metric indicate that a class has many methods and probably many
23 responsibilities, which conflicts with good programming practices (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 Public Methods";
40 }
41
42 sub calculate {
43 my ($self, $module) = @_;
44
45 my $count = 0;
46 for my $function ($self->model->functions($module)) {
47 $count += 1 if $self->_is_public($function);
48 }
49 return $count;
50 }
51
52 sub _is_public {
53 my ($self, $function) = @_;
54 return $self->model->{protection}->{$function} && $self->model->{protection}->{$function} eq "public";
55 }
56
57 1;
58