« Analizo/Metric/NumberOfPublicAttributes.pm
↑ Summary
Analizo/GlobalMetric/MethodsPerAbstractClass.pm »
| 1 | package Analizo::Metric::NumberOfPublicMethods; | ||||||||||||||||||||
| 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::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 | 21 | __PACKAGE__->mk_accessors(qw( model )); | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 15 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 31 | 15 | my ($package, %args) = @_; | |||||||||||||||||||
| 32 | my @instance_variables = ( | ||||||||||||||||||||
| 33 | model => $args{model} | ||||||||||||||||||||
| 34 | 15 | ); | |||||||||||||||||||
| 35 | 15 | return bless { @instance_variables }, $package; | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 4 | ▶ | sub description { | ||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 39 | 4 | return "Number of Public Methods"; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 11 | ▶ | sub calculate { | ||||||||||||||||||
|
Subroutine
calculate: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 43 | 11 | my ($self, $module) = @_; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 11 | my $count = 0; | |||||||||||||||||||
| 46 | 11 | for my $function ($self->model->functions($module)) { | |||||||||||||||||||
| 47 | 17 | ▶ | $count += 1 if $self->_is_public($function); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | 11 | return $count; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 17 | ▶ | sub _is_public { | ||||||||||||||||||
|
Subroutine
_is_public: called CC=2 SCAR=7.1
| |||||||||||||||||||||
| 53 | 17 | my ($self, $function) = @_; | |||||||||||||||||||
| 54 | 17 | ▶ | return $self->model->{protection}->{$function} && $self->model->{protection}->{$function} eq "public"; | ||||||||||||||||||
|
Condition66%2/3
$self->model->{'protection'}{$function} && $self->model->{'protection'}{$function} eq 'public'
MC/DC50%1/2
$self->model->{'protection'}{$function} && $self->model->{'protection'}{$function} eq 'public'
$self->model->{'protection'}{$function}
$self->model->{'protection'}{$function} eq 'public'
Truth table66%2/3
A && B
A= $self->model->{'protection'}{$function}B= $self->model->{'protection'}{$function} eq 'public'
| |||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 21 | 1; | |||||||||||||||||||
| 58 | |||||||||||||||||||||