| 1 |
package Analizo::Metric::ResponseForClass; |
| 2 |
use strict; |
| 3 |
use parent qw(Class::Accessor::Fast Analizo::ModuleMetric); |
| 4 |
|
| 5 |
=head1 NAME |
| 6 |
|
| 7 |
Analizo::Metric::ResponseForClass - Response for Class (RFC) metric |
| 8 |
|
| 9 |
=head1 DESCRIPTION |
| 10 |
|
| 11 |
The metric calculation is based on the following article and calculates the sum |
| 12 |
between the number of methods in the module and the number of functions called |
| 13 |
by each module function. |
| 14 |
|
| 15 |
Article: I<A metrics suite for object oriented design> by Shyam R. Chidamber |
| 16 |
and Chris F. Kemerer. |
| 17 |
|
| 18 |
See the paragraph about Response for Class in the article: |
| 19 |
|
| 20 |
... The response set of a class is a set of methods that can potentially be |
| 21 |
executed in response to a message received by an object of that class. The |
| 22 |
cardinality of this set is a measure of the attributes of objects in the class. |
| 23 |
Since it specifically includes methods called from outside the class, it is |
| 24 |
also a measure of the potential communication between the class and other |
| 25 |
classes. |
| 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 "Response for a Class"; |
| 41 |
} |
| 42 |
|
| 43 |
sub calculate { |
| 44 |
my ($self, $module) = @_; |
| 45 |
|
| 46 |
my @functions = $self->model->functions($module); |
| 47 |
my $number_of_functions = scalar @functions; |
| 48 |
my $number_of_functions_called_by_module_functions = $self->_number_of_functions_called_by(@functions); |
| 49 |
|
| 50 |
return $number_of_functions + $number_of_functions_called_by_module_functions; |
| 51 |
} |
| 52 |
|
| 53 |
sub _number_of_functions_called_by { |
| 54 |
my ($self, @functions) = @_; |
| 55 |
|
| 56 |
my $count = 0; |
| 57 |
for my $function (@functions){ |
| 58 |
$count += scalar keys(%{$self->model->calls->{$function}}); |
| 59 |
} |
| 60 |
return $count; |
| 61 |
} |
| 62 |
|
| 63 |
1; |
| 64 |
|