| 1 | package Carmel::Builder; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Class::Tiny qw( snapshot cpanfile cpanfile_path repository_base collect_artifact ), { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 5 | 0 | ▶ | mirror => sub { $_[0]->build_mirror }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 6 | 1 | }; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carmel; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use File::pushd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Carmel::Lock; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carton::Dist; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use CPAN::DistnameInfo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Menlo::Index::Mirror; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use HTTP::Tinyish; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub tempdir { | ||||||||||||||||||||||||||
|
Subroutine
tempdir: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 19 | 0 | ▶ | $self->{tempdir} ||= $self->build_tempdir; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"tempdir"} ||= $self->build_tempdir
MC/DC0%0/2
$self->{"tempdir"} ||= $self->build_tempdir
$self->{"tempdir"}
$self->build_tempdir
Truth table0%0/3
A ||= B
A= $self->{"tempdir"}B= $self->build_tempdir
| |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub build_tempdir { | ||||||||||||||||||||||||||
|
Subroutine
build_tempdir: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 0 | my %opts = (); | |||||||||||||||||||||||||||
| 24 | $opts{CLEANUP} = $ENV{PERL_FILE_TEMP_CLEANUP} | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if exists $ENV{PERL_FILE_TEMP_CLEANUP}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | Path::Tiny->tempdir(%opts); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub build_mirror { | ||||||||||||||||||||||||||
|
Subroutine
build_mirror: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # FIXME: we could set the mirror option to $self->cpanfile in the caller | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my $cpanfile = $self->cpanfile_path | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | or die "Can't locate 'cpanfile' to load module list.\n"; | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # one mirror for now | ||||||||||||||||||||||||||||
| 38 | 0 | Module::CPANfile->load($cpanfile)->mirrors->[0]; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub install { | ||||||||||||||||||||||||||
|
Subroutine
install: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 0 | my($self, @args) = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | my @cmd; | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ($self->cpanfile) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | my $path = Path::Tiny->tempfile; | |||||||||||||||||||||||||||
| 47 | 0 | $self->cpanfile->save($path); | |||||||||||||||||||||||||||
| 48 | 0 | @cmd = ("--cpanfile", $path, "--installdeps", "."); | |||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||
| 50 | 0 | @cmd = @args; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ($self->snapshot) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | my $path = Path::Tiny->tempfile; | |||||||||||||||||||||||||||
| 55 | 0 | $self->snapshot->write_index($path); | |||||||||||||||||||||||||||
| 56 | 0 | unshift @cmd, | |||||||||||||||||||||||||||
| 57 | "--mirror-index", $path, | ||||||||||||||||||||||||||||
| 58 | "--cascade-search", | ||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | local $ENV{PERL_CPANM_HOME} = $self->tempdir; | |||||||||||||||||||||||||||
| 62 | 0 | local $ENV{PERL_CPANM_OPT}; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | my $mirror = $self->mirror; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my $lock = Carmel::Lock->new(path => $self->repository_base->child('run')); | |||||||||||||||||||||||||||
| 67 | 0 | $lock->acquire; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # cleanup perl5 in case it was left from previous runs | ||||||||||||||||||||||||||||
| 70 | 0 | my $lib = $self->repository_base->child('perl5'); | |||||||||||||||||||||||||||
| 71 | 0 | $lib->remove_tree({ safe => 0 }); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | require Menlo::CLI::Compat; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | my $cli = Menlo::CLI::Compat->new; | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | $cli->parse_options( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 77 | ($Carmel::DEBUG ? () : "--quiet"), | ||||||||||||||||||||||||||||
| 78 | ($mirror ? ("-M", $mirror) : ("--mirror", "https://cpan.metacpan.org/")), | ||||||||||||||||||||||||||||
| 79 | "--notest", | ||||||||||||||||||||||||||||
| 80 | "--save-dists", $self->repository_base->child('cache'), | ||||||||||||||||||||||||||||
| 81 | "-L", $lib, | ||||||||||||||||||||||||||||
| 82 | "--no-static-install", | ||||||||||||||||||||||||||||
| 83 | @cmd, | ||||||||||||||||||||||||||||
| 84 | ); | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | $cli->run; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | my @artifacts; | |||||||||||||||||||||||||||
| 89 | 0 | for my $ent ($self->tempdir->child("latest-build")->children) { | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | next unless $ent->is_dir && $ent->child("blib/meta/install.json")->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ent->is_dir and $ent->child("blib/meta/install.json")->exists
MC/DC0%0/2
$ent->is_dir and $ent->child("blib/meta/install.json")->exists
$ent->is_dir
$ent->child("blib/meta/install.json")->exists
Truth table0%0/3
A and B
A= $ent->is_dirB= $ent->child("blib/meta/install.json")->exists
| |||||||||||||||||||||||||||||
| 91 | 0 | push @artifacts, $self->collect_artifact->($ent); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | $lib->remove_tree({ safe => 0 }); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | return @artifacts; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub search_module { | ||||||||||||||||||||||||||
|
Subroutine
search_module: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | 0 | my($self, $module, $version) = @_; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | local $ENV{PERL_CPANM_HOME} = $self->tempdir; | |||||||||||||||||||||||||||
| 103 | 0 | local $ENV{PERL_CPANM_OPT}; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | my $cli = $self->cached_cli; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ($version && $version =~ /==|<|!/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$version and $version =~ /==|<|!/
MC/DC0%0/2
$version and $version =~ /==|<|!/
$version
$version =~ /==|<|!/
Truth table0%0/3
A and B
A= $versionB= $version =~ /==|<|!/
| |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | my $dist = $cli->search_module($module, $version) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | or return; | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | return Carton::Dist->new( | ||||||||||||||||||||||||||||
| 112 | name => $dist->{distvname}, | ||||||||||||||||||||||||||||
| 113 | pathname => $dist->{pathname}, | ||||||||||||||||||||||||||||
| 114 | provides => { | ||||||||||||||||||||||||||||
| 115 | $dist->{module} => { | ||||||||||||||||||||||||||||
| 116 | version => $dist->{module_version}, | ||||||||||||||||||||||||||||
| 117 | }, | ||||||||||||||||||||||||||||
| 118 | }, | ||||||||||||||||||||||||||||
| 119 | version => $dist->{version}, | ||||||||||||||||||||||||||||
| 120 | 0 | ); | |||||||||||||||||||||||||||
| 121 | } else { | ||||||||||||||||||||||||||||
| 122 | 0 | ▶ | my $res = $self->index->search_packages({ package => $module }) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | or return; | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | (my $path = $res->{uri}) =~ s!^cpan:///distfile/!!; | |||||||||||||||||||||||||||
| 126 | 0 | my $info = CPAN::DistnameInfo->new($path); | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | return Carton::Dist->new( | ||||||||||||||||||||||||||||
| 129 | name => $info->distvname, | ||||||||||||||||||||||||||||
| 130 | pathname => $info->pathname, | ||||||||||||||||||||||||||||
| 131 | provides => { | ||||||||||||||||||||||||||||
| 132 | $res->{package} => { | ||||||||||||||||||||||||||||
| 133 | version => $res->{version}, | ||||||||||||||||||||||||||||
| 134 | }, | ||||||||||||||||||||||||||||
| 135 | }, | ||||||||||||||||||||||||||||
| 136 | 0 | version => $info->version, | |||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub cached_cli { | ||||||||||||||||||||||||||
|
Subroutine
cached_cli: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 142 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | $self->{cli} ||= $self->build_cli(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"cli"} ||= $self->build_cli
MC/DC0%0/2
$self->{"cli"} ||= $self->build_cli
$self->{"cli"}
$self->build_cli
Truth table0%0/3
A ||= B
A= $self->{"cli"}B= $self->build_cli
| |||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub build_cli { | ||||||||||||||||||||||||||
|
Subroutine
build_cli: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 147 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | my $mirror = $self->mirror; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | require Menlo::CLI::Compat; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | my $cli = Menlo::CLI::Compat->new; | |||||||||||||||||||||||||||
| 154 | 0 | ▶ | $cli->parse_options( | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 155 | ($Carmel::DEBUG ? () : "--quiet"), | ||||||||||||||||||||||||||||
| 156 | ($mirror ? ("-M", $mirror) : ()), | ||||||||||||||||||||||||||||
| 157 | "--info", | ||||||||||||||||||||||||||||
| 158 | "--save-dists", $self->repository_base->child('cache'), | ||||||||||||||||||||||||||||
| 159 | ".", | ||||||||||||||||||||||||||||
| 160 | ); | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | # This needs to be done to setup http backends for mirror #52 | ||||||||||||||||||||||||||||
| 163 | 0 | $cli->setup_home; | |||||||||||||||||||||||||||
| 164 | 0 | $cli->init_tools; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | return $cli; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub index { | ||||||||||||||||||||||||||
|
Subroutine
index: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 170 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 171 | 0 | ▶ | $self->{index} ||= $self->build_index; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"index"} ||= $self->build_index
MC/DC0%0/2
$self->{"index"} ||= $self->build_index
$self->{"index"}
$self->build_index
Truth table0%0/3
A ||= B
A= $self->{"index"}B= $self->build_index
| |||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | sub build_index { | ||||||||||||||||||||||||||
|
Subroutine
build_index: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 175 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | my $mirror = $self->mirror || "https://cpan.metacpan.org/"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->mirror || 'https://cpan.metacpan.org/'
MC/DC0%0/1
$self->mirror || 'https://cpan.metacpan.org/'
$self->mirror
Truth table0%0/2
A
A= $self->mirror
| |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | # Use $cli->mirror to support file: URLs | ||||||||||||||||||||||||||||
| 180 | return Menlo::Index::Mirror->new({ | ||||||||||||||||||||||||||||
| 181 | mirror => $mirror, | ||||||||||||||||||||||||||||
| 182 | 0 | ▶ | fetcher => sub { $self->cached_cli->mirror(@_) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 183 | 0 | }); | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub rollout { | ||||||||||||||||||||||||||
|
Subroutine
rollout: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 187 | 0 | my($self, $install_base, $artifacts) = @_; | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | require ExtUtils::Install; | |||||||||||||||||||||||||||
| 190 | 0 | require ExtUtils::InstallPaths; | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 0 | for my $artifact (@$artifacts) { | |||||||||||||||||||||||||||
| 193 | 0 | my $dir = pushd $artifact->path; | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | my $paths = ExtUtils::InstallPaths->new(install_base => $install_base); | |||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | printf "Installing %s to %s\n", $artifact->distname, $install_base; | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | # ExtUtils::Install writes to STDOUT | ||||||||||||||||||||||||||||
| 200 | 0 | open my $fh, ">", \my $output; | |||||||||||||||||||||||||||
| 201 | 0 | ▶ | my $old; $old = select $fh unless $Carmel::DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 0 | my %result; | |||||||||||||||||||||||||||
| 204 | 0 | ExtUtils::Install::install([ | |||||||||||||||||||||||||||
| 205 | from_to => $paths->install_map, | ||||||||||||||||||||||||||||
| 206 | verbose => 0, | ||||||||||||||||||||||||||||
| 207 | dry_run => 0, | ||||||||||||||||||||||||||||
| 208 | uninstall_shadows => 0, | ||||||||||||||||||||||||||||
| 209 | skip => undef, | ||||||||||||||||||||||||||||
| 210 | always_copy => 1, | ||||||||||||||||||||||||||||
| 211 | result => \%result, | ||||||||||||||||||||||||||||
| 212 | ]); | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | ▶ | select $old unless $Carmel::DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 1 | 1; | |||||||||||||||||||||||||||