| 1 |
package inc::OSPrereqs; |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use namespace::autoclean; |
| 6 |
|
| 7 |
use MetaCPAN::Client; |
| 8 |
|
| 9 |
use Moose; |
| 10 |
|
| 11 |
extends 'Dist::Zilla::Plugin::OSPrereqs'; |
| 12 |
|
| 13 |
# This fixes https://github.com/dagolden/Dist-Zilla-Plugin-OSPrereqs/issues/16 |
| 14 |
## no critic (ValuesAndExpressions::ProhibitInterpolationOfLiterals ) |
| 15 |
sub BUILDARGS { |
| 16 |
my ( $class, @arg ) = @_; |
| 17 |
my %copy = ref $arg[0] ? %{ $arg[0] } : @arg; |
| 18 |
|
| 19 |
my $zilla = delete $copy{zilla}; |
| 20 |
my $name = delete $copy{plugin_name}; |
| 21 |
my $os = delete $copy{prereq_os}; |
| 22 |
|
| 23 |
my @dashed = grep {/^-/} keys %copy; |
| 24 |
|
| 25 |
my %other; |
| 26 |
for my $dkey (@dashed) { |
| 27 |
( my $key = $dkey ) =~ s/^-//; |
| 28 |
|
| 29 |
$other{$key} = delete $copy{$dkey}; |
| 30 |
} |
| 31 |
|
| 32 |
Carp::confess "don't try to pass -_prereq as a build arg!" |
| 33 |
if $other{_prereq}; |
| 34 |
|
| 35 |
return { |
| 36 |
zilla => $zilla, |
| 37 |
plugin_name => $name, |
| 38 |
( defined $os ? ( prereq_os => $os ) : () ), |
| 39 |
_prereq => \%copy, |
| 40 |
%other, |
| 41 |
}; |
| 42 |
} |
| 43 |
|
| 44 |
my $FallbackVersion = '1.94'; |
| 45 |
my $Version; |
| 46 |
|
| 47 |
## no critic (Subroutines::ProhibitUnusedPrivateSubroutines ) |
| 48 |
sub _prereq { |
| 49 |
my $self = shift; |
| 50 |
|
| 51 |
return if $ENV{CI}; |
| 52 |
|
| 53 |
return { 'DateTime::TimeZone::Local::Win32' => $Version } |
| 54 |
if $Version; |
| 55 |
|
| 56 |
my $release |
| 57 |
= MetaCPAN::Client->new->release('DateTime-TimeZone-Local-Win32'); |
| 58 |
if ($release) { |
| 59 |
$Version = $release->version; |
| 60 |
} |
| 61 |
else { |
| 62 |
$Version = $FallbackVersion; |
| 63 |
$self->log_warning( |
| 64 |
"Could not find DateTime-TimeZone-Local-Win32 on MetaCPAN. Falling back to hard-coded version $FallbackVersion" |
| 65 |
); |
| 66 |
} |
| 67 |
|
| 68 |
return { 'DateTime::TimeZone::Local::Win32' => $Version }; |
| 69 |
} |
| 70 |
|
| 71 |
__PACKAGE__->meta->make_immutable; |
| 72 |
|
| 73 |
1; |