line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::DB::Sqlite; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
18922
|
use 5.014; |
|
1
|
|
|
|
|
4
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use Venus::Class; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'Venus::Role::Optional'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
1913
|
use DBI; |
|
1
|
|
|
|
|
17191
|
|
|
1
|
|
|
|
|
46
|
|
13
|
1
|
|
|
1
|
|
493
|
use File::Copy (); |
|
1
|
|
|
|
|
2316
|
|
|
1
|
|
|
|
|
24
|
|
14
|
1
|
|
|
1
|
|
6
|
use File::Spec (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
13
|
|
15
|
1
|
|
|
1
|
|
729
|
use File::Temp (); |
|
1
|
|
|
|
|
9552
|
|
|
1
|
|
|
|
|
465
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# ATTRIBUTES |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
attr 'dbh'; |
24
|
|
|
|
|
|
|
attr 'dsn'; |
25
|
|
|
|
|
|
|
attr 'file'; |
26
|
|
|
|
|
|
|
attr 'uri'; |
27
|
|
|
|
|
|
|
attr 'database'; |
28
|
|
|
|
|
|
|
attr 'template'; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# OPTIONS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub lazy_build_dbh { |
33
|
0
|
|
|
0
|
0
|
|
my ($self, $data) = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
0
|
|
|
|
$data ||= DBI->connect($self->dsn, '', '', { RaiseError => 1, AutoCommit => 1 }); |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
return $data; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub lazy_build_dsn { |
41
|
0
|
|
|
0
|
0
|
|
my ($self, $data) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
return $data ? $data : "dbi:SQLite:dbname=@{[$self->file]}"; |
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub lazy_build_file { |
47
|
0
|
|
|
0
|
0
|
|
my ($self, $data) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $database = $self->database; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
return $data ? $data : File::Spec->catfile(File::Temp::tempdir, "$database.db"); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub lazy_build_uri { |
55
|
0
|
|
|
0
|
0
|
|
my ($self, $data) = @_; |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
return $data ? $data : "sqlite:@{[$self->file]}"; |
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub lazy_build_database { |
61
|
0
|
|
|
0
|
0
|
|
my ($self, $data) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
return $data ? $data : join '_', 'testing_db', time, $$, sprintf "%04d", rand 999; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub lazy_build_template { |
67
|
0
|
|
|
0
|
0
|
|
my ($self, $data) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
return $data ? $data : $ENV{TESTDB_TEMPLATE}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# METHODS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub clone { |
75
|
0
|
|
|
0
|
1
|
|
my ($self, $file) = @_; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
0
|
|
|
|
File::Copy::copy($file || $self->template, $self->file); |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return $self->create; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub create { |
83
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $dbh = $self->dbh; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$self->uri; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return $self; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub destroy { |
93
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $file = $self->file; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
unlink $file; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
return $self; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 NAME |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Test::DB::Sqlite - Temporary Testing Databases for Sqlite |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 ABSTRACT |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Temporary Sqlite Database for Testing |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 VERSION |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
0.10 |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SYNOPSIS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
package main; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
use Test::DB::Sqlite; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $tdbo = Test::DB::Sqlite->new; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# my $dbh = $tdbo->create->dbh; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 DESCRIPTION |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This package provides methods for generating and destroying Sqlite databases |
139
|
|
|
|
|
|
|
for testing purposes. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This package has the following attributes: |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 dbh |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
dbh(Object) |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This attribute is read-only, accepts C<(Object)> values, and is optional. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 dsn |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
dsn(Str) |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This attribute is read-only, accepts C<(Str)> values, and is optional. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 database |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
database(Str) |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
This attribute is read-only, accepts C<(Str)> values, and is optional. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=cut |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 file |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
file(Str) |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This attribute is read-only, accepts C<(Str)> values, and is optional. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 uri |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
uri(Str) |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This attribute is read-only, accepts C<(Str)> values, and is optional. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 METHODS |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This package provides the following methods: |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 clone |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
clone(Str $source) : Object |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
The clone method creates a temporary database from a database template. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=over 4 |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item clone example 1 |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# given: synopsis |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
$tdbo->clone('source.db'); |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
# |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=back |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=cut |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head2 create |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
create() : Object |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
The create method creates a temporary database and returns the invocant. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=over 4 |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item create example 1 |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
# given: synopsis |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
$tdbo->create; |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=back |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=cut |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head2 destroy |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
destroy() : Object |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
The destroy method destroys (drops) the database and returns the invocant. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=over 4 |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=item destroy example 1 |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
# given: synopsis |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
$tdbo->create; |
248
|
|
|
|
|
|
|
$tdbo->destroy; |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
# |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=back |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=cut |