| 1 |
package Analizo::Metric::AfferentConnections; |
| 2 |
use strict; |
| 3 |
use parent qw(Class::Accessor::Fast Analizo::ModuleMetric); |
| 4 |
|
| 5 |
=head1 NAME |
| 6 |
|
| 7 |
Analizo::Metric::AfferentConnections - Afferent Connections per Class (ACC) metric |
| 8 |
|
| 9 |
=head1 DESCRIPTION |
| 10 |
|
| 11 |
The metric calculation is based on the following article and calculates the |
| 12 |
class connectivity. |
| 13 |
|
| 14 |
PhD Thesis: I<Monitoramento de metricas de codigo-fonte em projetos de software livre> |
| 15 |
by Paulo Roberto Miranda Meirelles. |
| 16 |
|
| 17 |
See the adaptation of the paragraph about Afferent Connections per Class in |
| 18 |
the article: |
| 19 |
|
| 20 |
Measures the connectivity of a class. If a class C<Ci> access a method or |
| 21 |
attribute of a class C<Cj>, consider C<Ci> a client of the supplier class |
| 22 |
C<Cj>, denoting C<< Ci => Cj >>. Consider the follow function: |
| 23 |
|
| 24 |
client(Ci, Cj) = 1, if (Ci => Cj) and (Ci != Cj) |
| 25 |
client(Ci, Cj) = 0, otherwise. |
| 26 |
|
| 27 |
So C<ACC(Cj) = (sum(client(Ci, Cj)), i = 1 to N)>, where C<N> is the total |
| 28 |
number of system classes. If the value of this metric is large, a change in the |
| 29 |
class has substantially more side effects, making maintenance more difficult. |
| 30 |
|
| 31 |
=head1 REFERENCES |
| 32 |
|
| 33 |
=over |
| 34 |
|
| 35 |
=item * |
| 36 |
|
| 37 |
L<Monitoramento de metricas de codigo-fonte em projetos de software livre|https://www.teses.usp.br/teses/disponiveis/45/45134/tde-27082013-090242> |
| 38 |
|
| 39 |
=back |
| 40 |
|
| 41 |
=cut |
| 42 |
|
| 43 |
__PACKAGE__->mk_accessors(qw( model analized_module)); |
| 44 |
|
| 45 |
sub new { |
| 46 |
my ($package, %args) = @_; |
| 47 |
my @instance_variables = ( |
| 48 |
model => $args{model}, |
| 49 |
analized_modules => undef |
| 50 |
); |
| 51 |
return bless { @instance_variables }, $package; |
| 52 |
} |
| 53 |
|
| 54 |
sub description { |
| 55 |
return 'Afferent Connections per Class (used to calculate COF - Coupling Factor)'; |
| 56 |
} |
| 57 |
|
| 58 |
sub calculate { |
| 59 |
my ($self, $module) = @_; |
| 60 |
$self->analized_module($module); |
| 61 |
my $acc_result = $self->model->modules_graph->in_degree($module); |
| 62 |
return $acc_result ? $acc_result : 0; |
| 63 |
} |
| 64 |
|
| 65 |
1; |