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