line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Net::Download::Queue::DBI - Net::Download::Queue::DBI base class
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=cut
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package Net::Download::Queue::DBI;
|
16
|
1
|
|
|
1
|
|
6
|
use base 'Class::DBI::SQLite';
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
878
|
|
17
|
|
|
|
|
|
|
#use base 'Class::DBI::mysql';
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = 0.01;
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
3494859
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
26
|
1
|
|
|
1
|
|
5
|
use File::Basename;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
476
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 CLASS METHODS
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
These must be before the other ones...
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 fileDatabase()
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Return file name of SQLite database.
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut
|
42
|
|
|
|
|
|
|
sub fileDatabase {
|
43
|
2
|
|
|
2
|
1
|
3
|
return("./download-queue.db");
|
44
|
|
|
|
|
|
|
}
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 rebuildDatabase()
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Empty and rebuild the SQLite database.
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Return 1 on success, else die on errors.
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut
|
57
|
|
|
|
|
|
|
sub rebuildDatabase {
|
58
|
0
|
|
|
0
|
1
|
0
|
my $pkg = shift;
|
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
$pkg->db_Main->disconnect; #To avoid it being locked when unlinking
|
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
my $fileDatabase = $pkg->fileDatabase;
|
63
|
0
|
0
|
|
|
|
0
|
unlink($fileDatabase); -f $fileDatabase and die("Could not delete existing database file ($fileDatabase): $!\n");
|
|
0
|
|
|
|
|
0
|
|
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
return( $pkg->ensureDatabase() );
|
66
|
|
|
|
|
|
|
}
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 ensureDatabase()
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Rebuild the SQLite database if it's not present.
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Return 1 on success, else die on errors.
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut
|
79
|
|
|
|
|
|
|
sub ensureDatabase {
|
80
|
1
|
|
|
1
|
1
|
3
|
my $pkg = shift;
|
81
|
1
|
|
|
|
|
4
|
my $fileDatabase = $pkg->fileDatabase;
|
82
|
1
|
50
|
|
|
|
28
|
-f $fileDatabase and return(1);
|
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
0
|
my $fileSql = dirname(__FILE__) . "/database/sqlite/create.sql";
|
85
|
0
|
0
|
|
|
|
0
|
-f $fileSql or die("Could not find SQLite create file ($fileSql)\n");
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# warn "dbish\n";
|
88
|
0
|
|
|
|
|
0
|
`dbish "dbi:SQLite:dbname=$fileDatabase" < "$fileSql" 2>&1`;
|
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
return(1);
|
91
|
|
|
|
|
|
|
}
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__PACKAGE__->ensureDatabase(); #Must be there before set_db
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $fileDatabase = __PACKAGE__->fileDatabase;
|
100
|
|
|
|
|
|
|
my ($dsn, $username, $password) = ("dbi:SQLite:dbname=$fileDatabase", undef, undef);
|
101
|
|
|
|
|
|
|
#my ($dsn, $username, $password) = ("dbi:mysql:database=app;port=3306", "app", "abc123");
|
102
|
|
|
|
|
|
|
__PACKAGE__->set_db('Main', $dsn, $username, $password, { AutoCommit => 1 } );
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
#my $dbh = DBI->connect($dsn, $username, $password) or die("Could not connect to db\n");
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 METHODS
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 CLASS METHODS
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 accessor_name
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Reformat accessor names. Overridden.
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut
|
120
|
14
|
|
|
14
|
1
|
173084
|
sub accessor_name { my $pkg = shift;
|
121
|
14
|
|
|
|
|
24
|
my ($column) = @_;
|
122
|
|
|
|
|
|
|
|
123
|
14
|
|
|
|
|
39
|
$column =~ s/ (_+) (\w) / uc($2) /gex;
|
|
12
|
|
|
|
|
236
|
|
124
|
|
|
|
|
|
|
|
125
|
14
|
|
|
|
|
71
|
return($column);
|
126
|
|
|
|
|
|
|
}
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 search_first
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Like search(), but return the first row.
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut
|
137
|
|
|
|
|
|
|
sub search_first {
|
138
|
0
|
|
|
0
|
1
|
|
my $pkg = shift;
|
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
my $itRow = $pkg->search(@_);
|
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
return($itRow->next);
|
143
|
|
|
|
|
|
|
}
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 oDownloadStatus($name)
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Return DownloadStatus object with $name, or die on errors.
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut
|
154
|
|
|
|
|
|
|
sub oDownloadStatus {
|
155
|
0
|
|
|
0
|
1
|
|
my $pkg = shift;
|
156
|
0
|
|
|
|
|
|
my ($name) = @_;
|
157
|
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
|
my $oStatus = Net::Download::Queue::DownloadStatus->search_first({name => $name}) or die("Could not get status ($name)\n");
|
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
return($oStatus);
|
161
|
|
|
|
|
|
|
}
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
1;
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
__END__
|