| 1 | package CPAN::InGit; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | our $VERSION = '0.006'; # VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Manage custom CPAN trees to pin versions for your projects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Git::Raw::Repository; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Archive::Tar; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Archive::Tar::Constant; # for constants to be avilable at compile time | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Scalar::Util 'blessed'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use CPAN::InGit::MirrorTree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use CPAN::Meta 2.150010; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use Module::Metadata; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use Fcntl qw( S_ISREG S_ISLNK S_IFMT S_ISDIR ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use Moo; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use v5.36; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 18 | ▶ | sub BUILDARGS($class, @list) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=3 SCAR=11.0
Pod
undocumented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 18 | ▶ | unshift @list, 'git_repo' if @list == 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 18 | my $args= $class->next::method(@list); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 18 | ▶ | $args->{git_repo}= delete $args->{repo} if defined $args->{repo}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 18 | $args; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 11 | has git_repo => ( is => 'ro', required => 1, coerce => \&_open_repo ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 11 | has git_author_name => ( is => 'rw', default => 'CPAN::InGit' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 11 | has git_author_email => ( is => 'rw', default => 'CPAN::InGit@localhost' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 11 | has workdir_branch_name => ( is => 'lazy' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | sub _build_workdir_branch_name($self) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_workdir_branch_name: called CC=3 SCAR=13.1
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | return undef if $self->git_repo->is_bare || $self->git_repo->is_head_detached; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->git_repo->is_bare or $self->git_repo->is_head_detached
MC/DC0%0/2
$self->git_repo->is_bare or $self->git_repo->is_head_detached
$self->git_repo->is_bare
$self->git_repo->is_head_detached
Truth table33%1/3
A or B
A= $self->git_repo->is_bareB= $self->git_repo->is_head_detached
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 | return $self->git_repo->head->shorthand; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 11 | has useragent => ( is => 'lazy' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub _build_useragent($self) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_useragent: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | require Mojo::UserAgent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | return Mojo::UserAgent->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 18 | ▶ | sub _open_repo($thing) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_open_repo: called CC=3 SCAR=15.4
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 18 | ▶ | return $thing if blessed($thing) && $thing->isa('Git::Raw::Repository'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($thing) and $thing->isa("Git::Raw::Repository")
MC/DC0%0/2
builtin::blessed($thing) and $thing->isa("Git::Raw::Repository")
builtin::blessed($thing)
$thing->isa("Git::Raw::Repository")
Truth table33%1/3
A and B
A= builtin::blessed($thing)B= $thing->isa("Git::Raw::Repository")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | return Git::Raw::Repository->open("$thing"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 63 | ▶ | sub get_archive_tree($self, $branch_or_tag_or_id) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_archive_tree: called CC=12 SCAR=25.1
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 63 | my ($tree, $origin)= $self->lookup_tree($branch_or_tag_or_id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 63 | ▶ | return undef unless $tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 63 | ▶ | my $branch= $origin && ref($origin)->isa('Git::Raw::Branch')? $origin : undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$origin and ref($origin)->isa("Git::Raw::Branch")
MC/DC50%1/2
$origin and ref($origin)->isa("Git::Raw::Branch")
$origin
ref($origin)->isa("Git::Raw::Branch")
Truth table66%2/3
A and B
A= $originB= ref($origin)->isa("Git::Raw::Branch")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # If HEAD requested or using the branch pointed to by HEAD, and if it has a work directory, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # then apply any changes to the workdir. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 63 | ▶ | my $use_workdir= !$self->git_repo->is_bare && (($branch && $branch->is_head) || $branch_or_tag_or_id eq 'HEAD'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%9/9
!$self->git_repo->is_bare && ($branch && $branch->is_head || $branch_or_tag_or_id eq 'HEAD')
$branch and $branch->is_head or $branch_or_tag_or_id eq "HEAD"
$branch and $branch->is_head
MC/DC50%2/4
!$self->git_repo->is_bare && ($branch && $branch->is_head || $branch_or_tag_or_id eq 'HEAD')
!$self->git_repo->is_bare
$branch
$branch->is_head
$branch_or_tag_or_id eq "HEAD"
Truth table66%4/6
not(A) && B and C or D
A= !$self->git_repo->is_bareB= $branchC= $branch->is_headD= $branch_or_tag_or_id eq "HEAD"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Does it look like an ArchiveTree? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 63 | my $config_blob; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 63 | ▶ | if ($use_workdir) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | my $ent= $self->git_repo->index->find('cpan_ingit.json'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | ▶ | return undef unless $ent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 3 | $config_blob= $ent->blob; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 60 | my $ent= $tree->entry_bypath('cpan_ingit.json'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 60 | ▶ | return undef unless $ent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 60 | $config_blob= $ent->object; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 63 | my $cfg= JSON::PP->new->relaxed->decode($config_blob->content); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 63 | ▶ | my $class= $cfg->{upstream_url}? 'CPAN::InGit::MirrorTree' : 'CPAN::InGit::ArchiveTree'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 63 | ▶ | return $class->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | parent => $self, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | tree => $tree, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | name => $branch? $branch->shorthand : "$branch_or_tag_or_id", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | use_workdir => $use_workdir, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | (branch => $branch)x!!$branch, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 15 | ▶ | sub create_archive_tree($self, $name, %params) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_archive_tree: called CC=4 SCAR=14.8
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 15 | ▶ | croak "Branch '$name' already exists" | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | if Git::Raw::Branch->lookup($self->git_repo, $name, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 15 | ▶ | croak "Branch '$name' already exists upstream" | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | if Git::Raw::Branch->lookup($self->git_repo, $name, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 15 | my $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 15 | ▶ | if ($params{upstream_url}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $t= CPAN::InGit::MirrorTree->new(%params, parent => $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $t->add_upstream_package_details; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 15 | $t= CPAN::InGit::ArchiveTree->new(%params, parent => $self); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 15 | $t->write_package_details; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # It won't exist until we create a commit and create a branch. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 15 | $t->write_config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 15 | $t->commit("Called create_archive_tree", create_branch => $name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 15 | return $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 168 | ▶ | sub lookup_tree($self, $branch_or_tag_or_id) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lookup_tree: called CC=19 SCAR=36.4
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 168 | my ($tree, $origin); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 168 | ▶ | defined $branch_or_tag_or_id or croak "missing argument"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 168 | my $repo= $self->git_repo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 168 | ▶ | if (blessed($branch_or_tag_or_id) && $branch_or_tag_or_id->isa('Git::Raw::Reference')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
Condition100%3/3
builtin::blessed($branch_or_tag_or_id) and $branch_or_tag_or_id->isa("Git::Raw::Reference")
MC/DC100%2/2
builtin::blessed($branch_or_tag_or_id) and $branch_or_tag_or_id->isa("Git::Raw::Reference")
builtin::blessed($branch_or_tag_or_id)
$branch_or_tag_or_id->isa("Git::Raw::Reference")
Truth table100%3/3
A and B
A= builtin::blessed($branch_or_tag_or_id)B= $branch_or_tag_or_id->isa("Git::Raw::Reference")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 138 | $origin= $branch_or_tag_or_id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 138 | $tree= $origin->peel('tree'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ▶ | } elsif (blessed($branch_or_tag_or_id) && $branch_or_tag_or_id->isa('Git::Raw::Commit')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
builtin::blessed($branch_or_tag_or_id) and $branch_or_tag_or_id->isa("Git::Raw::Commit")
MC/DC50%1/2
builtin::blessed($branch_or_tag_or_id) and $branch_or_tag_or_id->isa("Git::Raw::Commit")
builtin::blessed($branch_or_tag_or_id)
$branch_or_tag_or_id->isa("Git::Raw::Commit")
Truth table66%2/3
A and B
A= builtin::blessed($branch_or_tag_or_id)B= $branch_or_tag_or_id->isa("Git::Raw::Commit")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 7 | $origin= $branch_or_tag_or_id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 7 | $tree= $origin->tree; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ▶ | } elsif (blessed($branch_or_tag_or_id) && $branch_or_tag_or_id->isa('Git::Raw::Tag')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
builtin::blessed($branch_or_tag_or_id) and $branch_or_tag_or_id->isa("Git::Raw::Tag")
MC/DC0%0/2
builtin::blessed($branch_or_tag_or_id) and $branch_or_tag_or_id->isa("Git::Raw::Tag")
builtin::blessed($branch_or_tag_or_id)
$branch_or_tag_or_id->isa("Git::Raw::Tag")
Truth table33%1/3
A and B
A= builtin::blessed($branch_or_tag_or_id)B= $branch_or_tag_or_id->isa("Git::Raw::Tag")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $origin= $branch_or_tag_or_id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $origin= $origin->target while $origin->isa('Git::Raw::Tag'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | $tree= $origin->isa('Git::Raw::Commit')? $origin->tree : $origin; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } elsif ($branch_or_tag_or_id eq 'HEAD') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | $tree= $repo->head->target->tree; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 1 | ▶ | $origin= $repo->is_head_detached? undef | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | : $repo->head; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 22 | } elsif ($origin= eval { Git::Raw::Branch->lookup($repo, $branch_or_tag_or_id, 1) }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 20 | $tree= $origin->peel('tree'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | } elsif ($origin= eval { Git::Raw::Tag->lookup($repo, $branch_or_tag_or_id) }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $tree= $origin->peel('tree'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | } elsif (my $obj= eval { $repo->lookup($branch_or_tag_or_id) }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | ▶ | if ($obj->isa('Git::Raw::Commit')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | $origin= Git::Raw::Commit->lookup($repo, $obj->id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | $tree= $origin->tree; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } elsif ($obj->isa('Git::Raw::Tree')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $tree= Git::Raw::Tree->lookup($repo, $obj->id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } elsif ($obj->isa('Git::Raw::Tag')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $origin= Git::Raw::Tag->lookup($repo, $obj->id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $tree= $origin->target; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 168 | ▶ | return wantarray? ($tree, $origin) : $tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | ▶ | sub add_git_tree_to_tar($self, $tar, $path, $tree) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_git_tree_to_tar: called CC=4 SCAR=20.7
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | ▶ | unless ($tree->can('entries')) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $id= $tree; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | $tree = Git::Raw::Tree->lookup($self->git_repo, $id) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | or die "Can't find TREE $id referenced by '$path'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | $self->add_git_dirent_to_tar($tar, "$path/".$_->name, $_) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | for $tree->entries; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | ▶ | sub add_git_dirent_to_tar($self, $tar, $path, $dirent) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_git_dirent_to_tar: called CC=5 SCAR=20.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | ▶ | if ($dirent->type == Git::Raw::Object::BLOB()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | my $mode = $dirent->file_mode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | my $blob = Git::Raw::Blob->lookup($self->git_repo, $dirent->id) | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | or die "Can't find BLOB ".$dirent->id." referenced by '$path'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # Check if it's a symlink (mode 0120000 or 40960 decimal) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | ▶ | if (($mode & 0170000) == 0120000) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # Symlink: content is the target path | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $tar->add_data($path, $blob->content, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | mode => $mode, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | type => Archive::Tar::Constant::SYMLINK, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | linkname => $blob->content | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # Regular file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | $tar->add_data($path, $blob->content, { mode => $mode }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | elsif ($dirent->type == Git::Raw::Object::TREE()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $self->add_git_tree_to_tar($tar, $path, $dirent->id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | warn "Omitting $path from TAR, not a BLOB or TREE"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 34 | ▶ | sub new_signature($self) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_signature: called CC=1 SCAR=0.0
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 34 | Git::Raw::Signature->now($self->git_author_name, $self->git_author_email); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | sub lookup_versions($self, $module_name) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lookup_versions: not called CC=2 SCAR=17.9
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | for my $up ($self->upstream_mirrors->@*) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ...; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | sub process_distfile($self, %opts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_distfile: not called CC=25 SCAR=64.8
Pod
documented
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my ($tree, $file_path, $file_data, $extract)= @opts{'tree','file_path','file_data','extract'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # Decompress tar in memory. The decompression gets complicated since it can be bz2 or gz | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # so write to a temp file and then parse that with the auto-detection of "compress". | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if ($file_path =~ /\.(tar\.gz|tar\.bz2|tgz)\z/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $path_without_extension= substr($file_path, 0, $-[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my $tmp= File::Temp->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | $tmp->print($$file_data) or die "write: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $tmp->flush; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Iterate across the files in the tar archive | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $tar= Archive::Tar->new("$tmp", 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my @files= $tar->get_files; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if (!@files) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | croak "Failed to extract any files from archive $file_path"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # Remove prefix directory if every file in archive starts with the same directory | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | (my $prefix= $files[0]->name) =~ s,/.*,,; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $prefix .= '/'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | for (@files) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if (substr($_->name,0,length $prefix) ne $prefix) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $prefix= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | last; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # Build by-name hash of files | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my %files= map +( substr($_->name, length $prefix) => $_ ), @files; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $meta; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # Look for a META.json | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if (my $meta_json= $files{'META.json'}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my $cm= CPAN::Meta->load_json_string($meta_json->get_content); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $meta= $cm->as_struct({ version => 2 }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } or warn "Failed to load $file_path/${prefix}META.json: $@"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # else look for META.yml | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if (!$meta && (my $meta_yml= $files{'META.yml'})) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $meta and my $meta_yml = $files{"META.yml"}
MC/DC0%0/2
not $meta and my $meta_yml = $files{"META.yml"}
not $meta
my $meta_yml = $files{"META.yml"}
Truth table0%0/3
not(A) and B
A= not $metaB= my $meta_yml = $files{"META.yml"}
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | my $cm= CPAN::Meta->load_yaml_string($meta_yml->get_content); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $meta= $cm->as_struct({ version => 2 }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } or warn "Failed to load $file_path/${prefix}META.yml: $@"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # TODO: add some fall-back that guesses at prereqs. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | $meta //= {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$meta //= {}
MC/DC0%0/1
$meta //= {}
$meta
Truth table0%0/2
A
A= $meta
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # If the meta didn't contain "provides", add that using Module::Metadata | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | if (!$meta->{provides}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my $provides= $meta->{provides}= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | for my $pm_fname (grep /\.pm\z/ && !m{^(t|xt|inc|script|bin)/}, keys %files) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
/\.pm\z/u && !m[^(t|xt|inc|script|bin)/]u
MC/DC0%0/2
/\.pm\z/u && !m[^(t|xt|inc|script|bin)/]u
/\.pm\z/u
!m[^(t|xt|inc|script|bin)/]u
Truth table0%0/3
A && not(B)
A= /\.pm\z/uB= !m[^(t|xt|inc|script|bin)/]u
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | open my $pm_fh, '<', $files{$pm_fname}->get_content_by_ref or die; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my $mm= Module::Metadata->new_from_handle($pm_fh, $pm_fname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | for my $pkg (grep $_ ne 'main', $mm->name, $mm->packages_inside) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | $provides->{$pkg}{file}= $pm_fname; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | $provides->{$pkg}{version} //= $mm->version($pkg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$provides->{$pkg}{"version"} //= $mm->version($pkg)
MC/DC0%0/2
$provides->{$pkg}{"version"} //= $mm->version($pkg)
$provides->{$pkg}{"version"}
$mm->version($pkg)
Truth table0%0/3
A //= B
A= $provides->{$pkg}{"version"}B= $mm->version($pkg)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } or warn "Failed to parse packages in $file_path/${prefix}$pm_fname: $@"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # If caller requests 'extract', add the tar's files and symlinks to the tree | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | if ($extract) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | for (keys %files) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $mode= $files{$_}->mode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if (S_ISREG($mode)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # normalize to 644 or 755 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | $mode= S_IFMT($mode) | (($mode & 1)? 0755 : 0644); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $tree->set_path("$path_without_extension/$_", $files{$_}->get_content_by_ref, $mode); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } elsif (S_ISLNK($mode)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $tree->set_path("$path_without_extension/$_", \$files{$_}->linkname, S_IFMT($mode)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } elsif (!S_ISDIR($mode)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | warn "Skipping tar entry for '$path_without_extension/$_' (mode=$mode)\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | $tree->set_path($file_path, $file_data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # Now serialzie the meta and write it to the tree alongside the TAR | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $json= CPAN::Meta->new($meta)->as_string({ version => 2 }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | $tree->set_path($path_without_extension . '.json', \$json); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | warn "$file_path does not appear to be a TAR file. Skipping metadata processing."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | $tree->set_path($file_path, $file_data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | #=method parse_cpanfile_snapshot | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # $distribution_spec= $cpan_repo->parse_cpanfile_snapshot($file_contents); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | #Given a scalar with the content of a cpanfile.snapshot from L<Carton>, this returns the data of | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | #that file as a hierarchial structure: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # "Distribution-Name-1.002003" => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # "pathname" => "A/AU/AUTHOR/Distribution-Name-1.002003.tar.gz", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | # "provides" => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | # "Distribution::Name" => '1.002003', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # ... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # "requirements" => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # "Dependency" => "2.05", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # ... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | #=cut | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | sub _context { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_context: not called CC=1 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | my $context= substr($_, pos($_), $_[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $context =~ s/\r/\\r/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $context =~ s/\n/\\n/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | return $context; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | sub _parse_cpanfile_snapshot($self, $text) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_cpanfile_snapshot: not called CC=13 SCAR=52.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # TODO: use official module if available, else fall back to this: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my %distributions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | local $_= $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | unless (eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | /^# carton snapshot format: version 1.0\r?\n/mgc | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | or die "Unsupported cpanfile.snapshot version\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | /\GDISTRIBUTIONS\r?\n/gc | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | or die "expected DISTRIBUTIONS\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | while (length > pos) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | my ($dist_name)= /\G (\S+)\r?\n/gc | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | or die "expected dist name\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | my $dist= $distributions{$dist_name}= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | while (/\G (\w[^\r\n:]*): *(.*?)\r?\n/gc) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my ($attr, $val)= ($1, $2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | if (length $val) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $dist->{$attr}= $val; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } else { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | while (/\G (.*)\r?\n/gc) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | push @{ $dist->{$attr} }, $1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | die "Unexpected sub-element of $dist_name $attr\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | if /\G /gc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | die "Unexpected sub-element of $dist_name\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | if /\G /gc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # convert 'provides' and 'requirements' to hashrefs of versions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | for (qw( provides requirements )) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | if (ref $dist->{$_} eq 'ARRAY') { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | $dist->{$_}= { map +((split ' ')[0,1]), @{$dist->{$_}} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | chomp $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | my $context= _context(20); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | croak "syntax error: $@, near \"$context\""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | \%distributions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 11 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||