1 package Parse::BACKPAN::Packages;
8 use parent qw(Class::Accessor::Fast);
12 __PACKAGE__->mk_accessors(qw(
20 # Translate from PBP options to BackPAN::Index
21 $options->{update} = 1 if $options->{no_cache};
22 $options->{releases_only_from_authors} = $options->{only_authors};
24 my $backpan = BackPAN::Index->new($options);
25 return $class->SUPER::new({ _delegate => $backpan });
31 my($method) = $AUTOLOAD =~ /:: ([^:]+) $/x;
33 # Skip things like DESTROY
34 return if uc $method eq $method;
36 $self->_delegate->$method(@_);
43 my $rs = $self->_delegate->files;
44 while( my $file = $rs->next ) {
45 $files{$file->path} = $file;
52 my ( $self, $path ) = @_;
54 return $self->_delegate->files->single({ path => $path });
58 my($self, $dist) = @_;
60 return $self->_delegate->releases($dist)->all;
67 # For backwards compatibilty when releases() was distributions()
68 return $self->releases(shift) if @_;
70 return [$self->_delegate->distributions->get_column("name")->all];
73 sub distributions_by {
74 my ( $self, $author ) = @_;
75 return unless $author;
77 my $dists = $self->_dbh->selectcol_arrayref(q[
93 my $authors = $self->_dbh->selectcol_arrayref(q[
94 SELECT DISTINCT cpanid
105 my $size = $self->_dbh->selectcol_arrayref(q[
106 SELECT SUM(size) FROM files
118 Parse::BACKPAN::Packages - Provide an index of BACKPAN
122 use Parse::BACKPAN::Packages;
123 my $p = Parse::BACKPAN::Packages->new();
124 print "BACKPAN is " . $p->size . " bytes\n";
126 my @filenames = keys %$p->files;
128 # see Parse::BACKPAN::Packages::File
129 my $file = $p->file("authors/id/L/LB/LBROCARD/Acme-Colour-0.16.tar.gz");
130 print "That's " . $file->size . " bytes\n";
132 # see Parse::BACKPAN::Packages::Release
133 my @acme_colours = $p->releases("Acme-Colour");
135 my @authors = $p->authors;
136 my @acmes = $p->distributions_by('LBROCARD');
140 Parse::BackPAN::Packages has been B<DEPRECATED>. Please use the
141 faster and more flexible L<BackPAN::Index>.
143 The Comprehensive Perl Archive Network (CPAN) is a very useful
144 collection of Perl code. However, in order to keep CPAN relatively
145 small, authors of modules can delete older versions of modules to only
146 let CPAN have the latest version of a module. BACKPAN is where these
147 deleted modules are backed up. It's more like a full CPAN mirror, only
148 without the deletions. This module provides an index of BACKPAN and
149 some handy functions.
151 The data is fetched from the net and cached for an hour.
157 The constructor downloads a ~1M index file from the web and parses it,
158 so it might take a while to run:
160 my $p = Parse::BACKPAN::Packages->new();
162 By default it caches the file locally for one hour. If you do not
163 want this caching then you can pass in:
165 my $p = Parse::BACKPAN::Packages->new( { no_cache => 1 } );
169 The authors method returns a list of all the authors. This is meant so
170 that you can pass them into the distributions_by method:
172 my @authors = $p->authors;
176 my $distributions = $p->distributions;
178 The distributions method returns an array ref of the names of all the
179 distributions in BackPAN.
183 The releases method returns a list of objects representing all
184 the different releases of a distribution:
186 # see Parse::BACKPAN::Packages::Release
187 my @acme_colours = $p->releases("Acme-Colour");
189 =head2 distributions_by
191 The distributions_by method returns a list of distribution names
192 representing all the distributions that an author has uploaded:
194 my @acmes = $p->distributions_by('LBROCARD');
198 The file method finds metadata relating to a file:
200 # see Parse::BACKPAN::Packages::File
201 my $file = $p->file("authors/id/L/LB/LBROCARD/Acme-Colour-0.16.tar.gz");
202 print "That's " . $file->size . " bytes\n";
206 The files method returns a hash reference where the keys are the
207 filenames of the files on CPAN and the values are
208 Parse::BACKPAN::Packages::File objects:
210 my @filenames = keys %$p->files;
214 The size method returns the sum of all the file sizes in BACKPAN:
216 print "BACKPAN is " . $p->size . " bytes\n";
220 Leon Brocard <acme@astray.com>
224 Copyright (C) 2005-9, Leon Brocard
228 This module is free software; you can redistribute it or modify it under
229 the same terms as Perl itself.
233 L<BackPAN::Index>, L<CPAN::DistInfoname>