blib/lib/CPAN/Requirements/Dynamic.pm

filter: Statementstmt 76.4% 65 / 85 Branchbran 72.7% 16 / 22 Conditioncond 40.0% 6 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 66.6% 14 / 21 Podpod 100% 3 / 3 totaltotal 67.1% 104 / 155 CC 21 SCAR 14.0
CC
21
Cov
71%
evaluate
8.8
__ANON__
6.0
new
4.7
CRAP 4.0
↑ Summary
1 package CPAN::Requirements::Dynamic;
2 1 $CPAN::Requirements::Dynamic::VERSION = '0.002';
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 sub _version_satisfies {
10 3 ▶ my ($version, $range) = @_;
Subroutine _version_satisfies: called CC=1 SCAR=0.0
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 can_run => sub {
17 0 ▶ my ($self, $command) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 0 require IPC::Cmd;
19 0 return IPC::Cmd::can_run($command);
20 },
21 config_defined => sub {
22 1 ▶ my ($self, $entry) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
23 1 return $self->{config}->get($entry) eq 'define';
24 },
25 has_env => sub {
26 0 ▶ my ($self, $entry) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 0 return !!$ENV{$entry};
28 },
29 has_perl => sub {
30 3 ▶ my ($self, $range) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
31 3 return _version_satisfies($], $range);
32 },
33 is_extended => sub {
34 0 ▶ return !!$ENV{EXTENDED_TESTING};
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 },
36 is_os => sub {
37 2 ▶ my ($self, @wanted) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
38 2 return !!grep { $_ eq $^O } @wanted
39 },
40 is_os_type => sub {
41 0 ▶ my ($self, $wanted) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 0 require Perl::OSType;
43 0 return Perl::OSType::is_os_type($wanted);
44 },
45 is_smoker => sub {
46 0 ▶ return !!$ENV{AUTOMATED_TESTING};
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 },
48 want_xs => sub {
49 0 ▶ my ($self) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
50 0 ▶ return !!0 if $self->{pureperl_only};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pureperl_only"} 0 0 0
51 0 require ExtUtils::HasCompiler;
52 0 return ExtUtils::HasCompiler::can_compile_extension(config => $self->{config});
53 },
54 1 );
55  
56 sub new {
57 1 ▶ my ($class, %args) = @_;
Subroutine new: called CC=4 SCAR=15.5
Pod documented
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 }
l!l&&r!l&&!r
010
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 }
ABresult
1X1
011
000
60 1 ▶ prereqs => $args{prereqs} || do { require CPAN::Meta::Prereqs; CPAN::Meta::Prereqs->new },
Condition50%1/2
$args{'commands'} || \%default_commands
l!l
01
MC/DC0%0/1
$args{'commands'} || \%default_commands
$args{'commands'}
Truth table50%1/2
A
A= $args{'commands'}
Aresult
11
00
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 }
l!l&&r!l&&!r
010
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 }
ABresult
1X1
011
000
64 }
65  
66 sub _get_command {
67 8 ▶ my ($self, $name) = @_;
Subroutine _get_command: called CC=4 SCAR=14.2
68 8 ▶ if ($name eq 'or') {
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'or') { } 1 7 8
elsif ($name eq 'and') { } 1 6 7
69 return sub {
70 1 ▶ my ($self, @each) = @_;
Subroutine __ANON__: called CC=3 SCAR=12.0
71 1 for my $elem (@each) {
72 1 ▶ return !!1 if $self->_run_condition($elem);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_run_condition($elem) 1 0 1
73 }
74 0 return !!0;
75 1 };
76 } elsif ($name eq 'and') {
77 return sub {
78 1 ▶ my ($self, @each) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.1
79 1 for my $elem (@each) {
80 2 ▶ return !!0 if not $self->_run_condition($elem);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_run_condition($elem) 1 1 2
81 }
82 0 return !!1;
83 1 };
84 } else {
85 6 ▶ return $self->{commands}{$name} || croak "No such command $name";
Condition33%1/3
$self->{'commands'}{$name} || croak("No such command $name")
l!l&&r!l&&!r
600
MC/DC0%0/2
$self->{'commands'}{$name} || croak("No such command $name")
$self->{'commands'}{$name} croak("No such command $name")
Truth table33%1/3
A || B
A= $self->{'commands'}{$name}B= croak("No such command $name")
ABresult
1X1
011
000
86 }
87 }
88  
89 sub _run_condition {
90 8 ▶ my ($self, $condition) = @_;
Subroutine _run_condition: called CC=3 SCAR=11.0
91  
92 8 my $negate = !!0;
93 8 my ($function, @arguments) = @{ $condition };
94 8 ▶ while ($function eq 'not') {
Branch: 1 branch
BranchTrueFalseTotal
if ($function eq "not") 1 8 9
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
BranchTrueFalseTotal
$negate ? : 1 7 8
102 }
103  
104 sub evaluate {
105 1 ▶ my ($self, $argument) = @_;
Subroutine evaluate: called CC=8 SCAR=21.7
Pod documented
106 1 my $version = $argument->{version};
107 1 ▶ croak "Dynamic prereqs spec version $version is not supported" if int $version > 1;
Branch: 1 branch
BranchTrueFalseTotal
if int $version > 1 0 1 1
108 1 my @prereqs;
109  
110 1 for my $entry (@{ $argument->{expressions} }) {
111 5 ▶ if ($self->_run_condition($entry->{condition})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_run_condition($entry->{"condition"})) 3 2 5
112 3 ▶ if ($entry->{error}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($entry->{'error'}) { } 0 3 3
elsif (my $prereqs = $entry->{'prereqs'}) { } 3 0 3
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'
l!l
03
MC/DC0%0/1
$entry->{'phase'} || 'runtime'
$entry->{'phase'}
Truth table50%1/2
A
A= $entry->{'phase'}
Aresult
11
00
116 3 ▶ my $relation = $entry->{relation} || 'requires';
Condition50%1/2
$entry->{'relation'} || 'requires'
l!l
03
MC/DC0%0/1
$entry->{'relation'} || 'requires'
$entry->{'relation'}
Truth table50%1/2
A
A= $entry->{'relation'}
Aresult
11
00
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 sub evaluate_file {
127 0 ▶ my ($self, $filename) = @_;
Subroutine evaluate_file: not called CC=1 SCAR=6.9
Pod documented
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__
↑ Summary