| 1 | package App::CpanDak::Specials; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use CPAN::Meta::YAML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | our $VERSION = '0.1.0'; # VERSION | |||||||||||||||||||||||||||
| 8 | # ABSTRACT: fetch and expose the "special" instructions for distributions | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 6 | my ($class, $path) = @_; | |||||||||||||||||||||||||||
| 13 | 6 | ▶ | $path ||= $ENV{PERL_CPANDAK_SPECIALS_PATH}; | ||||||||||||||||||||||||||
|
Condition100%3/3
$path ||= $ENV{"PERL_CPANDAK_SPECIALS_PATH"}
MC/DC100%2/2
$path ||= $ENV{"PERL_CPANDAK_SPECIALS_PATH"}
$path
$ENV{"PERL_CPANDAK_SPECIALS_PATH"}
Truth table100%3/3
A ||= B
A= $pathB= $ENV{"PERL_CPANDAK_SPECIALS_PATH"}
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 6 | return bless { | |||||||||||||||||||||||||||
| 16 | path => $path, | ||||||||||||||||||||||||||||
| 17 | }, $class; | ||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 5 | ▶ | sub _vname { | ||||||||||||||||||||||||||
|
Subroutine
_vname: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||
| 21 | 5 | my ($dist) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 5 | ▶ | return $dist->{distvname} if $dist->{distvname}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 5 | ▶ | return "$dist->{meta}{name}-$dist->{meta}{version}" if $dist->{meta}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 5 | ▶ | return "$dist->{dist}-$dist->{version}" if $dist->{dist} && $dist->{version}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dist->{"dist"} and $dist->{"version"}
MC/DC50%1/2
$dist->{"dist"} and $dist->{"version"}
$dist->{"dist"}
$dist->{"version"}
Truth table66%2/3
A and B
A= $dist->{"dist"}B= $dist->{"version"}
| |||||||||||||||||||||||||||||
| 26 | 2 | return undef; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 4 | ▶ | sub _name { | ||||||||||||||||||||||||||
|
Subroutine
_name: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 30 | 4 | my ($dist) = @_; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 4 | ▶ | return $dist->{meta}{name} if $dist->{meta}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 4 | return $dist->{dist}; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 5 | ▶ | sub match_for { | ||||||||||||||||||||||||||
|
Subroutine
match_for: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 5 | my ($self, $dist, $ext) = @_; | |||||||||||||||||||||||||||
| 39 | 5 | ▶ | $ext //= ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$ext //= ""
MC/DC0%0/1
$ext //= ""
$ext
Truth table50%1/2
A
A= $ext
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # no point looking for matches if we don't have a "specials" | ||||||||||||||||||||||||||||
| 42 | # directory to look into | ||||||||||||||||||||||||||||
| 43 | my $path = $self->{path} | ||||||||||||||||||||||||||||
| 44 | 5 | ▶ | or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 4 | for my $name ( | |||||||||||||||||||||||||||
| 47 | _vname($dist), | ||||||||||||||||||||||||||||
| 48 | _name($dist), | ||||||||||||||||||||||||||||
| 49 | ) { | ||||||||||||||||||||||||||||
| 50 | 8 | ▶ | next unless $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 6 | $name = "$path/$name$ext"; | |||||||||||||||||||||||||||
| 52 | 6 | ▶ | return $name if -e $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | return undef; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub all_options_for { | ||||||||||||||||||||||||||
|
Subroutine
all_options_for: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 0 | my ($self, $dist) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $options_file = $self->match_for($dist, '.options.yml') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | or return; | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | return CPAN::Meta::YAML::LoadFile($options_file); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub option_for { | ||||||||||||||||||||||||||
|
Subroutine
option_for: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 70 | 0 | my ($self, $dist, $key) = @_; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $options = $self->all_options_for($dist) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | or return; | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | return $options->{$key}; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | ▶ | sub env_for { | ||||||||||||||||||||||||||
|
Subroutine
env_for: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 1 | my ($self, $dist, $phase) = @_; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | ▶ | my $env_file = $self->match_for($dist, ".$phase.env.yml") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | or return {}; | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 1 | return CPAN::Meta::YAML::LoadFile($env_file); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 1 | ▶ | sub apply_patch_to { | ||||||||||||||||||||||||||
|
Subroutine
apply_patch_to: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 1 | my ($self, $dist, $dir) = @_; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 1 | ▶ | my $patch_file = $self->match_for($dist, '.patch') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | or return; | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 1 | my $rc = system patch => ( | |||||||||||||||||||||||||||
| 96 | -d => $dir, | ||||||||||||||||||||||||||||
| 97 | '-f', | ||||||||||||||||||||||||||||
| 98 | -i => $patch_file, | ||||||||||||||||||||||||||||
| 99 | -p => 1, | ||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 1 | ▶ | return if $rc == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1 | require Carp; | |||||||||||||||||||||||||||
| 105 | 1 | Carp::croak('! Patching '._vname($dist).' failed'); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 4 | 1; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||||||||||