CPAN/Maker/Bootstrapper/Role/ReconcileDeps.pm untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 91 CC 6 SCAR 22.3
CC
6
Cov
0%
cmd_reconcile_deps
20.0
_write_requires
12.0
BEGIN
2.0
CRAP 9.3
1 package CPAN::Maker::Bootstrapper::Role::ReconcileDeps;
2  
3 use strict;
4 use warnings;
5  
6 use CLI::Simple::Constants qw(:booleans);
7 use CLI::Simple::Utils qw(slurp);
8  
9 use English qw(-no_match_vars);
10 use Role::Tiny;
11  
12 use Role::Tiny::With;
13 with 'CPAN::Maker::Bootstrapper::Role::DepsFilter';
14  
15 ########################################################################
16 sub cmd_reconcile_deps {
17 ########################################################################
18 my ($self) = @_;
19  
20 my @types = $self->get_args;
21  
22 die "ERROR: usage: reconcile-deps dependency-type [...]\n"
23 if !@types;
24  
25 my @mirrors = ('https://cpan.metacpan.org');
26  
27 if ( -e 'build-mirrors' ) {
28  
29 foreach my $mirror ( split /\n/xsm, slurp('build-mirrors') ) {
30 next if !$mirror || $mirror =~ /^[#]/xsm;
31 push @mirrors, $mirror;
32 }
33  
34 }
35  
36 my $index = $self->fetch_index( \@mirrors );
37  
38 foreach my $type (@types) {
39 my $requires = $self->_filter_requires( "$type.raw", "$type.skip", $type, );
40  
41 my %package_lines;
42  
43 foreach my $module ( keys %{$requires} ) {
44 my $lookup = $module;
45 $lookup =~ s/^[+]//xsm;
46  
47 $package_lines{$lookup} = sprintf '%s %s', $module, $requires->{$module};
48 }
49  
50 my $filtered = $self->_filter_package_hash( $index, \%package_lines, );
51  
52 $self->_write_requires( $type, $filtered );
53 }
54  
55 return $SUCCESS;
56 }
57  
58 ########################################################################
59 sub _write_requires {
60 ########################################################################
61 my ( $self, $filename, $requires ) = @_;
62  
63 my $output = q{};
64  
65 if ( %{$requires} ) {
66 $output = join( "\n", sort values %{$requires} ) . "\n";
67 }
68  
69 if ( !-e $filename || slurp($filename) ne $output ) {
70 open my $fh, '>', $filename
71 or die "ERROR: could not write $filename: $OS_ERROR\n";
72  
73 print {$fh} $output;
74  
75 close $fh
76 or die "ERROR: could not close $filename: $OS_ERROR\n";
77 }
78  
79 return;
80 }
81  
82 1;