| 1 | package CPAN::Requirements::Dynamic; | ||||||||||||||||||||
| 2 | 1 | $CPAN::Requirements::Dynamic::VERSION = '0.003'; | |||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | ▶ | use Carp 'croak'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Parse::CPAN::Meta; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 3 | ▶ | sub _version_satisfies { | ||||||||||||||||||
|
Subroutine
_version_satisfies: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 3 | my ($version, $range) = @_; | |||||||||||||||||||
| 11 | 3 | require CPAN::Meta::Requirements::Range; | |||||||||||||||||||
| 12 | 3 | return CPAN::Meta::Requirements::Range->with_string_requirement($range)->accepts($version); | |||||||||||||||||||
| 13 | } | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | my %default_commands = ( | ||||||||||||||||||||
| 16 | 0 | ▶ | can_run => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 17 | 0 | my ($self, $command) = @_; | |||||||||||||||||||
| 18 | 0 | require IPC::Cmd; | |||||||||||||||||||
| 19 | 0 | return IPC::Cmd::can_run($command); | |||||||||||||||||||
| 20 | }, | ||||||||||||||||||||
| 21 | 1 | ▶ | config_defined => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||
| 22 | 1 | my ($self, $entry) = @_; | |||||||||||||||||||
| 23 | 1 | ▶ | return ($self->{config}->get($entry) // '') eq 'define'; | ||||||||||||||||||
|
Condition50%1/2
$self->{"config"}->get($entry) // ""
MC/DC0%0/1
$self->{"config"}->get($entry) // ""
$self->{"config"}->get($entry)
Truth table50%1/2
A
A= $self->{"config"}->get($entry)
| |||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||
| 25 | 0 | ▶ | has_env => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 26 | 0 | my ($self, $entry) = @_; | |||||||||||||||||||
| 27 | 0 | return !!$ENV{$entry}; | |||||||||||||||||||
| 28 | }, | ||||||||||||||||||||
| 29 | 3 | ▶ | has_perl => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | 3 | my ($self, $range) = @_; | |||||||||||||||||||
| 31 | 3 | return _version_satisfies($], $range); | |||||||||||||||||||
| 32 | }, | ||||||||||||||||||||
| 33 | 0 | ▶ | is_extended => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 34 | 0 | return !!$ENV{EXTENDED_TESTING}; | |||||||||||||||||||
| 35 | }, | ||||||||||||||||||||
| 36 | 2 | ▶ | is_os => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | 2 | my ($self, @wanted) = @_; | |||||||||||||||||||
| 38 | 2 | return !!grep { $_ eq $^O } @wanted | |||||||||||||||||||
| 39 | }, | ||||||||||||||||||||
| 40 | 0 | ▶ | is_os_type => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 41 | 0 | my ($self, $wanted) = @_; | |||||||||||||||||||
| 42 | 0 | require Perl::OSType; | |||||||||||||||||||
| 43 | 0 | return Perl::OSType::is_os_type($wanted); | |||||||||||||||||||
| 44 | }, | ||||||||||||||||||||
| 45 | 0 | ▶ | is_smoker => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 46 | 0 | return !!$ENV{AUTOMATED_TESTING}; | |||||||||||||||||||
| 47 | }, | ||||||||||||||||||||
| 48 | 0 | ▶ | want_xs => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 49 | 0 | my ($self) = @_; | |||||||||||||||||||
| 50 | 0 | ▶ | return !!0 if $self->{pureperl_only}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 0 | require ExtUtils::HasCompiler; | |||||||||||||||||||
| 52 | 0 | return ExtUtils::HasCompiler::can_compile_extension(config => $self->{config}); | |||||||||||||||||||
| 53 | }, | ||||||||||||||||||||
| 54 | 1 | ); | |||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 1 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=15.5
Pod
documented
| |||||||||||||||||||||
| 57 | 1 | my ($class, %args) = @_; | |||||||||||||||||||
| 58 | return bless { | ||||||||||||||||||||
| 59 | 1 | ▶ | config => $args{config} || do { require ExtUtils::Config; ExtUtils::Config->new }, | ||||||||||||||||||
|
Condition33%1/3
$args{'prereqs'} || do {
require CPAN::Meta::Prereqs;
'CPAN::Meta::Prereqs'->new
}
MC/DC0%0/2
$args{'prereqs'} || do {
require CPAN::Meta::Prereqs;
'CPAN::Meta::Prereqs'->new
}
$args{'prereqs'}
do {
require CPAN::Meta::Prereqs;
'CPAN::Meta::Prereqs'->new
}
Truth table33%1/3
A || B
A= $args{'prereqs'}B= do {
require CPAN::Meta::Prereqs;
'CPAN::Meta::Prereqs'->new
}
| |||||||||||||||||||||
| 60 | 1 | ▶ | prereqs => $args{prereqs} || do { require CPAN::Meta::Prereqs; CPAN::Meta::Prereqs->new }, | ||||||||||||||||||
|
Condition50%1/2
$args{'commands'} || \%default_commands
MC/DC0%0/1
$args{'commands'} || \%default_commands
$args{'commands'}
Truth table50%1/2
A
A= $args{'commands'}
| |||||||||||||||||||||
| 61 | commands => $args{commands} || \%default_commands, | ||||||||||||||||||||
| 62 | pureperl_only => $args{pureperl_only}, | ||||||||||||||||||||
| 63 | 1 | ▶ | }, $class; | ||||||||||||||||||
|
Condition33%1/3
$args{'config'} || do {
require ExtUtils::Config;
'ExtUtils::Config'->new
}
MC/DC0%0/2
$args{'config'} || do {
require ExtUtils::Config;
'ExtUtils::Config'->new
}
$args{'config'}
do {
require ExtUtils::Config;
'ExtUtils::Config'->new
}
Truth table33%1/3
A || B
A= $args{'config'}B= do {
require ExtUtils::Config;
'ExtUtils::Config'->new
}
| |||||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 8 | ▶ | sub _get_command { | ||||||||||||||||||
|
Subroutine
_get_command: called CC=4 SCAR=14.1
| |||||||||||||||||||||
| 67 | 8 | my ($self, $name) = @_; | |||||||||||||||||||
| 68 | 8 | ▶ | if ($name eq 'or') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 69 | 1 | ▶ | return sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||
| 70 | 1 | my ($self, @each) = @_; | |||||||||||||||||||
| 71 | 1 | for my $elem (@each) { | |||||||||||||||||||
| 72 | 1 | ▶ | return !!1 if $self->_run_condition($elem); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 0 | return !!0; | |||||||||||||||||||
| 75 | 1 | }; | |||||||||||||||||||
| 76 | } elsif ($name eq 'and') { | ||||||||||||||||||||
| 77 | 1 | ▶ | return sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||
| 78 | 1 | my ($self, @each) = @_; | |||||||||||||||||||
| 79 | 1 | for my $elem (@each) { | |||||||||||||||||||
| 80 | 2 | ▶ | return !!0 if not $self->_run_condition($elem); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | 0 | return !!1; | |||||||||||||||||||
| 83 | 1 | }; | |||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||
| 85 | 6 | ▶ | return $self->{commands}{$name} || croak "No such command $name"; | ||||||||||||||||||
|
Condition50%1/2
$self->{'commands'}{$name} || croak("No such command $name")
MC/DC0%0/1
$self->{'commands'}{$name} || croak("No such command $name")
$self->{'commands'}{$name}
Truth table50%1/2
A
A= $self->{'commands'}{$name}
| |||||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 8 | ▶ | sub _run_condition { | ||||||||||||||||||
|
Subroutine
_run_condition: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 90 | 8 | my ($self, $condition) = @_; | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 8 | my $negate = !!0; | |||||||||||||||||||
| 93 | 8 | my ($function, @arguments) = @{ $condition }; | |||||||||||||||||||
| 94 | 8 | ▶ | while ($function eq 'not') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | 1 | $function = shift @arguments; | |||||||||||||||||||
| 96 | 1 | $negate = !$negate; | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 8 | my $method = $self->_get_command($function); | |||||||||||||||||||
| 100 | 8 | my $primary = $self->$method(@arguments); | |||||||||||||||||||
| 101 | 8 | ▶ | return $negate ? !$primary : $primary; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 1 | ▶ | sub evaluate { | ||||||||||||||||||
|
Subroutine
evaluate: called CC=8 SCAR=21.7
Pod
documented
| |||||||||||||||||||||
| 105 | 1 | my ($self, $argument) = @_; | |||||||||||||||||||
| 106 | 1 | my $version = $argument->{version}; | |||||||||||||||||||
| 107 | 1 | ▶ | croak "Dynamic prereqs spec version $version is not supported" if int $version > 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 108 | 1 | my @prereqs; | |||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 1 | for my $entry (@{ $argument->{expressions} }) { | |||||||||||||||||||
| 111 | 5 | ▶ | if ($self->_run_condition($entry->{condition})) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | 3 | ▶ | if ($entry->{error}) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 113 | 0 | die "$entry->{error}\n"; | |||||||||||||||||||
| 114 | } elsif (my $prereqs = $entry->{prereqs}) { | ||||||||||||||||||||
| 115 | 3 | ▶ | my $phase = $entry->{phase} || 'runtime'; | ||||||||||||||||||
|
Condition50%1/2
$entry->{'phase'} || 'runtime'
MC/DC0%0/1
$entry->{'phase'} || 'runtime'
$entry->{'phase'}
Truth table50%1/2
A
A= $entry->{'phase'}
| |||||||||||||||||||||
| 116 | 3 | ▶ | my $relation = $entry->{relation} || 'requires'; | ||||||||||||||||||
|
Condition50%1/2
$entry->{'relation'} || 'requires'
MC/DC0%0/1
$entry->{'relation'} || 'requires'
$entry->{'relation'}
Truth table50%1/2
A
A= $entry->{'relation'}
| |||||||||||||||||||||
| 117 | 3 | my $prereqs = { $phase => { $relation => $entry->{prereqs} } }; | |||||||||||||||||||
| 118 | 3 | push @prereqs, CPAN::Meta::Prereqs->new($prereqs); | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 1 | return $self->{prereqs}->with_merged_prereqs(\@prereqs); | |||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 0 | ▶ | sub evaluate_file { | ||||||||||||||||||
|
Subroutine
evaluate_file: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 127 | 0 | my ($self, $filename) = @_; | |||||||||||||||||||
| 128 | 0 | my $structure = Parse::CPAN::Meta->load_file($filename); | |||||||||||||||||||
| 129 | 0 | return $self->evaluate($structure); | |||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | 1 | 1; | |||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | # ABSTRACT: Dynamic prerequisites in meta files | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | __END__ | ||||||||||||||||||||