File Coverage

blib/lib/Dist/Zilla/Plugin/Author/Plicease/Core.pm
Criterion Covered Total %
statement 14 39 35.9
branch 0 10 0.0
condition n/a
subroutine 5 7 71.4
pod 0 2 0.0
total 19 58 32.7


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::Author::Plicease::Core 2.73 {
2              
3 1     1   823 use 5.020;
  1         4  
4 1     1   7 use Moose;
  1         2  
  1         8  
5 1     1   10907 use Module::CoreList ();
  1         111285  
  1         486  
6 1     1   17 use version ();
  1         2  
  1         279  
7 1     1   8 use experimental qw( postderef );
  1         3  
  1         17  
8              
9             # ABSTRACT: Handle core prereqs
10             # VERSION
11              
12             with 'Dist::Zilla::Role::PrereqSource', 'Dist::Zilla::Role::InstallTool';
13              
14             has starting_version => (
15             is => 'ro',
16             lazy => 1,
17             default => sub {
18             my($self) = @_;
19             my $version = $self->zilla->prereqs->as_string_hash->{runtime}->{requires}->{perl};
20             $self->log("guessing perl version $version");
21             $version;
22             },
23             );
24              
25             has check_at_configure => (
26             is => 'ro',
27             default => sub { { } },
28             );
29              
30             sub register_prereqs
31             {
32 0     0 0   my($self) = @_;
33              
34 0           my $prereqs = $self->zilla->prereqs->as_string_hash;
35              
36 0           foreach my $phase (keys %$prereqs)
37             {
38 0 0         next if $phase eq 'develop';
39 0           foreach my $type (keys $prereqs->{$phase}->%*)
40             {
41 0           foreach my $module (sort keys %{ $prereqs->{$phase}->{$type} })
  0            
42             {
43 0 0         next if $module =~ /^(ExtUtils::MakeMaker|Module::Build)$/;
44 0           my $value = $prereqs->{$phase}->{$type}->{$module};
45 0 0         next unless $value == 0;
46 0           my $added_in = Module::CoreList->first_release($module);
47 0 0         next unless defined $added_in;
48             #$self->log("considering $phase $type $module");
49             #$self->log("addedin = $added_in");
50             #$self->log("starting_version = @{[ version->parse($self->starting_version) ]}");
51             #$self->log("added_in = @{[ version->parse($added_in) ]}");
52 0 0         if(version->parse($self->starting_version) >= version->parse($added_in))
53             {
54 0           $self->log("removing prereq: $module");
55 0           $self->zilla->prereqs->requirements_for($phase, $type)->clear_requirement($module);
56 0           $self->check_at_configure->{$module}++;
57             }
58             }
59             }
60             }
61             }
62              
63             sub setup_installer
64             {
65 0     0 0   my($self) = @_;
66 0           foreach my $file (grep { $_->name =~ /^(Makefile\.PL|Build\.PL)$/ } $self->zilla->files->@*)
  0            
67             {
68 0           my $content = $file->content;
69              
70             $content = join "\n",
71             "BEGIN {",
72             " use strict; use warnings;",
73             " my \%missing = map {",
74             " eval qq{ require \$_ };",
75             " \$\@ ? (\$_=>1) : ()",
76 0           " } qw( @{[ sort keys %{ $self->check_at_configure } ]} );",
  0            
77             " if(%missing)",
78             " {",
79             " print \"Your Perl is missing core modules: \@{[ sort keys \%missing ]}\\n\";",
80 0           (map { " print \"$_\\n\";" }
  0            
81             "Ideally if you are using the system Perl you can install the appropriate",
82             "package which includes the core Perl modules. On at least some versions",
83             "of Fedora, CentOS and RHEL, this is the `perl-core` package.",
84             "",
85             " \% dnf install perl-core",
86             " ~ or ~",
87             " \% yum install perl-core",
88             "",
89             "If you really want to install dual-life modules from CPAN, then you can",
90             "use cpanm:",
91             "",
92             " \% cpanm \@{[ sort keys \%missing ]}",
93             "",
94             "Note that some core modules are not available from CPAN.",
95             ),
96             " exit;",
97             " }",
98             "}",
99             $content;
100              
101 0           $file->content($content);
102             }
103              
104             }
105              
106              
107             }
108              
109             1;
110              
111             __END__
112              
113             =pod
114              
115             =encoding UTF-8
116              
117             =head1 NAME
118              
119             Dist::Zilla::Plugin::Author::Plicease::Core - Handle core prereqs
120              
121             =head1 VERSION
122              
123             version 2.73
124              
125             =head1 AUTHOR
126              
127             Graham Ollis <plicease@cpan.org>
128              
129             =head1 COPYRIGHT AND LICENSE
130              
131             This software is copyright (c) 2012-2022 by Graham Ollis.
132              
133             This is free software; you can redistribute it and/or modify it under
134             the same terms as the Perl 5 programming language system itself.
135              
136             =cut