line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPANPLUS::Internals::Source::SQLite::Tie; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
15
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
58
|
|
4
|
2
|
|
|
2
|
|
20
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
69
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
12
|
use CPANPLUS::Error; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
111
|
|
7
|
2
|
|
|
2
|
|
14
|
use CPANPLUS::Module; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
51
|
|
8
|
2
|
|
|
2
|
|
11
|
use CPANPLUS::Module::Fake; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
64
|
|
9
|
2
|
|
|
2
|
|
10
|
use CPANPLUS::Module::Author::Fake; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
39
|
|
10
|
2
|
|
|
2
|
|
10
|
use CPANPLUS::Internals::Constants; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
761
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
16
|
use Params::Check qw[check]; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
97
|
|
13
|
2
|
|
|
2
|
|
12
|
use Module::Load::Conditional qw[can_load]; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
95
|
|
14
|
2
|
|
|
2
|
|
13
|
use Locale::Maketext::Simple Class => 'CPANPLUS', Style => 'gettext'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
490
|
use vars qw[@ISA $VERSION]; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1497
|
|
17
|
|
|
|
|
|
|
$VERSION = "0.9912"; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
require Tie::Hash; |
20
|
|
|
|
|
|
|
push @ISA, 'Tie::StdHash'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub TIEHASH { |
24
|
0
|
|
|
0
|
|
|
my $class = shift; |
25
|
0
|
|
|
|
|
|
my %hash = @_; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $tmpl = { |
28
|
|
|
|
|
|
|
dbh => { required => 1 }, |
29
|
|
|
|
|
|
|
table => { required => 1 }, |
30
|
|
|
|
|
|
|
key => { required => 1 }, |
31
|
|
|
|
|
|
|
cb => { required => 1 }, |
32
|
|
|
|
|
|
|
offset => { default => 0 }, |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
my $args = check( $tmpl, \%hash ) or return; |
36
|
0
|
|
|
|
|
|
my $obj = bless { %$args, store => {} } , $class; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
return $obj; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub FETCH { |
42
|
0
|
|
|
0
|
|
|
my $self = shift; |
43
|
0
|
0
|
|
|
|
|
my $key = shift or return; |
44
|
0
|
|
|
|
|
|
my $dbh = $self->{dbh}; |
45
|
0
|
|
|
|
|
|
my $cb = $self->{cb}; |
46
|
0
|
|
|
|
|
|
my $table = $self->{table}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
### did we look this one up before? |
50
|
0
|
0
|
|
|
|
|
if( my $obj = $self->{store}->{$key} ) { |
51
|
0
|
|
|
|
|
|
return $obj; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $res = $dbh->query( |
55
|
|
|
|
|
|
|
"SELECT * from $table where $self->{key} = ?", $key |
56
|
0
|
0
|
|
|
|
|
) or do { |
57
|
0
|
|
|
|
|
|
error( $dbh->error ); |
58
|
0
|
|
|
|
|
|
return; |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $href = $res->hash; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
### get rid of the primary key |
64
|
0
|
|
|
|
|
|
delete $href->{'id'}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
### no results? |
67
|
0
|
0
|
|
|
|
|
return unless keys %$href; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
### expand author if needed |
70
|
|
|
|
|
|
|
### XXX no longer generic :( |
71
|
0
|
0
|
|
|
|
|
if( $table eq 'module' ) { |
72
|
0
|
0
|
|
|
|
|
$href->{author} = $cb->author_tree( $href->{author } ) or return; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $class = { |
76
|
|
|
|
|
|
|
module => 'CPANPLUS::Module', |
77
|
|
|
|
|
|
|
author => 'CPANPLUS::Module::Author', |
78
|
0
|
|
|
|
|
|
}->{ $table }; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my $obj = $self->{store}->{$key} = $class->new( %$href, _id => $cb->_id ); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return $obj; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub STORE { |
86
|
0
|
|
|
0
|
|
|
my $self = shift; |
87
|
0
|
|
|
|
|
|
my $key = shift; |
88
|
0
|
|
|
|
|
|
my $val = shift; |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$self->{store}->{$key} = $val; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
1; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub FIRSTKEY { |
96
|
0
|
|
|
0
|
|
|
my $self = shift; |
97
|
0
|
|
|
|
|
|
my $dbh = $self->{'dbh'}; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $res = $dbh->query( |
100
|
|
|
|
|
|
|
"select $self->{key} from $self->{table} order by $self->{key} limit 1" |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$self->{offset} = 0; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $key = $res->flat->[0]; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return $key; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub NEXTKEY { |
111
|
0
|
|
|
0
|
|
|
my $self = shift; |
112
|
0
|
|
|
|
|
|
my $dbh = $self->{'dbh'}; |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
my $res = $dbh->query( |
115
|
|
|
|
|
|
|
"select $self->{key} from $self->{table} ". |
116
|
|
|
|
|
|
|
"order by $self->{key} limit 1 offset $self->{offset}" |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
$self->{offset} +=1; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
my $key = $res->flat->[0]; |
122
|
0
|
|
|
|
|
|
my $val = $self->FETCH( $key ); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
### use each() semantics |
125
|
0
|
0
|
|
|
|
|
return wantarray ? ( $key, $val ) : $key; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
0
|
|
|
sub EXISTS { !!$_[0]->FETCH( $_[1] ) } |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub SCALAR { |
131
|
0
|
|
|
0
|
|
|
my $self = shift; |
132
|
0
|
|
|
|
|
|
my $dbh = $self->{'dbh'}; |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my $res = $dbh->query( "select count(*) from $self->{table}" ); |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
return $res->flat; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
### intentionally left blank |
140
|
|
|
|
0
|
|
|
sub DELETE { } |
141
|
|
|
|
0
|
|
|
sub CLEAR { } |
142
|
|
|
|
|
|
|
|