line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::App::CPANIDX::Database; |
2
|
|
|
|
|
|
|
$Test::App::CPANIDX::Database::VERSION = '0.06'; |
3
|
|
|
|
|
|
|
# ABSTRACT: generate a test database for App::CPANIDX |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
136856
|
use strict; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
95
|
|
6
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
86
|
|
7
|
4
|
|
|
4
|
|
3448
|
use DBI; |
|
4
|
|
|
|
|
36528
|
|
|
4
|
|
|
|
|
211
|
|
8
|
4
|
|
|
4
|
|
36
|
use File::Spec; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
69
|
|
9
|
4
|
|
|
4
|
|
1705
|
use App::CPANIDX::Tables; |
|
4
|
|
|
|
|
233287
|
|
|
4
|
|
|
|
|
130
|
|
10
|
|
|
|
|
|
|
|
11
|
4
|
|
|
4
|
|
40
|
use constant CPANIDX => 'cpanidx.db'; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
1647
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
4
|
|
|
4
|
1
|
2427
|
my $package = shift; |
15
|
4
|
|
|
|
|
20
|
my %self = @_; |
16
|
4
|
|
|
|
|
35
|
$self{lc $_} = delete $self{$_} for keys %self; |
17
|
4
|
100
|
66
|
|
|
43
|
$self{unlink} = 1 unless defined $self{unlink} and !$self{unlink}; |
18
|
|
|
|
|
|
|
die "Invalid dir specified\n" if |
19
|
4
|
50
|
66
|
|
|
150
|
defined $self{dir} and !( -d File::Spec->rel2abs($self{dir}) ); |
20
|
4
|
100
|
|
|
|
54
|
$self{dir} = File::Spec->rel2abs($self{dir}) if defined $self{dir}; |
21
|
4
|
100
|
|
|
|
51
|
my $db = $self{dir} ? File::Spec->catfile( $self{dir}, CPANIDX ) : CPANIDX; |
22
|
|
|
|
|
|
|
|
23
|
4
|
50
|
|
|
|
52
|
my $dbh = DBI->connect("dbi:SQLite:dbname=$db",'','') or die $DBI::errstr; |
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
|
|
41601
|
foreach my $table ( App::CPANIDX::Tables->tables() ) { |
26
|
84
|
|
|
|
|
633812
|
my $sql = App::CPANIDX::Tables->table( $table ); |
27
|
84
|
50
|
|
|
|
3675
|
$dbh->do($sql) or die $dbh->errstr; |
28
|
84
|
50
|
|
|
|
1655896
|
$dbh->do('DELETE FROM ' . $table) or die $dbh->errstr; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
4
|
|
|
|
|
25530
|
my $statements = { |
32
|
|
|
|
|
|
|
auths => qq{INSERT INTO auths values (?,?,?)}, |
33
|
|
|
|
|
|
|
mods => qq{INSERT INTO mods values (?,?,?,?,?)}, |
34
|
|
|
|
|
|
|
dists => qq{INSERT INTO dists values (?,?,?,?)}, |
35
|
|
|
|
|
|
|
timestamp => qq{INSERT INTO timestamp values(?,?)}, |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
4
|
|
66
|
|
|
69
|
my $stamp = ( $self{time} || time() ); |
39
|
4
|
|
|
|
|
48
|
my $data = [ |
40
|
|
|
|
|
|
|
[ 'auths', 'FOOBAR', 'Foo Bar', 'foobar@cpan.org' ], |
41
|
|
|
|
|
|
|
[ 'mods', 'Foo::Bar','Foo-Bar','0.01','FOOBAR','0.01' ], |
42
|
|
|
|
|
|
|
[ 'dists', 'Foo-Bar','FOOBAR','F/FO/FOOBAR/Foo-Bar-0.01.tar.gz','0.01' ], |
43
|
|
|
|
|
|
|
[ 'timestamp', $stamp, $stamp ], |
44
|
|
|
|
|
|
|
]; |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
12
|
foreach my $datum ( @{ $data } ) { |
|
4
|
|
|
|
|
20
|
|
47
|
16
|
|
|
|
|
84
|
my $table = shift @{ $datum }; |
|
16
|
|
|
|
|
67
|
|
48
|
16
|
|
|
|
|
54
|
my $sql = $statements->{ $table }; |
49
|
16
|
50
|
|
|
|
161
|
my $sth = $dbh->prepare($sql) or die $dbh->errstr; |
50
|
16
|
|
|
|
|
1547
|
$sth->execute( @{ $datum } ); |
|
16
|
|
|
|
|
104852
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
4
|
|
|
|
|
947
|
return bless \%self, $package; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub dbfile { |
57
|
8
|
|
|
8
|
1
|
2895
|
my $self = shift; |
58
|
|
|
|
|
|
|
return |
59
|
8
|
100
|
|
|
|
165
|
$self->{dir} ? File::Spec->catfile( $self->{dir}, CPANIDX ) : CPANIDX; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub DESTROY { |
63
|
4
|
|
|
4
|
|
4008
|
my $self = shift; |
64
|
4
|
100
|
|
|
|
27
|
return unless $self->{unlink}; |
65
|
3
|
100
|
|
|
|
27
|
my $db = $self->{dir} ? File::Spec->catfile( $self->{dir}, CPANIDX ) : CPANIDX; |
66
|
3
|
|
|
|
|
396
|
unlink $db; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
__END__ |