File Coverage

blib/lib/Parse/BACKPAN/Packages.pm
Criterion Covered Total %
statement 34 48 70.8
branch 5 10 50.0
condition n/a
subroutine 10 13 76.9
pod 8 8 100.0
total 57 79 72.1


line stmt bran cond sub pod time code
1             package Parse::BACKPAN::Packages;
2              
3 3     3   5928749 use strict;
  3         17  
  3         170  
4 3     3   18 use warnings;
  3         6  
  3         332  
5              
6             our $VERSION = '0.40';
7              
8 3     3   1131 use Mouse;
  3         42893  
  3         26  
9 3     3   1861 use BackPAN::Index::Types;
  3         7  
  3         1653  
10              
11             has no_cache =>
12             is => 'ro',
13             isa => 'Bool',
14             default => 0;
15              
16             has only_authors =>
17             is => 'ro',
18             isa => 'Bool',
19             default => 1
20             ;
21              
22             has _delegate =>
23             is => 'rw',
24             isa => 'BackPAN::Index';
25              
26              
27             sub BUILD {
28 2     2 1 755376 my $self = shift;
29 2         7 my $args = shift;
30              
31             # Translate from PBP options to BackPAN::Index
32 2 50       16 if( exists $args->{no_cache} ) {
33 0         0 $args->{update} = $args->{no_cache};
34             }
35              
36 2 50       10 if( exists $args->{only_authors} ) {
37 0         0 $args->{releases_only_from_authors} = $args->{only_authors};
38             }
39              
40 2         30 require BackPAN::Index;
41 2         33 $self->_delegate( BackPAN::Index->new($args) );
42              
43 2         26 return $self;
44             }
45              
46             our $AUTOLOAD;
47             sub AUTOLOAD {
48 7     7   1213 my $self = shift;
49 7         67 my($method) = $AUTOLOAD =~ /:: ([^:]+) $/x;
50              
51             # Skip things like DESTROY
52 7 50       31 return if uc $method eq $method;
53              
54 7         206 $self->_delegate->$method(@_);
55             }
56              
57             sub files {
58 0     0 1 0 my $self = shift;
59              
60 0         0 my %files;
61 0         0 my $rs = $self->_delegate->files;
62 0         0 while( my $file = $rs->next ) {
63 0         0 $files{$file->path} = $file;
64             }
65            
66 0         0 return \%files;
67             }
68              
69             sub file {
70 1     1 1 51 my ( $self, $path ) = @_;
71              
72 1         8 return $self->_delegate->files->single({ path => $path });
73             }
74              
75             sub releases {
76 1     1 1 3 my($self, $dist) = @_;
77              
78 1         16 return $self->_delegate->releases($dist)->all;
79             }
80              
81              
82             sub distributions {
83 0     0 1 0 my $self = shift;
84              
85             # For backwards compatibilty when releases() was distributions()
86 0 0       0 return $self->releases(shift) if @_;
87              
88 0         0 return [$self->_delegate->distributions->get_column("name")->all];
89             }
90              
91             sub distributions_by {
92 4     4 1 36450 my ( $self, $author ) = @_;
93 4 100       23 return unless $author;
94              
95 3         41 my $dists = $self->db->dbh->selectcol_arrayref(q[
96             SELECT DISTINCT dist
97             FROM releases
98             WHERE cpanid = ?
99             ORDER BY dist
100             ],
101             undef,
102             $author
103             );
104              
105 3         2165 return @$dists;
106             }
107              
108             sub authors {
109 1     1 1 1092 my $self = shift;
110              
111 1         10 my $authors = $self->db->dbh->selectcol_arrayref(q[
112             SELECT DISTINCT cpanid
113             FROM releases
114             ORDER BY cpanid
115             ]);
116              
117 1         212549 return @$authors;
118             }
119              
120             sub size {
121 0     0 1   my $self = shift;
122              
123 0           my $size = $self->db->dbh->selectcol_arrayref(q[
124             SELECT SUM(size) FROM files
125             ]);
126              
127 0           return $size->[0];
128             }
129              
130             1;
131              
132             __END__