line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPAN::Digger::DB; |
2
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.03'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1491
|
use DBI; |
|
1
|
|
|
|
|
17704
|
|
|
1
|
|
|
|
|
94
|
|
8
|
1
|
|
|
1
|
|
11
|
use Exporter qw(import); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
9
|
1
|
|
|
1
|
|
710
|
use File::HomeDir (); |
|
1
|
|
|
|
|
5655
|
|
|
1
|
|
|
|
|
28
|
|
10
|
1
|
|
|
1
|
|
440
|
use FindBin (); |
|
1
|
|
|
|
|
1043
|
|
|
1
|
|
|
|
|
31
|
|
11
|
1
|
|
|
1
|
|
7
|
use Path::Tiny qw(path); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1049
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw(get_fields); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my @fields = qw(distribution version author date vcs_url vcs_name travis github_actions appveyor circleci has_ci license issues azure_pipelines); |
16
|
|
|
|
|
|
|
sub get_fields { |
17
|
1
|
|
|
1
|
0
|
5
|
return @fields; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
1
|
|
|
1
|
0
|
18
|
my ($class, %args) = @_; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
3
|
my $self = bless {}, $class; |
25
|
1
|
|
|
|
|
5
|
for my $key (keys %args) { |
26
|
1
|
|
|
|
|
6
|
$self->{$key} = $args{$key}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
4
|
my $dbh = $self->{dbh} = $self->get_db(); |
30
|
1
|
|
|
|
|
6
|
$self->{sth_get_distro} = $dbh->prepare('SELECT * FROM dists WHERE distribution=?'); |
31
|
1
|
|
|
|
|
92
|
$self->{sth_get_every_distro} = $dbh->prepare('SELECT * FROM dists ORDER by date DESC'); |
32
|
1
|
|
|
|
|
93
|
my $fields = join ', ', @fields; |
33
|
1
|
|
|
|
|
6
|
my $places = join ', ', ('?') x scalar @fields; |
34
|
1
|
|
|
|
|
9
|
$self->{sth_insert} = $dbh->prepare("INSERT INTO dists ($fields) VALUES ($places)"); |
35
|
1
|
|
|
|
|
117
|
$self->{sth_delete} = $dbh->prepare("DELETE FROM dists WHERE distribution=?"); |
36
|
1
|
|
|
|
|
77
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get_db { |
41
|
1
|
|
|
1
|
0
|
13
|
my ($self) = @_; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Default to in-memory database |
44
|
1
|
|
|
|
|
4
|
my $db_file = ':memory:'; |
45
|
1
|
|
|
|
|
2
|
my $exists = undef; |
46
|
|
|
|
|
|
|
|
47
|
1
|
50
|
|
|
|
4
|
if ($self->{db}) { |
48
|
0
|
|
|
|
|
0
|
$db_file = $self->{db}; |
49
|
0
|
|
|
|
|
0
|
$exists = -e $db_file; |
50
|
|
|
|
|
|
|
} |
51
|
1
|
|
|
|
|
17
|
my $dbh = DBI->connect( "dbi:SQLite:dbname=$db_file", "", "", { |
52
|
|
|
|
|
|
|
PrintError => 0, |
53
|
|
|
|
|
|
|
RaiseError => 1, |
54
|
|
|
|
|
|
|
AutoCommit => 1, |
55
|
|
|
|
|
|
|
FetchHashKeyName => 'NAME_lc', |
56
|
|
|
|
|
|
|
}); |
57
|
1
|
50
|
|
|
|
12003
|
if (not $exists) { |
58
|
1
|
|
|
|
|
5
|
local $/ = undef; |
59
|
1
|
|
|
|
|
22
|
my $schema = <DATA>; |
60
|
1
|
|
|
|
|
9
|
$dbh->do($schema); |
61
|
|
|
|
|
|
|
} |
62
|
1
|
|
|
|
|
531
|
return $dbh |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub db_insert_into { |
66
|
2
|
|
|
2
|
0
|
7
|
my ($self, @params) = @_; |
67
|
2
|
|
|
|
|
92
|
$self->{sth_insert}->execute(@params); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# TODO have an update here? |
71
|
|
|
|
|
|
|
sub db_update { |
72
|
0
|
|
|
0
|
0
|
0
|
my ($self, $distribution, @params) = @_; |
73
|
0
|
|
|
|
|
0
|
$self->{sth_delete}->execute($distribution); |
74
|
0
|
|
|
|
|
0
|
$self->{sth_insert}->execute(@params); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub db_get_distro { |
79
|
2
|
|
|
2
|
0
|
20
|
my ($self, $distribution) = @_; |
80
|
|
|
|
|
|
|
|
81
|
2
|
|
|
|
|
46
|
$self->{sth_get_distro}->execute($distribution); |
82
|
2
|
|
|
|
|
45
|
my $row = $self->{sth_get_distro}->fetchrow_hashref; |
83
|
2
|
|
|
|
|
9
|
return $row; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub db_get_every_distro { |
87
|
1
|
|
|
1
|
0
|
3
|
my ($self) = @_; |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
22
|
$self->{sth_get_every_distro}->execute; |
90
|
1
|
|
|
|
|
3
|
my @distros; |
91
|
1
|
|
|
|
|
35
|
while (my $row = $self->{sth_get_every_distro}->fetchrow_hashref) { |
92
|
2
|
|
|
|
|
31
|
push @distros, $row; |
93
|
|
|
|
|
|
|
} |
94
|
1
|
|
|
|
|
6
|
return \@distros; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
42; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__DATA__ |
100
|
|
|
|
|
|
|
CREATE TABLE dists ( |
101
|
|
|
|
|
|
|
distribution VARCHAR(255) NOT NULL UNIQUE, |
102
|
|
|
|
|
|
|
date VARCHAR(255), |
103
|
|
|
|
|
|
|
version VARCHAR(255), |
104
|
|
|
|
|
|
|
author VARCHAR(255), |
105
|
|
|
|
|
|
|
license VARCHAR(255), |
106
|
|
|
|
|
|
|
issues VARCHAR(255), |
107
|
|
|
|
|
|
|
vcs_url VARCHAR(255), |
108
|
|
|
|
|
|
|
vcs_name VARCHAR(255), |
109
|
|
|
|
|
|
|
appveyor BOOLEAN, |
110
|
|
|
|
|
|
|
circleci BOOLEAN, |
111
|
|
|
|
|
|
|
travis BOOLEAN, |
112
|
|
|
|
|
|
|
github_actions BOOLEAN, |
113
|
|
|
|
|
|
|
azure_pipelines BOOLEAN, |
114
|
|
|
|
|
|
|
has_ci BOOLEAN |
115
|
|
|
|
|
|
|
); |