DMOSS.pm

filter: Statementstmt 33.5% 58 / 173 Branchbran 7.8% 3 / 38 Conditioncond 12.5% 1 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 50.0% 13 / 26 Podpod 90.9% 10 / 11 totaltotal 32.5% 85 / 261 CC 38 SCAR 33.4
CC
38
Cov
28%
process
109.8
__handle_level
30.0
tree_process
20.0
CRAP 28.3
« DMOSS/Plugin/AutoClassify.pm ↑ Summary DMOSS/Report/HTML.pm »
1 package DMOSS;
2 # ABSTRACT: Data Mining Open Source Software
3 2 $DMOSS::VERSION = '0.01_2';
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use DMOSS::Oracle;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use DMOSS::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use DMOSS::Attr;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Storable qw/store retrieve dclone store_fd fd_retrieve/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Module::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶sub new {
Subroutine new: called CC=7 SCAR=21.6
Pod documented
16 1 my ($class,$basedir,@files) = @_;
17 1 my $self = bless({}, $class);
18 1 $self->{basedir} = $basedir;
19 1 $self->{typeof} = {};
20 1 $self->{res} = {};
21 1 $self->{meta} = {};
22  
23 1 ▶ my $dist = basename $basedir if $basedir;
Branch: 1 branch
BranchTrueFalseTotal
if $basedir 0 1 1
24  
25 1 $self->{meta}->{dist} = $dist;
26 1 ▶ if ($dist and $dist =~ m/([\d\-\.]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist and $dist =~ /([\d\-\.]+)$/) 0 1 1
Condition33%1/3
$dist and $dist =~ /([\d\-\.]+)$/
!ll&&!rl&&r
100
MC/DC0%0/2
$dist and $dist =~ /([\d\-\.]+)$/
$dist $dist =~ /([\d\-\.]+)$/
Truth table33%1/3
A and B
A= $distB= $dist =~ /([\d\-\.]+)$/
ABresult
0X0
100
111
27 0 my $version = $1;
28 0 $version =~ s/^[\-\.]+//;
29 0 ▶ if ($version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version) 0 0 0
30 0 $self->{meta}->{version} = $version;
31 }
32 }
33  
34 # start with an empty tree
35 1 $self->{tree} = {};
36  
37 # init files, and populate tree
38 1 $self->__init_files($basedir, @files);
39  
40 # find available plugins
41 1 my @available = findallmod DMOSS::Plugin;
42 1 my @plugins;
43 1 foreach (@available) {
44 7 eval "require $_;";
45 7 my $skip = eval '$'.$_ .'::SKIP or 0';
46 7 ▶ push @plugins, $_ unless $skip;
Branch: 1 branch
BranchTrueFalseTotal
unless $skip 7 0 7
47 }
48 1 $self->{plugins} = [@plugins];
49  
50 1 return $self;
51 }
52  
53 1 ▶sub __init_files {
Subroutine __init_files: called CC=3 SCAR=19.6
54 1 my ($self, $basedir, @files) = @_;
55 1 my $ora = DMOSS::Oracle->new();
56  
57 1 foreach (@files) {
58 0 my $file = DMOSS::File->new($basedir, $_);
59 0 $self->{files}->{$file->path} = $file;
60  
61 0 my $type = $ora->type($file);
62 0 ▶ if ($type) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 0 0 0
63 0 $file->type($type);
64 0 $self->{files}->{$file->path}->{type} = $type;
65 0 $self->{typeof}->{$file->path} = $type;
66 }
67  
68 0 $self->__add_tree($file->path, $_);
69 }
70 }
71  
72 0 ▶sub __add_tree {
Subroutine __add_tree: not called CC=3 SCAR=24.8
73 0 my ($self, $path, $id) = @_;
74  
75 0 my @l = split /[\\\/]+/, $path; # FIXME generalize file separator
76  
77 0 my $root = $self->{tree};
78 0 my $next = shift @l;
79 0 ▶ while (@l) {
Branch: 1 branch
BranchTrueFalseTotal
if (@l) 0 0 0
80 0 ▶ $root->{$next} = {} unless exists($root->{$next});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $root->{$next} 0 0 0
81 0 $root = $root->{$next};
82 0 $next = shift @l;
83 }
84 0 $root->{$path} = $id;
85 }
86  
87 2 my $curr_file; # FIXME remove global variables
88  
89 0 ▶sub process {
Subroutine process: not called CC=11 SCAR=47.0
Pod documented
90 0 my ($self) = @_;
91 0 my @plugins = @{$self->{plugins}};
92 0 my $ora = DMOSS::Oracle->new;
93  
94 # load plugins and populate dispatch table per type
95 0 my $dispatch;
96 my @package_plugins;
97 0 foreach (@plugins) {
98 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
99 0 eval "require $_";
100 0 my @types = @{ $_ . '::types' };
101 0 foreach my $t (@types) {
102 0 ▶ if ($t =~ m/_PACKAGE/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /_PACKAGE/) 0 0 0
103 0 push @package_plugins, $_;
104 }
105 0 ▶ if ($t =~ m/^_/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /^_/) { } 0 0 0
106 0 foreach my $tt ($ora->group($t)) {
107 0 push @{$dispatch->{$tt}}, $_;
108 }
109 }
110 0 else { push @{$dispatch->{$t}}, $_; }
111 }
112 }
113  
114 # run plugins procesors for each file
115 0 foreach (keys %{$self->{files}}) {
116 0 my $file = $self->{files}->{$_};
117 0 ▶ next unless ($file->type and exists($dispatch->{$file->type}));
Branch: 1 branch
BranchTrueFalseTotal
unless $file->type and exists $$dispatch{$file->type} 0 0 0
Condition0%0/3
$file->type and exists $$dispatch{$file->type}
!ll&&!rl&&r
000
MC/DC0%0/2
$file->type and exists $$dispatch{$file->type}
$file->type exists $$dispatch{$file->type}
Truth table0%0/3
A and B
A= $file->typeB= exists $$dispatch{$file->type}
ABresult
0X0
100
111
118 0 $curr_file = $file;
119  
120 0 my @watchers = @{$dispatch->{$file->type}};
121 0 foreach (@watchers) {
122 0 my $obj = $_->new;
123 0 $obj->process($self, $file);
124 }
125 }
126 # run package processors
127 0 foreach (@package_plugins) {
128 0 $curr_file = DMOSS::File->new($self->{basedir}, '');
129 0 my $obj = $_->new;
130 0 $obj->process($self, $curr_file);
131 }
132  
133 # run post processing (reduce) functions
134 0 $self->tree_process($self->{tree}, '');
135 0 $self->__handle_level($self->{tree}, '');
136 }
137  
138 0 ▶sub tree_process {
Subroutine tree_process: not called CC=4 SCAR=30.0
Pod documented
139 0 my ($self, $root, $path) = @_;
140  
141 0 foreach my $k (keys %$root) {
142 0 ▶ if (ref($root->{$k}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $root->{$k} eq "HASH") 0 0 0
143 0 ▶ my $curr = $path ? "$path/$k" : $k;
Branch: 1 branch
BranchTrueFalseTotal
$path ? : 0 0 0
144 0 $self->tree_process($root->{$k}, $curr);
145 0 $self->__handle_level($root->{$k}, $curr);
146 }
147 }
148 }
149  
150 0 ▶sub __handle_level {
Subroutine __handle_level: not called CC=5 SCAR=34.0
151 0 my ($self, $root, $path) = @_;
152 0 $curr_file = DMOSS::File->new($self->{basedir}, $path);
153  
154 0 foreach my $p ( @{ $self->{plugins} } ) {
155 0 my @attrs;
156 0 foreach my $k (keys %$root) {
157 0 ▶ next unless $self->{attrs}->{$k}->{$p};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"attrs"}{$k}{$p} 0 0 0
158 0 push @attrs, @{ $self->{attrs}->{$k}->{$p} };
159 }
160 0 ▶ $p->reduce($self, @attrs) if (@attrs);
Branch: 1 branch
BranchTrueFalseTotal
if @attrs 0 0 0
161 }
162 }
163  
164 0 ▶sub add_attr {
Subroutine add_attr: not called CC=2 SCAR=17.9
Pod documented
165 0 my ($self, $name, $value) = @_;
166 0 my ($plugin) = caller;
167  
168 0 my $attr = DMOSS::Attr->new($curr_file, $plugin, $name, $value);
169 0 ▶ push @{ $self->{attrs}->{$attr->file->path or ''}->{$plugin} }, $attr;
Condition0%0/2
$attr->file->path || ''
l!l
00
MC/DC0%0/1
$attr->file->path || ''
$attr->file->path
Truth table0%0/2
A
A= $attr->file->path
Aresult
11
00
170 }
171  
172 0 ▶sub report_attrs_plugin {
Subroutine report_attrs_plugin: not called CC=4 SCAR=30.0
Pod documented
173 0 my ($self, $report, $plugin) = @_;
174 0 my @reports;
175 0 eval "require $plugin;";
176  
177 0 foreach my $k (keys %{ $self->{attrs} }) {
178 0 foreach (@{ $self->{attrs}->{$k}->{$plugin} }) {
179 0 my $r = $plugin->report($self, $_);
180 0 ▶ if (ref($r->[0]) eq 'ARRAY') { push @reports, @$r; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $r->[0] eq 'ARRAY') { } 0 0 0
181 0 else { push @reports, $r; }
182 }
183 }
184  
185 0 return @reports;
186 }
187  
188 0 ▶sub plugin_grade {
Subroutine plugin_grade: not called CC=1 SCAR=6.9
Pod undocumented
189 0 my ($self, $plugin) = @_;
190  
191 0 eval "require $plugin;";
192 0 return $plugin->grade($self, $self->{attrs}->{''}->{$plugin}->[0]);
193 }
194  
195 0 ▶sub dt {
Subroutine dt: not called CC=1 SCAR=6.9
Pod documented
196 0 my ($self, $f) = @_;
197  
198 0 $self->__dt($self->{tree}, '', $f);
199 }
200  
201 0 ▶sub __dt {
Subroutine __dt: not called CC=5 SCAR=28.8
202 0 my ($self, $root, $path, $f) = @_;
203 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
204  
205 0 foreach my $k (keys %$root) {
206 0 ▶ if (ref($root->{$k}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $root->{$k} eq "HASH") 0 0 0
207 0 ▶ my $curr = $path ? "$path/$k" : $k;
Branch: 1 branch
BranchTrueFalseTotal
$path ? : 0 0 0
208 0 $self->__dt($root->{$k}, $curr, $f);
209 }
210 }
211  
212 0 my $tmp = dclone($self->{res});
213 0 foreach my $k (keys %$root) {
214 0 &$f(dclone($self), $k);
215 }
216  
217 }
218  
219 0 ▶sub save {
Subroutine save: not called CC=2 SCAR=17.9
Pod documented
220 0 my ($self, $file) = @_;
221 0 ▶ $file = 'dmoss.data' unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 0 0
222  
223 0 store $self, $file;
224  
225 0 return $file;
226 }
227  
228 0 ▶sub to_stdout {
Subroutine to_stdout: not called CC=1 SCAR=6.9
Pod documented
229 0 my ($self) = @_;
230  
231 0 store_fd($self, *STDOUT);
232 }
233  
234 0 ▶sub load {
Subroutine load: not called CC=2 SCAR=17.9
Pod documented
235 0 my ($file) = @_;
236 0 ▶ $file = 'dmoss.data' unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 0 0
237  
238 0 my $ref = retrieve($file);
239 0 my $self = bless($ref, 'DMOSS');
240  
241 0 return $self;
242 }
243  
244 0 ▶sub from_stdout {
Subroutine from_stdout: not called CC=1 SCAR=6.9
Pod documented
245 0 my $ref = fd_retrieve(*STDIN);
246 0 my $self = bless($ref, 'DMOSS');
247  
248 0 return $self;
249 }
250  
251 2 1;
252  
253 __END__
« DMOSS/Plugin/AutoClassify.pm ↑ Summary DMOSS/Report/HTML.pm »