| 1 |
package Analizo::Metric::DepthOfInheritanceTree; |
| 2 |
use strict; |
| 3 |
use parent qw(Class::Accessor::Fast Analizo::ModuleMetric); |
| 4 |
|
| 5 |
=head1 NAME |
| 6 |
|
| 7 |
Analizo::Metric::DepthOfInheritanceTree - Depth of Inheritance Tree (DIT) metric |
| 8 |
|
| 9 |
=head1 DESCRIPTION |
| 10 |
|
| 11 |
The metric calculation is based on the following article and calculates the |
| 12 |
longest path from a module to the class hierarchy root. |
| 13 |
|
| 14 |
Article: I<An empirical study of aspect-oriented metrics> by Eduardo Kessler |
| 15 |
Piveta, Ana Moreira, Marcelo Soares Pimenta, Joao Araujo, Pedro Guerreiro and |
| 16 |
R. Tom Price. |
| 17 |
|
| 18 |
See the adaptation of the paragraph about Depth of Inheritance Tree in the |
| 19 |
article: |
| 20 |
|
| 21 |
Considering a function C<< s(x) : Module -> Module >> that computes the |
| 22 |
super-class or super-aspect of a giver module, the value of DIT is given by: |
| 23 |
|
| 24 |
DIT(m) = DIT(s(m)) + 1, ifc m != rootClass |
| 25 |
DIT(m) = 0, otherwise. |
| 26 |
|
| 27 |
=cut |
| 28 |
|
| 29 |
__PACKAGE__->mk_accessors(qw( model )); |
| 30 |
|
| 31 |
sub new { |
| 32 |
my ($package, %args) = @_; |
| 33 |
my @instance_variables = ( |
| 34 |
model => $args{model} |
| 35 |
); |
| 36 |
return bless { @instance_variables }, $package; |
| 37 |
} |
| 38 |
|
| 39 |
sub description { |
| 40 |
return "Depth of Inheritance Tree"; |
| 41 |
} |
| 42 |
|
| 43 |
sub calculate { |
| 44 |
my ($self, $module) = @_; |
| 45 |
|
| 46 |
my @parents = $self->model->inheritance($module); |
| 47 |
return 1 + $self->_depth_of_deepest_inheritance_tree(@parents) if (@parents); |
| 48 |
return 0; |
| 49 |
} |
| 50 |
|
| 51 |
sub _depth_of_deepest_inheritance_tree { |
| 52 |
my ($self, @parents) = @_; |
| 53 |
my @parent_dits = map { $self->calculate($_) } @parents; |
| 54 |
my @sorted = reverse(sort(@parent_dits)); |
| 55 |
return $sorted[0]; |
| 56 |
} |
| 57 |
|
| 58 |
1; |
| 59 |
|