CPAN-InGit
view release on metacpan or search on metacpan
0.003 - 2026-01-14
- cpangit-add can now process cpanfile or cpanfile.snapshot
- New method ArchiveTree->import_cpanfile_snapshot
- Support for backpan via MirrorTree->upstream_backup_url
0.002 - 2025-12-19
- Sort 02packages.details.txt case-insensitive so that it works with
binary search required by CPAN::02Packages::Search used by App::cpm
- Server:
- Refresh cache if a branch receives new commits
- Limit cache to 20 trees (LRU) when Tree::RB::XS is available
- Fix bugs in ability to generate .tar.gz files from dist dir
0.001 - 2025-12-16
lib/CPAN/InGit/MirrorTree.pm view on Meta::CPAN
use JSON::PP;
use Time::Piece;
use Log::Any '$log';
use Moo;
use v5.36;
extends 'CPAN::InGit::ArchiveTree';
has upstream_url => ( is => 'rw', coerce => \&_add_trailing_slash );
has upstream_backup_url => ( is => 'rw', lazy => 1, builder => 1, coerce => \&_add_trailing_slash );
has autofetch => ( is => 'rw', default => 1 );
has package_details_max_age => ( is => 'rw', default => 86400 );
sub _build_upstream_backup_url($self) {
($self->upstream_url||'') =~ m{^(https?)://www\.cpan\.org}
? "$1://backpan.perl.org/"
: undef;
}
sub _add_trailing_slash {
my $x= shift;
defined $x? $x =~ s{/?\z}{/}r : $x
}
sub _pack_config($self, $config) {
$config->{upstream_url}= $self->upstream_url;
$config->{upstream_backup_url}= $self->upstream_backup_url;
$config->{autofetch}= $self->autofetch;
$config->{package_details_max_age}= $self->package_details_max_age;
$self->next::method($config);
}
sub _unpack_config($self, $config) {
$self->next::method($config);
$self->upstream_url($config->{upstream_url});
$self->upstream_backup_url($config->{upstream_backup_url})
if exists $config->{upstream_backup_url};
$self->autofetch($config->{autofetch});
$self->package_details_max_age($config->{package_details_max_age});
}
sub get_path($self, $path) {
my $ent= $self->next::method($path);
if ($self->autofetch) {
# Special case for 02packages.details.txt, load it if missing or if cache is stale
if ($path eq 'modules/02packages.details.txt') {
if ($ent) {
lib/CPAN/InGit/MirrorTree.pm view on Meta::CPAN
}
sub fetch_upstream_file($self, $path, %options) {
croak "No upstream URL for this tree"
unless defined $self->upstream_url;
my $url= $self->upstream_url . $path;
my $tx= $self->parent->useragent->get($url);
$log->debugf(" GET %s -> %s %s", $url, $tx->result->code, $tx->result->message);
unless ($tx->result->is_success) {
if ($self->upstream_backup_url && $path =~ m{^authors/id/}) {
my $url2= $self->upstream_backup_url . $path;
my $tx2= $self->parent->useragent->get($url2);
$log->debugf(" GET %s -> %s %s", $url2, $tx2->result->code, $tx2->result->message);
return \$tx2->result->body
if $tx2->result->is_success;
}
return undef if $options{undef_if_404} && $tx->result->code == 404;
croak "Failed to find file upstream: ".$tx->result->message;
}
return \$tx->result->body;
}
lib/CPAN/InGit/MirrorTree.pm view on Meta::CPAN
This is a subclass of L<CPAN::InGit::ArchiveTree> which behaves as a pure mirror of an
upstream CPAN or DarkPAN. The attribute L</autofetch> allows it to import files from the public
CPAN on demand.
=head1 ATTRIBUTES
=head2 upstream_url
This is the base URL from which files will be fetched.
=head2 upstream_backup_url
This is a fallback URL for if the primary URL lacks a distribution file. The backup url is
presumed to have the exact same distribution files as the primary URL, but a longer history of
them. The package index of the backup URL is never used.
If the primary URL is C<< http://www.cpan.org >> then this will default to
C<< https://backpan.perl.org >>.
=head2 autofetch
If enabled, attempts to access author files which exist on the L</upstream_url> and not locally
will immediately go download the file and return it as if it had existed all along. These
changes are not automatically committed. Use C<has_changes> to see if anything needs committed.
( run in 0.573 second using v1.01-cache-2.11-cpan-63428c044ed )