| 1 | 7 | ▶ | use 5.006; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 2 | 7 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 3 | 7 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | package Dist::Zilla::Plugin::Prereqs::Soften; | ||||||||||||||||||||||
| 6 | |||||||||||||||||||||||
| 7 | 7 | our $VERSION = '0.006003'; | |||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | # ABSTRACT: Downgrade listed dependencies to recommendations if present. | ||||||||||||||||||||||
| 10 | |||||||||||||||||||||||
| 11 | 7 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||||||||||||||
| 12 | |||||||||||||||||||||||
| 13 | 7 | ▶ | use Moose qw( with has around ); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 14 | 7 | ▶ | use MooseX::Types::Moose qw( ArrayRef HashRef Str Bool ); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 15 | 7 | with 'Dist::Zilla::Role::PrereqSource'; | |||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | |||||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | |||||||||||||||||||||||
| 23 | has 'modules' => ( | ||||||||||||||||||||||
| 24 | is => ro =>, | ||||||||||||||||||||||
| 25 | isa => ArrayRef [Str], | ||||||||||||||||||||||
| 26 | lazy => 1, | ||||||||||||||||||||||
| 27 | 1 | ▶ | default => sub { [] }, | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 28 | 7 | ); | |||||||||||||||||||||
| 29 | |||||||||||||||||||||||
| 30 | |||||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | |||||||||||||||||||||||
| 33 | |||||||||||||||||||||||
| 34 | |||||||||||||||||||||||
| 35 | |||||||||||||||||||||||
| 36 | |||||||||||||||||||||||
| 37 | |||||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 39 | |||||||||||||||||||||||
| 40 | |||||||||||||||||||||||
| 41 | |||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | |||||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | |||||||||||||||||||||||
| 48 | 7 | ▶ | use Moose::Util::TypeConstraints qw(enum); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | has 'to_relationship' => ( | ||||||||||||||||||||||
| 51 | is => ro =>, | ||||||||||||||||||||||
| 52 | isa => enum( [qw(none requires recommends suggests conflicts)] ), | ||||||||||||||||||||||
| 53 | lazy => 1, | ||||||||||||||||||||||
| 54 | 3 | ▶ | default => sub { 'recommends' }, | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 55 | 7 | ); | |||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | 7 | ▶ | no Moose::Util::TypeConstraints; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 58 | |||||||||||||||||||||||
| 59 | |||||||||||||||||||||||
| 60 | |||||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | |||||||||||||||||||||||
| 63 | |||||||||||||||||||||||
| 64 | |||||||||||||||||||||||
| 65 | |||||||||||||||||||||||
| 66 | |||||||||||||||||||||||
| 67 | |||||||||||||||||||||||
| 68 | |||||||||||||||||||||||
| 69 | |||||||||||||||||||||||
| 70 | |||||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | |||||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | |||||||||||||||||||||||
| 76 | |||||||||||||||||||||||
| 77 | |||||||||||||||||||||||
| 78 | |||||||||||||||||||||||
| 79 | |||||||||||||||||||||||
| 80 | |||||||||||||||||||||||
| 81 | |||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | |||||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | |||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | |||||||||||||||||||||||
| 89 | |||||||||||||||||||||||
| 90 | has 'copy_to' => ( | ||||||||||||||||||||||
| 91 | is => 'ro', | ||||||||||||||||||||||
| 92 | isa => ArrayRef [Str], | ||||||||||||||||||||||
| 93 | lazy => 1, | ||||||||||||||||||||||
| 94 | 3 | ▶ | default => sub { [] }, | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 95 | 7 | ); | |||||||||||||||||||||
| 96 | |||||||||||||||||||||||
| 97 | 7 | has '_copy_to_extras' => ( | |||||||||||||||||||||
| 98 | is => 'ro', | ||||||||||||||||||||||
| 99 | isa => ArrayRef [HashRef], | ||||||||||||||||||||||
| 100 | lazy => 1, | ||||||||||||||||||||||
| 101 | builder => '_build__copy_to_extras', | ||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||
| 103 | |||||||||||||||||||||||
| 104 | |||||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | |||||||||||||||||||||||
| 107 | |||||||||||||||||||||||
| 108 | |||||||||||||||||||||||
| 109 | |||||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | |||||||||||||||||||||||
| 112 | |||||||||||||||||||||||
| 113 | |||||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | |||||||||||||||||||||||
| 116 | |||||||||||||||||||||||
| 117 | |||||||||||||||||||||||
| 118 | |||||||||||||||||||||||
| 119 | |||||||||||||||||||||||
| 120 | |||||||||||||||||||||||
| 121 | |||||||||||||||||||||||
| 122 | |||||||||||||||||||||||
| 123 | has 'modules_from_features' => ( | ||||||||||||||||||||||
| 124 | is => ro =>, | ||||||||||||||||||||||
| 125 | isa => Bool, | ||||||||||||||||||||||
| 126 | lazy => 1, | ||||||||||||||||||||||
| 127 | 5 | ▶ | default => sub { return }, | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 128 | 7 | ); | |||||||||||||||||||||
| 129 | |||||||||||||||||||||||
| 130 | 7 | has '_modules_hash' => ( | |||||||||||||||||||||
| 131 | is => ro =>, | ||||||||||||||||||||||
| 132 | isa => HashRef, | ||||||||||||||||||||||
| 133 | lazy => 1, | ||||||||||||||||||||||
| 134 | builder => _build__modules_hash =>, | ||||||||||||||||||||||
| 135 | ); | ||||||||||||||||||||||
| 136 | |||||||||||||||||||||||
| 137 | 0 | ▶ | around dump_config => sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 138 | 0 | my ( $orig, $self, @args ) = @_; | |||||||||||||||||||||
| 139 | 0 | my $config = $self->$orig(@args); | |||||||||||||||||||||
| 140 | 0 | my $payload = $config->{ +__PACKAGE__ } = {}; | |||||||||||||||||||||
| 141 | |||||||||||||||||||||||
| 142 | 0 | $payload->{modules} = $self->modules; | |||||||||||||||||||||
| 143 | 0 | $payload->{to_relationship} = $self->to_relationship; | |||||||||||||||||||||
| 144 | 0 | $payload->{copy_to} = $self->copy_to; | |||||||||||||||||||||
| 145 | 0 | $payload->{modules_from_features} = $self->modules_from_features; | |||||||||||||||||||||
| 146 | |||||||||||||||||||||||
| 147 | # inject $VERSION when subclassed | ||||||||||||||||||||||
| 148 | 0 | ▶ | $payload->{ q[$] . __PACKAGE__ . q[::VERSION] } = $VERSION unless __PACKAGE__ eq ref $self; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 149 | 0 | return $config; | |||||||||||||||||||||
| 150 | 7 | }; | |||||||||||||||||||||
| 151 | |||||||||||||||||||||||
| 152 | 7 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||
| 153 | 7 | ▶ | no Moose; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 154 | |||||||||||||||||||||||
| 155 | 6 | ▶ | sub mvp_multivalue_args { return qw(modules copy_to) } | ||||||||||||||||||||
|
Subroutine
mvp_multivalue_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 156 | 6 | ▶ | sub mvp_aliases { return { 'module' => 'modules' } } | ||||||||||||||||||||
|
Subroutine
mvp_aliases: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 157 | |||||||||||||||||||||||
| 158 | 6 | ▶ | sub _build__copy_to_extras { | ||||||||||||||||||||
|
Subroutine
_build__copy_to_extras: called CC=3 SCAR=11.0
| |||||||||||||||||||||||
| 159 | 6 | my $self = shift; | |||||||||||||||||||||
| 160 | 6 | my $to = []; | |||||||||||||||||||||
| 161 | 6 | for my $copy ( @{ $self->copy_to } ) { | |||||||||||||||||||||
| 162 | 3 | ▶ | if ( my ( $copy_phase, $copy_rel ) = $copy =~ /\A([^.]+)[.](.+)\z/msx ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 163 | 2 | push @{$to}, { phase => $copy_phase, relation => $copy_rel }; | |||||||||||||||||||||
| 164 | 2 | next; | |||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||
| 166 | 1 | return $self->log_fatal( [ 'copy_to contained value not in form: phase.relation, got %s', $copy ] ); | |||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||
| 168 | 5 | return $to; | |||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||
| 170 | |||||||||||||||||||||||
| 171 | 1 | ▶ | sub _get_feature_modules { | ||||||||||||||||||||
|
Subroutine
_get_feature_modules: called CC=6 SCAR=18.0
| |||||||||||||||||||||||
| 172 | 1 | my ($self) = @_; | |||||||||||||||||||||
| 173 | 1 | my $hash = {}; | |||||||||||||||||||||
| 174 | 1 | my $meta = $self->zilla->distmeta; | |||||||||||||||||||||
| 175 | 1 | ▶ | if ( not exists $meta->{optional_features} ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 176 | 0 | $self->log('No optional_features detected'); | |||||||||||||||||||||
| 177 | 0 | return $hash; | |||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||
| 179 | 1 | for my $feature_name ( keys %{ $meta->{optional_features} } ) { | |||||||||||||||||||||
| 180 | 1 | my $feature = $meta->{optional_features}->{$feature_name}; | |||||||||||||||||||||
| 181 | 1 | for my $rel_name ( keys %{ $feature->{prereqs} } ) { | |||||||||||||||||||||
| 182 | 1 | my $rel = $feature->{prereqs}->{$rel_name}; | |||||||||||||||||||||
| 183 | 1 | for my $phase_name ( keys %{$rel} ) { | |||||||||||||||||||||
| 184 | 1 | my $phase = $rel->{$phase_name}; | |||||||||||||||||||||
| 185 | 1 | for my $module ( keys %{$phase} ) { | |||||||||||||||||||||
| 186 | 1 | $self->log_debug("Got module ${module} from ${feature}.${rel_name}.${phase}"); | |||||||||||||||||||||
| 187 | 1 | $hash->{$module} = 1; | |||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||
| 192 | 1 | return keys %{$hash}; | |||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||
| 194 | |||||||||||||||||||||||
| 195 | 6 | ▶ | sub _build__modules_hash { | ||||||||||||||||||||
|
Subroutine
_build__modules_hash: called CC=4 SCAR=13.9
| |||||||||||||||||||||||
| 196 | 6 | my ($self) = @_; | |||||||||||||||||||||
| 197 | 6 | my $hash = {}; | |||||||||||||||||||||
| 198 | 6 | $hash->{$_} = 1 for @{ $self->modules }; | |||||||||||||||||||||
| 199 | 6 | ▶ | return $hash unless $self->modules_from_features; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 200 | 1 | $hash->{$_} = 1 for $self->_get_feature_modules; | |||||||||||||||||||||
| 201 | 1 | return $hash; | |||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||
| 203 | |||||||||||||||||||||||
| 204 | 5 | ▶ | sub _user_wants_softening_on { | ||||||||||||||||||||
|
Subroutine
_user_wants_softening_on: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 205 | 5 | my ( $self, $module ) = @_; | |||||||||||||||||||||
| 206 | 5 | return exists $self->_modules_hash->{$module}; | |||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||
| 208 | |||||||||||||||||||||||
| 209 | 15 | ▶ | sub _soften_prereqs { | ||||||||||||||||||||
|
Subroutine
_soften_prereqs: called CC=10 SCAR=23.9
| |||||||||||||||||||||||
| 210 | 15 | my ( $self, $conf ) = @_; | |||||||||||||||||||||
| 211 | 15 | my $prereqs = $self->zilla->prereqs; | |||||||||||||||||||||
| 212 | |||||||||||||||||||||||
| 213 | 15 | my $source_reqs = $prereqs->requirements_for( $conf->{from_phase}, $conf->{from_relation} ); | |||||||||||||||||||||
| 214 | |||||||||||||||||||||||
| 215 | 15 | my @target_reqs; | |||||||||||||||||||||
| 216 | |||||||||||||||||||||||
| 217 | 15 | for my $target ( @{ $conf->{to} } ) { | |||||||||||||||||||||
| 218 | 21 | ▶ | next if 'none' eq $target->{relation}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 219 | push @target_reqs, | ||||||||||||||||||||||
| 220 | { | ||||||||||||||||||||||
| 221 | phase => $target->{phase}, | ||||||||||||||||||||||
| 222 | relation => $target->{relation}, | ||||||||||||||||||||||
| 223 | 18 | reqs => $prereqs->requirements_for( $target->{phase}, $target->{relation} ), | |||||||||||||||||||||
| 224 | }; | ||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||
| 226 | |||||||||||||||||||||||
| 227 | 15 | for my $module ( $source_reqs->required_modules ) { | |||||||||||||||||||||
| 228 | 5 | ▶ | next unless $self->_user_wants_softening_on($module); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 229 | 5 | $self->log_debug("$conf->{from_phase}.$conf->{from_relation} contains $module"); | |||||||||||||||||||||
| 230 | 5 | my $reqstring = $source_reqs->requirements_for_module($module); | |||||||||||||||||||||
| 231 | 5 | $self->log_debug( [ ' - %-20s %s = %s', "$conf->{from_phase}.$conf->{from_relation}", $module, $reqstring ] ); | |||||||||||||||||||||
| 232 | 5 | $source_reqs->clear_requirement($module); | |||||||||||||||||||||
| 233 | 5 | for my $target (@target_reqs) { | |||||||||||||||||||||
| 234 | 6 | my $old_string = $target->{reqs}->requirements_for_module($module); | |||||||||||||||||||||
| 235 | 6 | $target->{reqs}->add_string_requirement( $module, $reqstring ); | |||||||||||||||||||||
| 236 | 6 | my $new_string = $target->{reqs}->requirements_for_module($module); | |||||||||||||||||||||
| 237 | |||||||||||||||||||||||
| 238 | # Calcluating the nature of the change for log debugging | ||||||||||||||||||||||
| 239 | 6 | ▶ | my $change = | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 240 | ( defined $old_string ) | ||||||||||||||||||||||
| 241 | ? ( $old_string eq $new_string ) | ||||||||||||||||||||||
| 242 | ? ( $new_string eq $reqstring ) | ||||||||||||||||||||||
| 243 | ? " (was already \"$new_string\")" | ||||||||||||||||||||||
| 244 | : " (unchanged from \"$old_string\")" | ||||||||||||||||||||||
| 245 | : " (was \"$old_string\", now \"$new_string\")" | ||||||||||||||||||||||
| 246 | : ( defined $new_string ) ? ' (new requirement)' | ||||||||||||||||||||||
| 247 | : ' (Possible Error, undef after assignment)'; | ||||||||||||||||||||||
| 248 | |||||||||||||||||||||||
| 249 | 6 | $self->log_debug( [ ' + %-20s %s = %s%s', "$target->{phase}.$target->{relation}", $module, $reqstring, $change ] ); | |||||||||||||||||||||
| 250 | |||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||
| 253 | 15 | return $self; | |||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||
| 255 | |||||||||||||||||||||||
| 256 | 6 | ▶ | sub register_prereqs { | ||||||||||||||||||||
|
Subroutine
register_prereqs: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||
| 257 | 6 | my ($self) = @_; | |||||||||||||||||||||
| 258 | |||||||||||||||||||||||
| 259 | 6 | $self->log_debug( [ 'Softening modules: %s', join q[, ], sort keys %{ $self->_modules_hash } ] ); | |||||||||||||||||||||
| 260 | 6 | for my $phase (qw( build test runtime )) { | |||||||||||||||||||||
| 261 | 16 | for my $relation (qw( requires )) { | |||||||||||||||||||||
| 262 | $self->_soften_prereqs( | ||||||||||||||||||||||
| 263 | { | ||||||||||||||||||||||
| 264 | from_phase => $phase, | ||||||||||||||||||||||
| 265 | from_relation => $relation, | ||||||||||||||||||||||
| 266 | 16 | to => [ { phase => $phase, relation => $self->to_relationship }, @{ $self->_copy_to_extras }, ], | |||||||||||||||||||||
| 267 | }, | ||||||||||||||||||||||
| 268 | ); | ||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||
| 271 | 5 | return; | |||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||
| 273 | |||||||||||||||||||||||
| 274 | 7 | 1; | |||||||||||||||||||||
| 275 | |||||||||||||||||||||||
| 276 | __END__ | ||||||||||||||||||||||