Analizo/Batch/Output/DB.pm

filter: Statementstmt 67.7% 130 / 192 Branchbran 52.2% 23 / 44 Conditioncond 26.4% 9 / 34 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 77.4% 24 / 31 Podpod 0.0% 0 / 5 totaltotal 56.7% 186 / 328 CC 40 SCAR 30.4
CC
40
Cov
60%
_add_modules
98.7
_add_module_version
20.0
_add_module
12.0
CRAP 20.8
« Analizo/Command/files_graph.pm ↑ Summary Analizo/Batch/Output/CSV.pm »
1 package Analizo::Batch::Output::DB;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use parent qw( Analizo::Batch::Output );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Digest::SHA qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 ▶sub database($) {
Subroutine database: called CC=3 SCAR=12.0
Pod undocumented
9 10 my ($self) = @_;
10 10 ▶ my $db = $self->file || 'output.sqlite3';
Condition50%1/2
$self->file || 'output.sqlite3'
l!l
100
MC/DC0%0/1
$self->file || 'output.sqlite3'
$self->file
Truth table50%1/2
A
A= $self->file
Aresult
11
00
11 10 ▶ if ($db =~ /^dbi:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($db =~ /^dbi:/) { } 0 10 10
12 0 return $db;
13 } else {
14 10 return 'dbi:SQLite:' . $db;
15 }
16 }
17  
18 2 ▶sub push($$) {
Subroutine push: called CC=1 SCAR=0.0
Pod undocumented
19 2 my ($self, $job) = @_;
20  
21 2 my $project_id = $self->_add_project($job->project_name);
22  
23 2 my $developer_id = $self->_add_developer($job);
24  
25 2 my $commit_id = $self->_add_commit($job, $project_id, $developer_id);
26  
27 2 $self->_add_modules($job, $commit_id, $project_id);
28 }
29  
30 0 ▶sub flush($) {
Subroutine flush: not called CC=1 SCAR=6.9
Pod undocumented
31 0 my ($self) = @_;
32 0 $self->{dbh}->disconnect();
33 }
34  
35 8 ▶sub _find_row_id($$@) {
Subroutine _find_row_id: called CC=3 SCAR=11.0
36 8 my ($self, $sql, @data) = @_;
37 8 my $statement_id = 'st_find_' . sha1_hex($sql); # is this SHA1 needed at all?
38  
39 8 ▶ $self->{$statement_id} ||= $self->{dbh}->prepare($sql);
Condition66%2/3
$self->{$statement_id} ||= $self->{"dbh"}->prepare($sql)
l!l&&r!l&&!r
530
MC/DC0%0/2
$self->{$statement_id} ||= $self->{"dbh"}->prepare($sql)
$self->{$statement_id} $self->{"dbh"}->prepare($sql)
Truth table66%2/3
A ||= B
A= $self->{$statement_id}B= $self->{"dbh"}->prepare($sql)
ABresult
1X1
011
000
40 8 my $list = $self->{dbh}->selectall_arrayref($self->{$statement_id}, {}, @data);
41 8 ▶ if (scalar(@$list) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$list == 0) { } 3 5 8
42 3 return undef;
43 } else {
44 5 return $list->[0]->[0];
45 }
46 }
47  
48 2 ▶sub _add_project($$) {
Subroutine _add_project: called CC=3 SCAR=11.0
49 2 my ($self, $project) = @_;
50 2 ▶ $self->{st_add_project} ||= $self->{dbh}->prepare('INSERT INTO projects (name) values(?)');
Condition66%2/3
$self->{"st_add_project"} ||= $self->{"dbh"}->prepare("INSERT INTO projects (name) values(?)")
l!l&&r!l&&!r
110
MC/DC0%0/2
$self->{"st_add_project"} ||= $self->{"dbh"}->prepare("INSERT INTO projects (name) values(?)")
$self->{"st_add_project"} $self->{"dbh"}->prepare("INSERT INTO projects (name) values(?)")
Truth table66%2/3
A ||= B
A= $self->{"st_add_project"}B= $self->{"dbh"}->prepare("INSERT INTO projects (name) values(?)")
ABresult
1X1
011
000
51  
52 2 my $project_id = $self->_find_project($project);
53 2 ▶ if (! $project_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($project_id) 1 1 2
54 1 $self->{st_add_project}->execute($project);
55 1 $project_id = $self->_find_project($project);
56 }
57  
58 2 return $project_id;
59 }
60  
61 3 ▶sub _find_project($$) {
Subroutine _find_project: called CC=1 SCAR=0.0
62 3 my ($self, $project) = @_;
63 3 return $self->_find_row_id('SELECT id from projects where name = ?', $project);
64 }
65  
66 2 ▶sub _add_developer($$) {
Subroutine _add_developer: called CC=5 SCAR=16.7
67 2 my ($self, $job) = @_;
68  
69 2 my $metadata = $job->metadata_hashref();
70 2 my $name = $metadata->{author_name};
71 2 my $email = $metadata->{author_email};
72  
73 # FIXME unstested
74 2 ▶ if (!$name || !$email) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name and $email) 0 2 2
Condition33%1/3
$name and $email
!ll&&!rl&&r
002
MC/DC0%0/2
$name and $email
$name $email
Truth table33%1/3
A and B
A= $nameB= $email
ABresult
0X0
100
111
75 0 return undef;
76 }
77  
78 2 ▶ $self->{st_add_developer} ||= $self->{dbh}->prepare('INSERT INTO developers (name,email) VALUES (?,?)');
Condition66%2/3
$self->{"st_add_developer"} ||= $self->{"dbh"}->prepare("INSERT INTO developers (name,email) VALUES (?,?)")
l!l&&r!l&&!r
110
MC/DC0%0/2
$self->{"st_add_developer"} ||= $self->{"dbh"}->prepare("INSERT INTO developers (name,email) VALUES (?,?)")
$self->{"st_add_developer"} $self->{"dbh"}->prepare("INSERT INTO developers (name,email) VALUES (?,?)")
Truth table66%2/3
A ||= B
A= $self->{"st_add_developer"}B= $self->{"dbh"}->prepare("INSERT INTO developers (name,email) VALUES (?,?)")
ABresult
1X1
011
000
79 2 my $developer_id = $self->_find_developer($name, $email);
80 2 ▶ if (! $developer_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($developer_id) 1 1 2
81 1 $self->{st_add_developer}->execute($name, $email);
82 1 $developer_id = $self->_find_developer($name, $email);
83 }
84  
85 2 return $developer_id;
86 }
87  
88 3 ▶sub _find_developer($$$) {
Subroutine _find_developer: called CC=1 SCAR=0.0
89 3 my ($self, $name, $email) = @_;
90 3 return $self->_find_row_id('SELECT id FROM developers WHERE name = ? AND email = ?', $name, $email);
91 }
92  
93 2 ▶sub _add_commit($$$$) {
Subroutine _add_commit: called CC=4 SCAR=14.2
94 2 my ($self, $job, $project_id, $developer_id) = @_;
95 2 ▶ unless ($self->_find_row_id('SELECT id FROM commits where id = ?', $job->id)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_find_row_id("SELECT id FROM commits where id = ?", $job->id)) 1 1 2
96 1 my $metadata = $job->metadata_hashref;
97 1 my $previous_commit_id = $metadata->{previous_commit_id};
98 1 my $date = $metadata->{author_date};
99  
100 1 my ($summary, $details) = ({}, {});
101 1 ▶ if ($job->metrics) {
Branch: 1 branch
BranchTrueFalseTotal
if ($job->metrics) 0 1 1
102 0 ($summary, $details) = $job->metrics->data();
103 }
104 1 my ($metric_placeholders_sql, $metric_column_names_sql, @metric_values) = _metrics_sql($summary, _project_metric_columns());
105  
106 1 ▶ $self->{st_insert_commit} ||= $self->{dbh}->prepare("INSERT INTO commits (id, project_id,developer_id,previous_commit_id,date,$metric_column_names_sql) VALUES(?,?,?,?,?,$metric_placeholders_sql)");
Condition33%1/3
$self->{"st_insert_commit"} ||= $self->{"dbh"}->prepare("INSERT INTO commits (id, project_id,developer_id,previous_commit_id,date,$metric_column_names_sql) VALUES(?,?,?,?,?,$metric_placeholders_sql)")
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"st_insert_commit"} ||= $self->{"dbh"}->prepare("INSERT INTO commits (id, project_id,developer_id,previous_commit_id,date,$metric_column_names_sql) VALUES(?,?,?,?,?,$metric_placeholders_sql)")
$self->{"st_insert_commit"} $self->{"dbh"}->prepare("INSERT INTO commits (id, project_id,developer_id,previous_commit_id,date,$metric_column_names_sql) VALUES(?,?,?,?,?,$metric_placeholders_sql)")
Truth table33%1/3
A ||= B
A= $self->{"st_insert_commit"}B= $self->{"dbh"}->prepare("INSERT INTO commits (id, project_id,developer_id,previous_commit_id,date,$metric_column_names_sql) VALUES(?,?,?,?,?,$metric_placeholders_sql)")
ABresult
1X1
011
000
107 1 $self->{st_insert_commit}->execute($job->id, $project_id, $developer_id, $previous_commit_id, $date, @metric_values);
108 }
109 2 return $job->id;
110 }
111  
112 2 ▶sub _add_modules($$$$) {
Subroutine _add_modules: called CC=12 SCAR=45.9
113 2 my ($self, $job, $commit_id, $project_id) = @_;
114 2 my $metadata = $job->metadata_hashref();
115  
116 2 my %module_versions = ();
117 2 ▶ if ($metadata->{files}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($metadata->{"files"}) 0 2 2
118 0 for my $file (keys(%{$metadata->{files}})) {
119 0 for my $module ($job->model->module_by_file($file)) {
120 0 ▶ unless($module_versions{$module}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module_versions{$module}) 0 0 0
121 0 my $module_id = $self->_add_module($module, $project_id);
122  
123 0 my $module_files = $job->model->files($module);
124 0 my @file_ids = map { $metadata->{files}->{$_} } sort(@$module_files);
125  
126 0 my $module_version_id = _module_version_id(@file_ids);
127  
128 0 my $metrics = $job->metrics->metrics_for($module);
129  
130 0 $self->_add_module_version($commit_id, $module_id, $module_version_id, %$metrics);
131 0 $module_versions{$module} = $module_version_id;
132 }
133 }
134 }
135 }
136  
137 2 ▶ if ($metadata->{changed_files}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($metadata->{"changed_files"}) 0 2 2
138 0 my %already_marked = ();
139 0 for my $file (keys(%{$metadata->{changed_files}})) {
140 0 for my $module ($job->model->module_by_file($file)) {
141 0 ▶ next if $already_marked{$module};
Branch: 1 branch
BranchTrueFalseTotal
if $already_marked{$module} 0 0 0
142 0 $already_marked{$module} = 1;
143  
144 0 my $module_version_id = $module_versions{$module};
145  
146 0 my $module_files = $job->model->files($module);
147 0 ▶ my @statuses = map { $metadata->{changed_files}->{$_} || 'K' } @$module_files;
Condition0%0/2
$metadata->{'changed_files'}{$_} || 'K'
l!l
00
MC/DC0%0/1
$metadata->{'changed_files'}{$_} || 'K'
$metadata->{'changed_files'}{$_}
Truth table0%0/2
A
A= $metadata->{'changed_files'}{$_}
Aresult
11
00
148 0 my $statuses = join('', @statuses);
149  
150 0 ▶ if ($statuses =~ /^A+$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($statuses =~ /^A+$/) { } 0 0 0
elsif (not $statuses =~ /^D+$/) { } 0 0 0
151 0 $self->_mark_as_added($commit_id, $module_version_id);
152 } elsif ($statuses !~ /^D+$/) {
153 0 $self->_mark_as_modified($commit_id, $module_version_id);
154 }
155 }
156 }
157 }
158 }
159  
160 0 ▶sub _add_module($$$) {
Subroutine _add_module: not called CC=3 SCAR=24.8
161 0 my ($self, $module, $project_id) = @_;
162  
163 0 my $module_id = $self->_find_module($module, $project_id);
164 0 ▶ if (!$module_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module_id) 0 0 0
165 0 ▶ $self->{st_add_module} ||= $self->{dbh}->prepare('INSERT INTO modules (name, project_id) values (?,?)');
Condition0%0/3
$self->{"st_add_module"} ||= $self->{"dbh"}->prepare("INSERT INTO modules (name, project_id) values (?,?)")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"st_add_module"} ||= $self->{"dbh"}->prepare("INSERT INTO modules (name, project_id) values (?,?)")
$self->{"st_add_module"} $self->{"dbh"}->prepare("INSERT INTO modules (name, project_id) values (?,?)")
Truth table0%0/3
A ||= B
A= $self->{"st_add_module"}B= $self->{"dbh"}->prepare("INSERT INTO modules (name, project_id) values (?,?)")
ABresult
1X1
011
000
166 0 $self->{st_add_module}->execute($module, $project_id);
167 0 $module_id = $self->_find_module($module, $project_id);
168 }
169  
170 0 return $module_id;
171 }
172  
173 0 ▶sub _find_module($$$) {
Subroutine _find_module: not called CC=1 SCAR=6.9
174 0 my ($self, $module, $project_id) = @_;
175 0 return $self->_find_row_id('SELECT id FROM modules WHERE name = ? AND project_id = ?', $module, $project_id);
176 }
177  
178 0 ▶sub _module_version_id {
Subroutine _module_version_id: not called CC=2 SCAR=17.9
179 0 my @file_ids = @_;
180 0 my $module_version_id;
181 0 ▶ if (scalar(@file_ids) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @file_ids == 1) { } 0 0 0
182 0 $module_version_id = $file_ids[0];
183 } else {
184 0 $module_version_id = sha1_hex(join('', @file_ids));
185 }
186 0 return $module_version_id;
187 }
188  
189 0 ▶sub _add_module_version {
Subroutine _add_module_version: not called CC=4 SCAR=30.0
190 0 my ($self, $commit_id, $module_id, $module_version_id, %metrics) = @_;
191 0 my $module_version_already_exists = $self->_find_row_id('SELECT id from module_versions WHERE module_id = ? AND id = ?', $module_id, $module_version_id);
192 0 ▶ unless ($module_version_already_exists) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module_version_already_exists) 0 0 0
193  
194 0 my ($metric_placeholders_sql, $metric_column_names_sql, @metric_values) = _metrics_sql(\%metrics, _module_metric_columns());
195  
196 0 my $statement = "INSERT INTO module_versions (id,module_id,$metric_column_names_sql) VALUES (?,?,$metric_placeholders_sql)";
197 0 ▶ $self->{st_add_module_version} ||= $self->{dbh}->prepare($statement);
Condition0%0/3
$self->{"st_add_module_version"} ||= $self->{"dbh"}->prepare($statement)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"st_add_module_version"} ||= $self->{"dbh"}->prepare($statement)
$self->{"st_add_module_version"} $self->{"dbh"}->prepare($statement)
Truth table0%0/3
A ||= B
A= $self->{"st_add_module_version"}B= $self->{"dbh"}->prepare($statement)
ABresult
1X1
011
000
198 0 $self->{st_add_module_version}->execute($module_version_id, $module_id, @metric_values);
199 }
200  
201 0 ▶ $self->{st_link_commit_and_module_version} ||= $self->{dbh}->prepare('INSERT INTO commits_module_versions (commit_id,module_version_id) VALUES (?,?)');
Condition0%0/3
$self->{"st_link_commit_and_module_version"} ||= $self->{"dbh"}->prepare("INSERT INTO commits_module_versions (commit_id,module_version_id) VALUES (?,?)")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"st_link_commit_and_module_version"} ||= $self->{"dbh"}->prepare("INSERT INTO commits_module_versions (commit_id,module_version_id) VALUES (?,?)")
$self->{"st_link_commit_and_module_version"} $self->{"dbh"}->prepare("INSERT INTO commits_module_versions (commit_id,module_version_id) VALUES (?,?)")
Truth table0%0/3
A ||= B
A= $self->{"st_link_commit_and_module_version"}B= $self->{"dbh"}->prepare("INSERT INTO commits_module_versions (commit_id,module_version_id) VALUES (?,?)")
ABresult
1X1
011
000
202 0 $self->{st_link_commit_and_module_version}->execute($commit_id, $module_version_id);
203  
204 0 return $module_version_id;
205 }
206  
207 0 ▶sub _mark_as_added($$$) {
Subroutine _mark_as_added: not called CC=2 SCAR=17.9
208 0 my ($self, $commit_id, $module_version_id) = @_;
209 0 ▶ $self->{st_mark_as_added} ||= $self->{dbh}->prepare('UPDATE commits_module_versions SET added = 1 WHERE commit_id = ? AND module_version_id = ?');
Condition0%0/3
$self->{"st_mark_as_added"} ||= $self->{"dbh"}->prepare("UPDATE commits_module_versions SET added = 1 WHERE commit_id = ? AND module_version_id = ?")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"st_mark_as_added"} ||= $self->{"dbh"}->prepare("UPDATE commits_module_versions SET added = 1 WHERE commit_id = ? AND module_version_id = ?")
$self->{"st_mark_as_added"} $self->{"dbh"}->prepare("UPDATE commits_module_versions SET added = 1 WHERE commit_id = ? AND module_version_id = ?")
Truth table0%0/3
A ||= B
A= $self->{"st_mark_as_added"}B= $self->{"dbh"}->prepare("UPDATE commits_module_versions SET added = 1 WHERE commit_id = ? AND module_version_id = ?")
ABresult
1X1
011
000
210 0 $self->{st_mark_as_added}->execute($commit_id, $module_version_id);
211 }
212  
213 0 ▶sub _mark_as_modified($$$) {
Subroutine _mark_as_modified: not called CC=2 SCAR=17.9
214 0 my ($self, $commit_id, $module_version_id) = @_;
215 0 ▶ $self->{st_mark_as_modified} ||= $self->{dbh}->prepare('UPDATE commits_module_versions SET modified = 1 WHERE commit_id = ? AND module_version_id = ?');
Condition0%0/3
$self->{"st_mark_as_modified"} ||= $self->{"dbh"}->prepare("UPDATE commits_module_versions SET modified = 1 WHERE commit_id = ? AND module_version_id = ?")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"st_mark_as_modified"} ||= $self->{"dbh"}->prepare("UPDATE commits_module_versions SET modified = 1 WHERE commit_id = ? AND module_version_id = ?")
$self->{"st_mark_as_modified"} $self->{"dbh"}->prepare("UPDATE commits_module_versions SET modified = 1 WHERE commit_id = ? AND module_version_id = ?")
Truth table0%0/3
A ||= B
A= $self->{"st_mark_as_modified"}B= $self->{"dbh"}->prepare("UPDATE commits_module_versions SET modified = 1 WHERE commit_id = ? AND module_version_id = ?")
ABresult
1X1
011
000
216 0 $self->{st_mark_as_modified}->execute($commit_id, $module_version_id);
217 }
218  
219 1 ▶sub _metrics_sql($@) {
Subroutine _metrics_sql: called CC=1 SCAR=0.0
220 1 my ($metrics_hash, @metric_columns) = @_;
221 1 my $metric_placeholders_sql = join(',', map { '?' } @metric_columns);
222 1 my $metric_column_names_sql = join(',', @metric_columns);
223 1 my @metric_values = map { $metrics_hash->{$_} } @metric_columns;
224 1 return ($metric_placeholders_sql, $metric_column_names_sql, @metric_values)
225 }
226  
227 # Initializes the database
228 #
229 # TODO the current approach of feeding DDL SQL statements directly to the
230 # database handle might not be good enough, since the SQL being written might
231 # not be portable to other databases than SQLite. It would be nice to have
232 # something similar to the rails migrations DSL here.
233 2 ▶sub initialize($) {
Subroutine initialize: called CC=3 SCAR=11.0
Pod undocumented
234 2 my ($self) = @_;
235 2 $self->{dbh} = DBI->connect($self->database, undef, undef, { RaiseError => 1, InactiveDestroy => 1});
236 # assume that if there is a table called `analizo_metadata`, then the database was already initialized
237 2 ▶ if (!grep { $_ =~ /analizo_metadata/ } $self->{dbh}->tables()) {
Branch: 1 branch
BranchTrueFalseTotal
if (not grep({$_ =~ /analizo_metadata/;} $self->{"dbh"}->tables)) 2 0 2
238 2 for my $statement (ddl_statements()) {
239 20 $statement =~ s/\@\@MODULE_METRICS\@\@/_metric_columns_ddl(_module_metric_columns())/egm;
240 20 $statement =~ s/\@\@PROJECT_METRICS\@\@/_metric_columns_ddl(_project_metric_columns())/egm;
241 20 $statement =~ s/\@\@NUMERIC_AUTOINC_PK\@\@/_numeric_autoinc_pk($self->database)/egm;
242 20 $self->{dbh}->do($statement);
243 }
244 }
245 }
246  
247 1 my $DDL_INITIALIZED = 0;
248 1 my @DDL_STATEMENTS = ();
249 2 ▶sub ddl_statements($) {
Subroutine ddl_statements: called CC=4 SCAR=13.9
Pod undocumented
250 2 ▶ if (!$DDL_INITIALIZED) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($DDL_INITIALIZED) 1 1 2
251 1 my $sql = '';
252 1 ▶ while (my $line = <DATA>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline DATA)) 51 1 52
253 51 $sql .= $line;
254 51 ▶ if ($line =~ /;\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /;\s*$/) 10 41 51
255 # SQL statement is ready
256 10 CORE::push @DDL_STATEMENTS, $sql;
257 10 $sql = '';
258 }
259 }
260 1 $DDL_INITIALIZED = 1;
261 }
262 2 return @DDL_STATEMENTS;
263 }
264  
265 1 ▶use Analizo::Metrics;
Subroutine BEGIN: called CC=1 SCAR=0.0
266 1 ▶use Analizo::Model;
Subroutine BEGIN: called CC=1 SCAR=0.0
267 1 my $__metric_columns = undef;
268 5 ▶sub _metric_columns() {
Subroutine _metric_columns: called CC=2 SCAR=6.9
269 5 ▶ if (!$__metric_columns) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($__metric_columns) 1 4 5
270 1 my $metrics = Analizo::Metrics->new(model => Analizo::Model->new);
271  
272 1 my %module_metrics = $metrics->list_of_metrics();
273 1 my @module_metrics= keys(%module_metrics);
274  
275 1 my %project_metrics = $metrics->list_of_global_metrics();
276 1 my @project_metrics = keys(%project_metrics);
277  
278 1 $__metric_columns = {
279 module => \@module_metrics,
280 project => \@project_metrics,
281 };
282 }
283 5 return $__metric_columns;
284 }
285  
286 2 ▶sub _module_metric_columns() {
Subroutine _module_metric_columns: called CC=1 SCAR=0.0
287 2 return @{ _metric_columns()->{module} };
288 }
289  
290 3 ▶sub _project_metric_columns() {
Subroutine _project_metric_columns: called CC=1 SCAR=0.0
291 3 return @{ _metric_columns()->{project} };
292 }
293  
294 4 ▶sub _metric_columns_ddl {
Subroutine _metric_columns_ddl: called CC=1 SCAR=0.0
295 4 my @columns = @_;
296 4 my $ddl = join(",\n ", map { "$_ REAL"} @columns);
297 4 return $ddl;
298 }
299  
300 1 my %NUMERIC_AUTOINC_PK = (
301 'sqlite' => 'INTEGER PRIMARY KEY AUTOINCREMENT',
302 'pg' => 'SERIAL PRIMARY KEY',
303 );
304  
305 8 ▶sub _numeric_autoinc_pk($) {
Subroutine _numeric_autoinc_pk: called CC=2 SCAR=7.0
306 8 my ($database) = @_;
307 8 my $dbtype = lc($database);
308 8 $dbtype =~ s/^dbi:(.*):.*/$1/;
309 8 my $sql = $NUMERIC_AUTOINC_PK{$dbtype};
310 8 ▶ die("Database $dbtype is not supported!") if (!defined($sql));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sql 0 8 8
311 8 return $sql;
312 }
313  
314 1 1;
315  
316 __DATA__
« Analizo/Command/files_graph.pm ↑ Summary Analizo/Batch/Output/CSV.pm »