| 1 | package Dist::Zilla::Plugin::Lump; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | our $DATE = '2016-02-14'; # DATE | |||||||||||||||||||||||||||
| 4 | 1 | our $VERSION = '0.10'; # VERSION | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | with ( | |||||||||||||||||||||||||||
| 12 | 'Dist::Zilla::Role::FileFinderUser' => | ||||||||||||||||||||||||||||
| 13 | {default_finders=>[':InstallModules']}, | ||||||||||||||||||||||||||||
| 14 | 'Dist::Zilla::Role::FileGatherer', | ||||||||||||||||||||||||||||
| 15 | 'Dist::Zilla::Role::FileMunger', | ||||||||||||||||||||||||||||
| 16 | 'Dist::Zilla::Role::MetaProvider', | ||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Data::Dmp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use App::lcpan::Call qw(call_lcpan_script); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use File::Slurper qw(read_binary); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Module::Path::More qw(module_path); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | #has lump_module => (is=>'rw'); | ||||||||||||||||||||||||||||
| 25 | 1 | has lump_dist => (is=>'rw'); | |||||||||||||||||||||||||||
| 26 | 1 | has lump_dist_and_deps => (is=>'rw'); | |||||||||||||||||||||||||||
| 27 | 1 | has include_author => (is=>'rw'); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub mvp_multivalue_args { qw(include_author lump_dist lump_dist_and_deps) } | ||||||||||||||||||||||||||
|
Subroutine
mvp_multivalue_args: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub gather_files { | ||||||||||||||||||||||||||
|
Subroutine
gather_files: not called CC=26 SCAR=64.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 34 | 1 | ▶ | use experimental 'smartmatch'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my @lump_mods; # to be added in our dist | |||||||||||||||||||||||||||
| 39 | my %dep_mods; # to stay as deps | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | ## lump_module | ||||||||||||||||||||||||||||
| 42 | #{ | ||||||||||||||||||||||||||||
| 43 | # last unless $self->lump_module; | ||||||||||||||||||||||||||||
| 44 | # for my $mod (@{ $self->lump_module }) { | ||||||||||||||||||||||||||||
| 45 | # push @lump_mods, $mod unless $mod ~~ @lump_mods; | ||||||||||||||||||||||||||||
| 46 | # } | ||||||||||||||||||||||||||||
| 47 | #} | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # lump_dist | ||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | last unless $self->lump_dist; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | my @mods = @{ $self->lump_dist }; | |||||||||||||||||||||||||||
| 53 | 0 | for (@mods) { | |||||||||||||||||||||||||||
| 54 | 0 | s/-/::/g; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 0 | my $res = call_lcpan_script( | |||||||||||||||||||||||||||
| 57 | argv=>["mods-from-same-dist", "--latest", @mods]); | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $self->log_fatal(["Can't lcpan mods-from-same-dist: %s - %s", $res->[0], $res->[1]]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | unless $res->[0] == 200; | ||||||||||||||||||||||||||||
| 60 | 0 | for my $mod (@{$res->[2]}) { | |||||||||||||||||||||||||||
| 61 | 0 | ▶ | push @lump_mods, $mod unless $mod ~~ @lump_mods; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # lump_dist_and_deps | ||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | last unless $self->lump_dist_and_deps; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | my @mods1 = @{ $self->lump_dist_and_deps }; | |||||||||||||||||||||||||||
| 69 | 0 | for (@mods1) { | |||||||||||||||||||||||||||
| 70 | 0 | s/-/::/g; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 0 | my $res = call_lcpan_script( | |||||||||||||||||||||||||||
| 73 | argv=>["mods-from-same-dist", "--latest", @mods1]); | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $self->log_fatal(["Can't lcpan mods-from-same-dist: %s - %s", $res->[0], $res->[1]]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | unless $res->[0] == 200; | ||||||||||||||||||||||||||||
| 76 | 0 | my @mods2 = @{$res->[2]}; | |||||||||||||||||||||||||||
| 77 | 0 | $res = call_lcpan_script(argv => ['deps', '-R', @$res]); | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | $self->log_fatal(["Can't lcpan deps: %s - %s", $res->[0], $res->[1]]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | unless $res->[0] == 200; | ||||||||||||||||||||||||||||
| 80 | 0 | my @mods3; | |||||||||||||||||||||||||||
| 81 | 0 | for my $rec (@{$res->[2]}) { | |||||||||||||||||||||||||||
| 82 | 0 | my $lump = 0; | |||||||||||||||||||||||||||
| 83 | 0 | my $mod = $rec->{module}; | |||||||||||||||||||||||||||
| 84 | 0 | $mod =~ s/\A\s+//; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # decide whether we should lump this module or not | ||||||||||||||||||||||||||||
| 87 | DECIDE: | ||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($self->include_author && @{ $self->include_author }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->include_author and @{$self->include_author;}
MC/DC0%0/2
$self->include_author and @{$self->include_author;}
$self->include_author
@{$self->include_author;}
Truth table0%0/3
A and B
A= $self->include_authorB= @{$self->include_author;}
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | last DECIDE unless $rec->{author} ~~ @{ $self->include_author }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 0 | $lump = 1; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | if ($lump) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | push @mods3, $mod; | |||||||||||||||||||||||||||
| 97 | } else { | ||||||||||||||||||||||||||||
| 98 | 0 | $dep_mods{$mod} = $rec->{version}; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 0 | $res = call_lcpan_script(argv => ['mods-from-same-dist', '--latest', @mods3]); | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | $self->log_fatal(["Can't lcpan mods-from-same-dist: %s - %s", $res->[0], $res->[1]]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | unless $res->[0] == 200; | ||||||||||||||||||||||||||||
| 104 | 0 | my @mods4 = @{$res->[2]}; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | for my $mod (@mods2, @mods4) { | |||||||||||||||||||||||||||
| 107 | 0 | ▶ | push @lump_mods, $mod unless $mod ~~ @lump_mods; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | 0 | @lump_mods = sort @lump_mods; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | my @lump_dists; | |||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||
| 114 | 0 | ▶ | last unless @lump_mods; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | my $res = call_lcpan_script(argv => ['mod2dist', @lump_mods]); | |||||||||||||||||||||||||||
| 116 | 0 | ▶ | $self->log_fatal(["Can't lcpan mod2dist: %s - %s", $res->[0], $res->[1]]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | unless $res->[0] == 200; | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if (@lump_mods == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | push @lump_dists, $res->[2]; | |||||||||||||||||||||||||||
| 120 | } else { | ||||||||||||||||||||||||||||
| 121 | 0 | for (values %$res) { | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | push @lump_dists, $_ unless $_ ~~ @lump_dists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | 0 | @lump_dists = sort @lump_dists; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | $self->log_debug(["modules to lump into dist: %s", \@lump_mods]); | |||||||||||||||||||||||||||
| 129 | 0 | $self->log_debug(["dists lumped into dist: %s", \@lump_dists]); | |||||||||||||||||||||||||||
| 130 | 0 | $self->log_debug(["modules to add as deps: %s", \%dep_mods]); | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | $self->{_lump_mods} = \@lump_mods; | |||||||||||||||||||||||||||
| 133 | 0 | $self->{_lump_dists} = \@lump_dists; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | my $meta_no_index = {}; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | for my $mod (@lump_mods) { | |||||||||||||||||||||||||||
| 138 | 0 | my $path = module_path(module => $mod); | |||||||||||||||||||||||||||
| 139 | 0 | ▶ | $self->log_fatal(["Can't find path for module %s, make sure the module is installed", $mod]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | unless $path; | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | my $mod_pm = $mod; | |||||||||||||||||||||||||||
| 143 | 0 | $mod_pm =~ s!::!/!g; | |||||||||||||||||||||||||||
| 144 | 0 | $mod_pm .= ".pm"; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | my $ct = read_binary($path); | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | MUNGE: | ||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||
| 150 | # adjust dist name | ||||||||||||||||||||||||||||
| 151 | 0 | $ct =~ s/^(=head1 VERSION\s+[^\n]+from Perl distribution )[\w-]+(?: version [^)\s]+)*/ | |||||||||||||||||||||||||||
| 152 | 0 | $1 . $self->zilla->name . " version " . $self->zilla->version/ems; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | my $file_path = "lib/$mod_pm"; | |||||||||||||||||||||||||||
| 156 | 0 | my $file = Dist::Zilla::File::InMemory->new( | |||||||||||||||||||||||||||
| 157 | name => $file_path, | ||||||||||||||||||||||||||||
| 158 | content => $ct, | ||||||||||||||||||||||||||||
| 159 | ); | ||||||||||||||||||||||||||||
| 160 | 0 | push @{ $meta_no_index->{file} }, $file_path; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | $self->add_file($file); | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | 0 | $self->{_meta_no_index} = $meta_no_index; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | for my $mod (keys %dep_mods) { | |||||||||||||||||||||||||||
| 167 | 0 | $self->zilla->register_prereqs($mod => $dep_mods{$mod}); | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub munge_files { | ||||||||||||||||||||||||||
|
Subroutine
munge_files: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 172 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | $self->munge_file($_) for @{ $self->found_files }; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub munge_file { | ||||||||||||||||||||||||||
|
Subroutine
munge_file: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 178 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | my $content = $file->content; | |||||||||||||||||||||||||||
| 181 | 0 | my $munged = 0; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $munged++ if $content =~ s/^(#\s*LUMPED_MODULES)$/"our \@LUMPED_MODULES = \@{" . dmp($self->{_lump_mods} ) . "}; $1"/em; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 0 | ▶ | $munged++ if $content =~ s/^(#\s*LUMPED_DISTS)$/ "our \@LUMPED_DISTS = \@{" . dmp($self->{_lump_dists}) . "}; $1"/em; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | $munged++ if $content =~ s/^(#\s*LUMPED_MODULES_POD)$/"=over\n\n" . join("", map { "=item * $_\n\n" } @{ $self->{_lump_mods} }) . "=back\n\n"/em; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | $munged++ if $content =~ s/^(#\s*LUMPED_DISTS_POD)$/ "=over\n\n" . join("", map { "=item * $_\n\n" } @{ $self->{_lump_dists} }) . "=back\n\n"/em; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | $file->content($content) if $munged; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | 0 | ▶ | sub metadata { | ||||||||||||||||||||||||||
|
Subroutine
metadata: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 191 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | { no_index => $self->{_meta_no_index} }; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 197 | 1 | 1; | |||||||||||||||||||||||||||
| 198 | # ABSTRACT: Lump other modules/dists together into dist | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | __END__ | ||||||||||||||||||||||||||||