Analizo/Extractor/Doxyparse.pm

filter: Statementstmt 85.9% 110 / 128 Branchbran 63.6% 28 / 44 Conditioncond 50.0% 7 / 14 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 100% 16 / 16 Podpod 33.3% 1 / 3 totaltotal 76.1% 163 / 214 CC 36 SCAR 28.4
CC
36
Cov
78%
feed
30.9
_cpp_hack
10.7
actually_process
6.8
CRAP 17.1
« Analizo/Batch/Output/CSV.pm ↑ Summary Analizo/Command.pm »
1 package Analizo::Extractor::Doxyparse;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use parent qw(Analizo::Extractor);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use File::Temp qw/ tempfile /;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use YAML::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use File::Spec::Functions qw/ tmpdir /;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 21 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
14 21 my ($package, @options) = @_;
15 21 return bless { files => [], @options }, $package;
16 }
17  
18 14 ▶sub _add_file {
Subroutine _add_file: called CC=1 SCAR=0.0
19 14 my ($self, $file) = @_;
20 14 push(@{$self->{files}}, $file);
21 }
22  
23 14 ▶sub _cpp_hack {
Subroutine _cpp_hack: called CC=7 SCAR=23.7
24 14 my ($self, $module) = @_;
25 14 my $current = $self->current_file;
26 14 ▶ if (defined($current) && $current =~ /^(.*)\.(h|hpp)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current and $current =~ /^(.*)\.(h|hpp)$/) 0 14 14
Condition33%1/3
defined $current and $current =~ /^(.*)\.(h|hpp)$/
!ll&&!rl&&r
0140
MC/DC0%0/2
defined $current and $current =~ /^(.*)\.(h|hpp)$/
defined $current $current =~ /^(.*)\.(h|hpp)$/
Truth table33%1/3
A and B
A= defined $currentB= $current =~ /^(.*)\.(h|hpp)$/
ABresult
0X0
100
111
27 0 my $prefix = $1;
28 # look for a previously added .cpp/.cc/etc
29 0 my @implementations = grep { /^$prefix\.(cpp|cxx|cc)$/ } @{$self->{files}};
30 0 foreach my $file (@implementations) {
31 0 $self->model->declare_module($module, $file);
32 }
33 }
34 14 ▶ if (defined($current) && $current =~ /^(.*)\.(cpp|cxx|cc)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $current and $current =~ /^(.*)\.(cpp|cxx|cc)$/) 1 13 14
Condition66%2/3
defined $current and $current =~ /^(.*)\.(cpp|cxx|cc)$/
!ll&&!rl&&r
0131
MC/DC50%1/2
defined $current and $current =~ /^(.*)\.(cpp|cxx|cc)$/
defined $current $current =~ /^(.*)\.(cpp|cxx|cc)$/
Truth table66%2/3
A and B
A= defined $currentB= $current =~ /^(.*)\.(cpp|cxx|cc)$/
ABresult
0X0
100
111
35 1 my $prefix = $1;
36 # look for a previously added .h/.hpp/etc
37 1 my @implementations = grep { /^$prefix\.(h|hpp)$/ } @{$self->{files}};
38 1 foreach my $file (@implementations) {
39 0 $self->model->declare_module($module, $file);
40 }
41 }
42 }
43  
44 14 ▶sub feed {
Subroutine feed: called CC=24 SCAR=34.3
Pod undocumented
45 14 my ($self, $doxyparse_output, $line) = @_;
46 14 my $yaml = undef;
47 14 eval { $yaml = Load($doxyparse_output) };
48 14 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 14 14
49 0 die $!;
50 }
51 14 foreach my $full_filename (sort keys %$yaml) {
52  
53 # current file declaration
54 14 my $file = _strip_current_directory($full_filename);
55 14 $self->current_file($file);
56 14 $self->_add_file($file);
57  
58 # current module declaration
59 14 foreach my $module (keys %{$yaml->{$full_filename}}) {
60 14 my $modulename = _file_to_module($module);
61 14 ▶ next if defined $yaml->{$full_filename}->{$module} && ref($yaml->{$full_filename}->{$module}) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if defined $yaml->{$full_filename}{$module} and ref $yaml->{$full_filename}{$module} ne "HASH" 0 14 14
Condition66%2/3
defined $yaml->{$full_filename}{$module} and ref $yaml->{$full_filename}{$module} ne "HASH"
!ll&&!rl&&r
2120
MC/DC0%0/2
defined $yaml->{$full_filename}{$module} and ref $yaml->{$full_filename}{$module} ne "HASH"
defined $yaml->{$full_filename}{$module} ref $yaml->{$full_filename}{$module} ne "HASH"
Truth table66%2/3
A and B
A= defined $yaml->{$full_filename}{$module}B= ref $yaml->{$full_filename}{$module} ne "HASH"
ABresult
0X0
100
111
62  
63 14 $self->current_module($modulename);
64 14 $self->_cpp_hack($modulename);
65  
66 # inheritance
67 14 ▶ if (defined $yaml->{$full_filename}->{$module}->{inherits}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $yaml->{$full_filename}{$module}{"inherits"}) 0 14 14
68 0 ▶ if (ref $yaml->{$full_filename}->{$module}->{inherits} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $yaml->{$full_filename}{$module}{'inherits'} eq 'ARRAY') { } 0 0 0
69 0 foreach my $inherits (@{ $yaml->{$full_filename}->{$module}->{inherits} }) {
70 0 $self->model->add_inheritance($self->current_module, $inherits);
71 }
72 }
73 else {
74 0 my $inherits = $yaml->{$full_filename}->{$module}->{inherits};
75 0 $self->model->add_inheritance($self->current_module, $inherits);
76 }
77 }
78  
79 # abstract class
80 14 ▶ if (defined $yaml->{$full_filename}->{$module}->{information}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $yaml->{$full_filename}{$module}{"information"}) 1 13 14
81 1 ▶ if ($yaml->{$full_filename}->{$module}->{information} eq 'abstract class') {
Branch: 1 branch
BranchTrueFalseTotal
if ($yaml->{$full_filename}{$module}{"information"} eq "abstract class") 1 0 1
82 1 $self->model->add_abstract_class($self->current_module);
83 }
84 }
85  
86 14 foreach my $definition (@{$yaml->{$full_filename}->{$module}->{defines}}) {
87 18 my ($name) = keys %$definition;
88 18 ▶ next if $definition->{$name}->{prototype} and $definition->{$name}->{prototype} eq 'yes';
Branch: 1 branch
BranchTrueFalseTotal
if $definition->{$name}{"prototype"} and $definition->{$name}{"prototype"} eq "yes" 0 18 18
Condition33%1/3
$definition->{$name}{"prototype"} and $definition->{$name}{"prototype"} eq "yes"
!ll&&!rl&&r
1800
MC/DC0%0/2
$definition->{$name}{"prototype"} and $definition->{$name}{"prototype"} eq "yes"
$definition->{$name}{"prototype"} $definition->{$name}{"prototype"} eq "yes"
Truth table33%1/3
A and B
A= $definition->{$name}{"prototype"}B= $definition->{$name}{"prototype"} eq "yes"
ABresult
0X0
100
111
89 18 my $type = $definition->{$name}->{type};
90 18 my $qualified_name = _qualified_name($self->current_module, $name);
91 18 $self->{current_member} = $qualified_name;
92  
93 # function declarations
94 18 ▶ if ($type eq 'function') {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'function') { } 15 3 18
elsif ($type eq 'variable') { } 3 0 3
elsif ($type eq 'macro definition') { } 0 0 0
95 15 $self->model->declare_function($self->current_module, $qualified_name);
96 }
97 # variable declarations
98 elsif ($type eq 'variable') {
99 3 $self->model->declare_variable($self->current_module, $qualified_name);
100 }
101 #FIXME: Implement define treatment (no novo doxyparse identifica como type = "macro definition")
102 # define declarations
103 elsif ($type eq 'macro definition') {
104 #$self->{current_member} = $qualified_name;
105 }
106  
107 # public members
108 18 ▶ if (defined $definition->{$name}->{protection}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $definition->{$name}{"protection"}) 3 15 18
109 3 my $protection = $definition->{$name}->{protection};
110 3 $self->model->add_protection($self->current_member, $protection);
111 }
112  
113 # method LOC
114 18 ▶ if (defined $definition->{$name}->{lines_of_code}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $definition->{$name}{"lines_of_code"}) 2 16 18
115 2 $self->model->add_loc($self->current_member, $definition->{$name}->{lines_of_code});
116 }
117  
118 # method parameters
119 18 ▶ if (defined $definition->{$name}->{parameters}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $definition->{$name}{"parameters"}) 1 17 18
120 1 $self->model->add_parameters($self->current_member, $definition->{$name}->{parameters});
121 }
122  
123 # method conditional paths
124 18 ▶ if (defined $definition->{$name}->{conditional_paths}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $definition->{$name}{"conditional_paths"}) 1 17 18
125 1 $self->model->add_conditional_paths($self->current_member, $definition->{$name}->{conditional_paths});
126 }
127  
128 18 foreach my $uses (@{ $definition->{$name}->{uses} }) {
129 5 my ($uses_name) = keys %$uses;
130 5 my $uses_type = $uses->{$uses_name}->{type};
131 5 my $defined_in = $uses->{$uses_name}->{defined_in};
132 5 my $qualified_uses_name = _qualified_name($defined_in, $uses_name);
133 # function calls/uses
134 5 ▶ if ($uses_type eq 'function') {
Branch: 2 branches
BranchTrueFalseTotal
if ($uses_type eq 'function') { } 3 2 5
elsif ($uses_type eq 'variable') { } 2 0 2
135 3 $self->model->add_call($self->current_member, $qualified_uses_name, 'direct');
136 }
137 # variable references
138 elsif ($uses_type eq 'variable') {
139 2 $self->model->add_variable_use($self->current_member, $qualified_uses_name);
140 }
141  
142 }
143 }
144 }
145 }
146 }
147  
148 # concat module with symbol (e.g. main::to_string)
149 23 ▶sub _qualified_name {
Subroutine _qualified_name: called CC=1 SCAR=0.0
150 23 my ($file, $symbol) = @_;
151 23 _file_to_module($file) . '::' . $symbol;
152 }
153  
154 # discard file suffix (e.g. .c or .h)
155 37 ▶sub _file_to_module {
Subroutine _file_to_module: called CC=2 SCAR=7.0
156 37 my ($filename) = @_;
157 37 ▶ $filename ||= 'unknown';
Condition50%1/2
$filename ||= "unknown"
l!l
370
MC/DC0%0/1
$filename ||= "unknown"
$filename
Truth table50%1/2
A
A= $filename
Aresult
11
00
158 37 $filename =~ s/\.\w+$//;
159 37 return $filename;
160 }
161  
162 14 ▶sub _strip_current_directory {
Subroutine _strip_current_directory: called CC=1 SCAR=0.0
163 14 my ($file) = @_;
164 14 my $pwd = getcwd();
165 14 $file =~ s#^$pwd/##;
166 14 return $file;
167 }
168  
169 4 ▶sub actually_process {
Subroutine actually_process: called CC=6 SCAR=19.1
Pod undocumented
170 4 my ($self, @input_files) = @_;
171 4 my ($temp_handle, $temp_filename) = tempfile();
172 4 foreach my $input_file (@input_files) {
173 26 print $temp_handle "$input_file\n"
174 }
175 4 close $temp_handle;
176  
177 0 ▶ eval 'use Alien::Doxyparse';
Subroutine BEGIN: called CC=1 SCAR=1.2
178 4 ▶ $ENV{PATH} = join(':', $ENV{PATH}, Alien::Doxyparse->bin_dir) unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 0 4 4
179  
180 4 eval {
181 4 local $ENV{TEMP} = tmpdir();
182 4 ▶ open DOXYPARSE, "doxyparse - < $temp_filename |" or die "can't run doxyparse: $!";
Branch: 1 branch
BranchTrueFalseTotal
open DOXYPARSE, "doxyparse - < $temp_filename |" or die "can't run doxyparse: $!" 4 0 4
183 4 local $/ = undef;
184 4 my $doxyparse_output = <DOXYPARSE>;
185 4 ▶ close DOXYPARSE or die "doxyparse error";
Branch: 1 branch
BranchTrueFalseTotal
close DOXYPARSE or die "doxyparse error" 0 4 4
186 0 $self->feed($doxyparse_output);
187 0 unlink $temp_filename;
188 };
189 4 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 4 0 4
190 4 warn($@);
191 4 exit -1;
192 }
193 }
194  
195 5 1;
« Analizo/Batch/Output/CSV.pm ↑ Summary Analizo/Command.pm »