NAME

CPAN::InGit::ArchiveTree - An object managing a CPAN file structure in a Git Tree

DESCRIPTION

This object represents a tree of files matching the layout of CPAN. It may be an actual mirror of an upstream CPAN/DarkPAN, or it may be a local curated collection of modules intended to provide pinned versions for an application. Mirrors (meaning *every* package from upstream is listed in the index and fetched on demand) are represented by the subclass MirrorTree which implements the fetching of files from upstream. This class only contains methods to import distributions from other Git branches.

Distributions in authors/id/X/XX/XXXXX should be kept identical to the public CPAN copy. Local changes/patches to those files should be given a new distribution name under authors/id/L/LO/LOCAL. The "provides" list (of modules) of a public CPAN distribution will be kept the same as reported by public CPAN (for security, so that a dist without permission to index a module still can't claim that name) but the "provides" list of a local distribution will always take precedence in the indexing.

ATTRIBUTES

name

A human-readable name for this ArchiveTree instance. Defaults to the branch name, when loaded from a branch. When loaded by "get_archive_tree" in CPAN::InGit it is set to tag or sha1 if a branch is not available.

config

A hashref of configuration stored in the tree, and lazily-loaded.

config_blob

Returns the Blob of the cpan_ingit.conf file, or undef if it doesn't exist.

canonical_url

The URL to be advertised in 02packages.details.txt, when written by this module.

default_import_sources

List of other branch names which the "import_modules" should search.

corelist_perl_version

Version of perl which should be considered when deciding whether a module already exists in the core distribution or whether it should be fetched from CPAN.

package_details

The parsed contents of modules/02package_details.txt:

{
  last_update => # Time::Piece of last-update
  by_module   => { $module_name => [ $mod, $ver, $path ] },
  by_dist     => { $author_path => [ [ $mod, $ver, $path ], ... ] },
}

The by_module and by_dist hashres refer to the same row arrayrefs.

METHODS

load_config

%attrs= $archive_tree->load_config();

Load the configuration of this ArchiveTree from the config file within the git tree. (path /cpan_ingit.json)

write_config

$archive_tree->write_config($config);

Create a new /cpan_ingit.json from the "config" attribute of this ArchiveTree. By default This stages the change (see CPAN::InGit::MutableTree) but does not commit it.

package_details_blob

Returns the Blob of the modules/02packages.details.txt file, or undef if it doesn't exist.

parse_package_details

Parse modules/02packages.details.txt.gz into a structure matching the description in attribute "package_details".

write_package_details

Write modules/02packages.details.txt from the current value of attribute "package_details". This adds it to the pending changes to the tree, but does not commit it.

index_distribution

$tree->index_distribution($author_path, \%package_versions);

Make this distribution the provider of the supplied packages and versions. Replace its previous package list and write the updated index to the tree.

has_module

$bool= $atree->has_module($mod_name);
$bool= $atree->has_module($mod_name, $version_requirement);

get_module_version

$ver= $atree->get_module_version($mod_name);

get_module_dist

$ver= $atree->get_module_dist($mod_name);

find_upgrades

my $list= $archive_tree->find_upgrades(sources => \@other_archive_trees);
# [
#   {
#     author_path => 'A/AU/AUTHOR/Example-1.00.tar.gz',
#     dist        => 'Example',
#     version     => '1.00',
#     upgrades    => [
#       { author_path => 'A/AU/AUTHOR/Example-1.02.tar.gz', dist => 'Example', version => '1.02',
#         source => 'www_cpan_org', kind => 'upgrade',
#         modules => { 'Example' => [ '1.00', '1.02' ] } },
#       { author_path => 'A/AU/AUTHOR/Example-Util-0.01.tar.gz', dist => 'Example-Util', version => '0.01',
#         source => 'www_cpan_org', kind => 'moved',
#         modules => { 'Example::Util' => [ '1.00', '1.01' ] } },
#     ],
#     left_behind   => [ 'Example::Old' ],
#     not_in_source => [ 'Example::Private' ],
#   },
#   ...
# ]

Compare the index of this tree with the index of other trees (by default, the trees named in "default_import_sources") and return every distribution of this tree for which a newer distribution is available, sorted by author path.

The comparison starts from the modules, because a module can move from one distribution to another. Each module of this tree is looked up in the sources, taking the source with the highest version of it. The modules are then grouped by the pair of (distribution here, distribution there), and each pair becomes an element of upgrades if it is newer:

kind => 'upgrade'

The other distribution has the same name and a higher release version.

kind => 'moved'

The other distribution has a different name, and a higher version of at least one module.

Each element of sources is an ArchiveTree, or a hashref of { name => $name, by_module => \%by_module } in the format of "package_details", for a caller that has its own snapshot of an index. The option dists (an arrayref of author paths) limits the comparison to those distributions of this tree.

modules has the version of each module here and there. left_behind lists the modules which the sources still attribute to the distribution of this tree; typically, modules that were removed from the newer release. not_in_source lists the modules that no source provides. Both are omitted when empty.

find_module_source

my $found= $archive_tree->find_module_source($module_name, sources => \@sources);
# { module => 'Example', version => '1.02', author_path => 'A/AU/AUTHOR/Example-1.02.tar.gz',
#   source => 'www_cpan_org' }

Look up one module in the sources (as described for "find_upgrades", which uses this same selection) and return the one with the highest version of it, or undef if no source provides it. The first source wins a tie.

meta_path_for_dist

$author_path= $archive_tree->meta_path_for_dist($author_path);

Return the author path for the .meta file corresponding with the distribution at an author path. This is just a simple replacement of file extension that accounts for some special cases.

import_dist

$archive_tree->import_dist($peer_tree, $author_path, %options);

Fetch an $author_path from another tree, and update the module index to assign ownership of the same modules as this dist had in the other tree. The tree is written, but not committed. This can change ownership of modules to this dist from another dist that claimed them. Warn about packages the archive claims that the peer index does not register for this distribution.

The .meta file of the distribution is copied from the peer as well. If the peer doesn't have one, it is written from the META.json or META.yml found inside the distribution.

dist_storage

my $storage= $tree->dist_storage($author_path);

Returns 'archive' if the distribution is stored in this tree as an archive file, 'unpacked' if it is stored as a directory of files (plus .meta file) from which a .tar.gz can be generated, or undef if this tree does not contain the distribution. This never fetches anything from the upstream of a mirror.

get_dist

my $dist= $tree->get_dist($author_path, %options);

Return a CPAN::InGit::DistTree for browsing, inspecting, or comparing the files of a distribution, or undef if this tree does not contain the distribution. An archive file is unpacked the first time it is requested and cached in "dist_cache_repo" in CPAN::InGit. This dies if the archive can't be unpacked.

Options:

fetch

For a MirrorTree which lacks the distribution, download it from upstream and unpack it into the cache, without adding the archive to the mirror.

get_distfile

my $bytes_ref= $tree->get_distfile($author_path);

Return a scalar reference to the archive, or undef if unavailable. For an unpacked distribution, generate the archive from its Git tree. Mirrors can fetch the archive without adding it to the tree.

localize_module

my $author_path= $tree->localize_module($package, %options);

Look up a package in this tree, then in the configured import sources (or the sources option). Unpack its distribution under the LOCAL author and preserve the package names and versions registered by the source.

add_local_dist

my $author_path= $tree->add_local_dist($filename, \$bytes, %options);

Unpack a distribution under authors/id/L/LO/LOCAL, write its metadata and register its packages in the index. Return the .tar.gz author path that serves the unpacked distribution. Supply versions as a hash of indexed packages and versions when importing from a known manifest.

get_dist_meta

$meta= $archive_tree->get_dist_meta($author_path);

Return the CPAN::Meta for the distribution, or undef if unknown. This comes from the .meta file stored next to the distribution, and otherwise from inspecting the contents of the distribution (see "meta" in CPAN::InGit::DistTree).

import_modules

# {
#   'Example::Module' => '>=0.011',
#   'Some::Module'    => '',   # any version
# }
my $imported= $archive_tree->import_modules(\%module_version_spec);
# {
#   'A/AU/AUTHOR/Example-Module-1.2.3.tar.gz' => $from_source,
#   ...
# }

This method processes a list of module requirements to pull in matching modules and only as many dependencies as are required. It starts by checking whether this branch contains a module that meets the requirements. If not, it checks the mirror branches listed in "import_sources". If this or any "import_source" branch has an "upstream_url", it may pull from remote into that branch.

The intended workflow is that you have one branch tracking www.cpan.org and pulling in packages automatically as needed, and then perhaps a branch where you review the modules before importing them, and maybe a branch where you upload private DarkPAN modules, and then any number of application branches that import from the reviewed branch or the DarkPAN branch. This way you separate the process of building an application's module collection from the process of reviewing public modules.

All changes will be pulled into this MutableTree object, but not committed. If this is the working branch, the index also gets updated.

import_cpanfile_snapshot

$archive_tree->import_cpanfile_snapshot(\%distribution_spec);

This function takes a data structure from a cpanfile.snapshot (parsed via "parse_cpanfile_snapshot" in CPAN::InGit ) and fetches the exact distribution files listed, and writes all the "provides" information into the "package_details".

This does not check any of the 'requires', on the assumption that the snapshot represents a complete package collection.

VERSION

version 0.007

AUTHOR

Michael Conrad <mike@nrdvana.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Michael Conrad, and IntelliTree Solutions.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.