| 1 | package Dist::Zilla::Role::DynamicPrereqs::Meta; | ||||||||||||
| 2 | 6 | $Dist::Zilla::Role::DynamicPrereqs::Meta::VERSION = '0.007'; | |||||||||||
| 3 | 6 | ▶ | use 5.020; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 6 | ▶ | use Moose::Role; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 6 | ▶ | use experimental qw/signatures postderef/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 6 | with 'Dist::Zilla::Role::MetaProvider'; | |||||||||||
| 8 | |||||||||||||
| 9 | 6 | ▶ | use Carp 'croak'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 6 | ▶ | use Cpanel::JSON::XS; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 6 | ▶ | use Dist::Zilla::File::InMemory; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 6 | ▶ | use MooseX::Types::Moose qw/ArrayRef Str/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 6 | ▶ | use MooseX::Enumeration; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 6 | ▶ | use Text::ParseWords 'shellwords'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | |||||||||||||
| 16 | 6 | my $coder = Cpanel::JSON::XS->new->pretty; | |||||||||||
| 17 | |||||||||||||
| 18 | 6 | my %aliases = ( | |||||||||||
| 19 | condition => 'conditions', | ||||||||||||
| 20 | prereq => 'prereqs', | ||||||||||||
| 21 | ); | ||||||||||||
| 22 | |||||||||||||
| 23 | 3 | ▶ | around 'mvp_multivalue_args', sub($orig, $self) { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 3 | return ($self->$orig, values %aliases); | |||||||||||
| 25 | 6 | }; | |||||||||||
| 26 | |||||||||||||
| 27 | 3 | ▶ | around 'mvp_aliases', sub($orig, $self) { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 3 | return { $self->$orig->%*, %aliases }; | |||||||||||
| 29 | 6 | }; | |||||||||||
| 30 | |||||||||||||
| 31 | 6 | has joiner => ( | |||||||||||
| 32 | is => 'ro', | ||||||||||||
| 33 | traits => ['Enumeration'], | ||||||||||||
| 34 | default => 'and', | ||||||||||||
| 35 | enum => [qw/and or/], | ||||||||||||
| 36 | ); | ||||||||||||
| 37 | |||||||||||||
| 38 | 6 | has input_conditions => ( | |||||||||||
| 39 | init_arg => 'conditions', | ||||||||||||
| 40 | required => 1, | ||||||||||||
| 41 | isa => ArrayRef[Str], | ||||||||||||
| 42 | traits => ['Array'], | ||||||||||||
| 43 | handles => { | ||||||||||||
| 44 | input_conditions => 'elements', | ||||||||||||
| 45 | }, | ||||||||||||
| 46 | ); | ||||||||||||
| 47 | |||||||||||||
| 48 | 6 | has input_prereqs => ( | |||||||||||
| 49 | init_arg => 'prereqs', | ||||||||||||
| 50 | traits => ['Array'], | ||||||||||||
| 51 | isa => ArrayRef, | ||||||||||||
| 52 | handles => { | ||||||||||||
| 53 | input_prereqs => 'elements', | ||||||||||||
| 54 | }, | ||||||||||||
| 55 | ); | ||||||||||||
| 56 | |||||||||||||
| 57 | 6 | has error => ( | |||||||||||
| 58 | is => 'ro', | ||||||||||||
| 59 | isa => Str, | ||||||||||||
| 60 | ); | ||||||||||||
| 61 | |||||||||||||
| 62 | 6 | has phase => ( | |||||||||||
| 63 | is => 'ro', | ||||||||||||
| 64 | isa => Str, | ||||||||||||
| 65 | default => 'runtime', | ||||||||||||
| 66 | ); | ||||||||||||
| 67 | |||||||||||||
| 68 | 6 | has relationship => ( | |||||||||||
| 69 | is => 'ro', | ||||||||||||
| 70 | isa => Str, | ||||||||||||
| 71 | default => 'requires', | ||||||||||||
| 72 | ); | ||||||||||||
| 73 | |||||||||||||
| 74 | 3 | ▶ | sub metadata($self) { | ||||||||||
|
Subroutine
metadata: called CC=8 SCAR=21.2
Pod
undocumented
| |||||||||||||
| 75 | 3 | ▶ | if (my @input_conditions = $self->input_conditions) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | 3 | my @conditions = map { [ shellwords($_) ] } @input_conditions; | |||||||||||
| 77 | 3 | ▶ | my $condition = @conditions == 1 ? $conditions[0] : [ $self->joiner, @conditions ]; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | 3 | my %entry = ( condition => $condition ); | |||||||||||
| 79 | 3 | ▶ | $entry{phase} = $self->phase if $self->phase ne 'runtime'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | 3 | ▶ | $entry{relationship} = $self->relationship if $self->relationship ne 'requires'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 81 | 3 | ▶ | if ($self->error) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 1 | $entry{error} = $self->error; | |||||||||||
| 83 | } else { | ||||||||||||
| 84 | 2 | my %result; | |||||||||||
| 85 | 2 | for my $line ($self->input_prereqs) { | |||||||||||
| 86 | 2 | my ($module, $version) = split ' ', $line, 2; | |||||||||||
| 87 | 2 | ▶ | $result{$module} = $version // 0; | ||||||||||
|
Condition50%1/2
$version // 0
MC/DC0%0/1
$version // 0
$version
Truth table50%1/2
A
A= $version
| |||||||||||||
| 88 | } | ||||||||||||
| 89 | 2 | $entry{prereqs} = \%result; | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | return { | ||||||||||||
| 93 | 3 | dynamic_config => 1, | |||||||||||
| 94 | x_static_install => 0, | ||||||||||||
| 95 | x_dynamic_prereqs => { | ||||||||||||
| 96 | version => 1, | ||||||||||||
| 97 | expressions => [ | ||||||||||||
| 98 | \%entry | ||||||||||||
| 99 | ], | ||||||||||||
| 100 | }, | ||||||||||||
| 101 | }; | ||||||||||||
| 102 | } else { | ||||||||||||
| 103 | 0 | return {}; | |||||||||||
| 104 | } | ||||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | 6 | 1; | |||||||||||
| 108 | |||||||||||||
| 109 | # ABSTRACT: A role to add dynamic prereqs to to the metadata in your Dist::Zilla build | ||||||||||||
| 110 | |||||||||||||
| 111 | __END__ | ||||||||||||