| 1 | package Analizo::Metric::NumberOfPublicAttributes; | ||||||||||||||||||||
| 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::NumberOfPublicAttributes - Number of Public Attributes (NPA) metric | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | =head1 DESCRIPTION | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | The metric calculation is based on the following article and calculates the | ||||||||||||||||||||
| 12 | number of public attributes 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 Attributes in the | ||||||||||||||||||||
| 18 | article: | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | It measures the encapsulation. The attributes of a class must only serve to the | ||||||||||||||||||||
| 21 | functionalities of itself. Thus, good programming practices recommend that the | ||||||||||||||||||||
| 22 | attributes of a class must be manipulated using the access methods (Beck, | ||||||||||||||||||||
| 23 | 1997), the attributes of a class must be private, indicating that the ideal | ||||||||||||||||||||
| 24 | number for this metric is zero. | ||||||||||||||||||||
| 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 Attributes"; | |||||||||||||||||||
| 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 $attribute ($self->model->variables($module)) { | |||||||||||||||||||
| 47 | 9 | ▶ | $count += 1 if $self->_is_public($attribute); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | 11 | return $count; | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 9 | ▶ | sub _is_public { | ||||||||||||||||||
|
Subroutine
_is_public: called CC=2 SCAR=7.1
| |||||||||||||||||||||
| 53 | 9 | my ($self, $attribute) = @_; | |||||||||||||||||||
| 54 | 9 | ▶ | return $self->model->{protection}->{$attribute} && $self->model->{protection}->{$attribute} eq "public"; | ||||||||||||||||||
|
Condition66%2/3
$self->model->{'protection'}{$attribute} && $self->model->{'protection'}{$attribute} eq 'public'
MC/DC50%1/2
$self->model->{'protection'}{$attribute} && $self->model->{'protection'}{$attribute} eq 'public'
$self->model->{'protection'}{$attribute}
$self->model->{'protection'}{$attribute} eq 'public'
Truth table66%2/3
A && B
A= $self->model->{'protection'}{$attribute}B= $self->model->{'protection'}{$attribute} eq 'public'
| |||||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 21 | 1; | |||||||||||||||||||
| 58 | |||||||||||||||||||||