| 1 | package Analizo::Metric::DepthOfInheritanceTree; | ||||||||||
| 2 | 21 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 21 | ▶ | use parent qw(Class::Accessor::Fast Analizo::ModuleMetric); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 21 | __PACKAGE__->mk_accessors(qw( model )); | |||||||||
| 30 | |||||||||||
| 31 | 16 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 32 | 16 | my ($package, %args) = @_; | |||||||||
| 33 | my @instance_variables = ( | ||||||||||
| 34 | model => $args{model} | ||||||||||
| 35 | 16 | ); | |||||||||
| 36 | 16 | return bless { @instance_variables }, $package; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 3 | ▶ | sub description { | ||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 40 | 3 | return "Depth of Inheritance Tree"; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 17 | ▶ | sub calculate { | ||||||||
|
Subroutine
calculate: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 44 | 17 | my ($self, $module) = @_; | |||||||||
| 45 | |||||||||||
| 46 | 17 | my @parents = $self->model->inheritance($module); | |||||||||
| 47 | 17 | ▶ | return 1 + $self->_depth_of_deepest_inheritance_tree(@parents) if (@parents); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 12 | return 0; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 5 | ▶ | sub _depth_of_deepest_inheritance_tree { | ||||||||
|
Subroutine
_depth_of_deepest_inheritance_tree: called CC=1 SCAR=0.0
| |||||||||||
| 52 | 5 | my ($self, @parents) = @_; | |||||||||
| 53 | 5 | my @parent_dits = map { $self->calculate($_) } @parents; | |||||||||
| 54 | 5 | my @sorted = reverse(sort(@parent_dits)); | |||||||||
| 55 | 5 | return $sorted[0]; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 21 | 1; | |||||||||
| 59 | |||||||||||