File Coverage

blib/lib/App/CPANIDX/Queries.pm
Criterion Covered Total %
statement 22 22 100.0
branch 6 10 60.0
condition n/a
subroutine 6 6 100.0
pod 2 2 100.0
total 36 40 90.0


line stmt bran cond sub pod time code
1             package App::CPANIDX::Queries;
2              
3 2     2   58801 use strict;
  2         2  
  2         46  
4 2     2   6 use warnings;
  2         2  
  2         38  
5 2     2   434 use Module::CoreList::DBSchema;
  2         44294  
  2         47  
6 2     2   10 use vars qw[$VERSION];
  2         2  
  2         355  
7              
8             $VERSION = '0.38';
9              
10             my $mcdbs = Module::CoreList::DBSchema->new();
11              
12             my %queries = (
13             'mod' => [ 'select mods.mod_name,mods.mod_vers,mods.cpan_id,dists.dist_name,dists.dist_vers,dists.dist_file from mods,dists where mod_name = ? and mods.dist_name = dists.dist_name and mods.dist_vers = dists.dist_vers', 1 ],
14             'dist' => [ 'select * from dists where dist_name = ?', 1 ],
15             'auth' => [ 'select * from auths where cpan_id = ?', 1 ],
16             'dists' => [ 'select * from dists where cpan_id = ?', 1 ],
17             'perms' => [ 'select * from perms where mod_name = ?', 1 ],
18             'timestamp' => [ 'select * from timestamp', 0 ],
19             'firstmod' => [ 'select mod_name from mods order by mod_name limit 1', 0 ],
20             'nextmod' => [ 'select mod_name from mods order by mod_name limit ?,1', 1 ],
21             'firstauth' => [ 'select cpan_id from auths order by cpan_id limit 1', 0 ],
22             'nextauth' => [ 'select cpan_id from auths order by cpan_id limit ?,1', 1 ],
23             'modkeys' => [ 'select mod_name from mods order by mod_name', 0 ],
24             'authkeys' => [ 'select cpan_id from auths order by cpan_id', 0 ],
25             'topten' => [ 'select cpan_id, count(*) as "dists" from dists group by cpan_id order by count(*) desc limit 10', 0 ],
26             'mirrors', => [ 'select * from mirrors', 0 ],
27             );
28              
29             foreach my $query ( $mcdbs->queries() ) {
30             $queries{ $query } = $mcdbs->query( $query );
31             }
32              
33             sub query {
34 30 50   30 1 19063 return unless @_;
35 30         23 my $query = shift;
36 30 50       73 $query = shift if $query->isa(__PACKAGE__);
37 30 50       37 return unless $query;
38 30 50       41 return unless exists $queries{ $query };
39 30         25 my $sql = $queries{ $query };
40 30 100       39 return @{ $sql } if wantarray;
  15         33  
41 15         16 return $sql;
42             }
43              
44             sub queries {
45 1     1 1 488 return keys %queries;
46             }
47              
48             1;
49              
50             __END__