NAME
CPAN::InGit::DistTree - A MutableTree holding the files of one CPAN distribution
SYNOPSIS
my $old= $app_tree->get_dist('A/AU/AUTHOR/Example-1.00.tar.gz');
my $new= $cpan_tree->get_dist('A/AU/AUTHOR/Example-1.02.tar.gz', fetch => 1);
# Browse it
my $entries= $new->list_dir('lib');
my ($blob, $mode)= @{ $new->get_path('lib/Example.pm') };
my ($changes_name, $changes_blob)= $new->changes_file;
# Inspect it
my $prereqs= $new->meta->effective_prereqs;
# Compare it
my $report= $old->compare($new);
DESCRIPTION
This is a MutableTree holding the contents of a single distribution. The files are always found at the root of the tree; the customary Dist-Name-1.23/ wrapper directory of a distribution archive is removed, so that the same file has the same path in every version of the distribution.
You normally get one from "get_dist" in CPAN::InGit::ArchiveTree, which handles distributions stored as archive files (unpacked once, then cached in "dist_cache_repo" in CPAN::InGit) as well as distributions stored unpacked in the Git branch. A DistTree is not connected to any branch, and so while it has the methods to make changes, it can't commit them.
ATTRIBUTES
name
The release name of the distribution, like Example-1.02. (the archive file name without its extension)
author_path
The path of this distribution relative to authors/id/, if it came from an ArchiveTree.
storage
How the distribution was found: 'archive' for an archive file in the ArchiveTree, 'unpacked' for a directory of files in the ArchiveTree, or 'upstream' for an archive downloaded from the upstream of a mirror without being added to the mirror.
git_repo
For a DistTree this is the "dist_cache_repo" in CPAN::InGit, which can read the objects of the main repository as well as the cache of unpacked archives.
METHODS
parse_filename
my ($name, $extension)= CPAN::InGit::DistTree->parse_filename($path);
Split the file name of a distribution archive into its release "name" and one of the supported archive extensions. Returns an empty list if the name doesn't look like a distribution archive.
parse_release
my ($dist_name, $version)= CPAN::InGit::DistTree->parse_release($path);
# 'A/AU/AUTHOR/Example-Dist-1.02.tar.gz' => ('Example-Dist', '1.02')
Split the file name of a distribution archive into the name of the distribution and the version of the release. Returns an empty list if the name doesn't have that form.
new_from_archive
my $dist= CPAN::InGit::DistTree->new_from_archive(
parent => $cpan_repo,
filename => 'Example-1.02.tar.gz',
data => \$bytes,
%other_attributes
);
Unpack a tar or zip archive into Git objects of the "dist_cache_repo" in CPAN::InGit. This dies if the archive can't be read, or contains anything other than files, directories, and symlinks, or has paths that are unsafe to store in Git (like .. or .git).
This does not consult or update the cache; see "get_dist" in CPAN::InGit::ArchiveTree.
files
my $files= $dist->files;
# { 'lib/Example.pm' => [ \$bytes, $mode ], ... }
Return every file of the distribution, in the form accepted by "set_path" in CPAN::InGit::MutableTree for a directory.
file_list
my @paths= $dist->file_list;
Return the sorted paths of every file (and symlink) in the distribution.
check_symlinks
$dist->check_symlinks;
Die if any symlink of the distribution is absolute, or refers to a path outside of the distribution, or passes through another symlink. Such links are harmless while stored in Git, but should be checked before writing the files to a directory.
meta
my $cpan_meta= $dist->meta;
Return a CPAN::Meta object for the distribution, loaded from its META.json or META.yml. If the distribution has neither (or they can't be parsed), this returns a minimal object built from the "name", which has no prereqs. Check "meta_source" to tell the difference.
meta_source
Returns 'META.json', 'META.yml', or 'synthesized', describing where "meta" came from.
provides
my $provides= $dist->provides;
# { 'Example' => { file => 'lib/Example.pm', version => '1.02' }, ... }
Return the packages of this distribution, in the format of the provides of the CPAN Meta Spec. If the "meta" doesn't declare them, they are found by scanning the .pm files for package declarations and literal $VERSION assignments. No code from the distribution is ever executed.
changes_file
my ($name, $blob)= $dist->changes_file;
Find the change log of the distribution, looking for the conventional names Changes, ChangeLog, and NEWS (in that order of preference, in any letter case, optionally with an extension like .md) in the root of the distribution. Returns an empty list if there isn't one.
diff_prereqs
my $changes= $dist->diff_prereqs($other_dist);
# {
# runtime => {
# requires => {
# 'Added::Module' => [ undef, '1.5' ],
# 'Changed::Module' => [ '0.10', '0.24' ],
# 'Removed::Module' => [ '0', undef ],
# },
# },
# }
Compare the prereqs declared by the "meta" of this distribution with those of another DistTree (or a CPAN::Meta object), returning only the phases, relationships, and modules which differ. Each module has an arrayref of the version requirement in this distribution and in the other, where undef means it is not required at all.
This can also be called as a class method on two CPAN::Meta objects:
my $changes= CPAN::InGit::DistTree->diff_prereqs($meta_a, $meta_b);
summary
my $info= $dist->summary;
# { name => 'Example-1.02', author_path => 'A/AU/AUTHOR/Example-1.02.tar.gz',
# version => '1.02', storage => 'archive', meta_source => 'META.json', tree => $tree_id }
Return a hashref of plain scalars describing this distribution.
compare
my $report= $dist->compare($other_dist, %options);
# {
# from => { name => 'Example-1.00', ... }, # see ->summary
# to => { name => 'Example-1.02', ... },
# prereqs => { ... }, # see ->diff_prereqs
# changes => {
# path => 'Changes',
# added => "1.02 - 2026-01-02\n - Fixed a bug\n",
# patch => "diff --git ...",
# },
# files => [
# { path => 'lib/Example.pm', status => 'modified', additions => 3, deletions => 1,
# patch => "diff --git ...", ... },
# { path => 'META.json', status => 'modified', additions => 9, deletions => 9,
# skipped => 'generated', ... },
# ],
# stats => { files => 2, additions => 12, deletions => 10 },
# }
Build a complete report of what changed between this distribution and another, as a structure of plain data which can be serialized or rendered as text or HTML. It is intended for reviewing an upgrade from this distribution to $other_dist.
All text of the report (paths, patches, and change log) is decoded as UTF-8 where it is valid UTF-8, so remember to encode it on output.
changes is undef unless $other_dist has a change log that differs from the one in this distribution. Its added is the text of the lines that were added to the change log.
files has one element per changed file, as described in "diff" in CPAN::InGit::MutableTree. A file without a patch has a skipped attribute giving the reason: 'generated' for files that are boilerplate or derived from other files (META.json, META.yml, MANIFEST, SIGNATURE, ppport.h and everything under inc/), 'binary', 'too large', 'version' when the only change was the version number (see hide_version_diff), or 'changes' for the change log which is reported separately. A file whose patch had some of its hunks removed by hide_version_diff has the number of them in hidden_version_hunks. The additions and deletions always count every line.
Options:
- paths
-
Arrayref of paths (or git pathspecs) to limit the file comparison. Naming paths also disables skipping of generated files.
- patch
-
Boolean, whether to include patches at all (default true).
- context_lines
-
Number of unchanged lines around each change in the patches (default 3)
- max_patch_size
-
Patches longer than this number of bytes are skipped as
'too large'. (default 200_000, and 0 means unlimited) - include_generated
-
Boolean, whether to include patches for generated files
- hide_version_diff
-
Boolean (default true), whether to remove from the patches every hunk that does nothing but change the version number. Such a hunk removes one line and adds one line, the line mentions
version(in any case), and the two lines are identical aside from the version of this distribution having been replaced with the version of$other_dist. This hides the$VERSIONdeclaration and the "version 1.02" POD line that change in every module of every release. The change log is not affected, and neither are generated files unless their patches were requested withinclude_generatedorpaths.
format_comparison
my $text= CPAN::InGit::DistTree->format_comparison($report, %options);
Render the result of "compare" as plain text: a header, the changed prereqs, the lines added to the change log, a summary of the files changed, and then the patches. The patches are standard unified diffs. Options:
- patch
-
Set to false to omit the patches
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.