| 1 | package Dist::Zilla::Role::ModuleIncluder; | ||||||||||||||||||||||||||||
| 2 | 4 | $Dist::Zilla::Role::ModuleIncluder::VERSION = '0.008'; | |||||||||||||||||||||||||||
| 3 | # vim: ts=4 sts=0 sw=0 noet | ||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use MooseX::Types::Moose qw/Bool/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use Dist::Zilla::File::InMemory 5.000; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use File::Slurper 'read_binary'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 4 | ▶ | use Scalar::Util qw/reftype/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use List::Util 1.45 'uniq'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Module::CoreList 5.20160520; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Module::Metadata; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Perl::PrereqScanner; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 4 | with 'Dist::Zilla::Role::FileInjector'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 6 | ▶ | sub _mod_to_filename { | ||||||||||||||||||||||||||
|
Subroutine
_mod_to_filename: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 6 | my $module = shift; | |||||||||||||||||||||||||||
| 21 | 6 | return File::Spec->catfile('inc', split / :: | ' /x, $module) . '.pm'; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 4 | my $version = \%Module::CoreList::version; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | ## no critic (Variables::ProhibitPackageVars) | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 4 | has include_dependencies => ( | |||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||
| 30 | isa => Bool, | ||||||||||||||||||||||||||||
| 31 | default => 1, | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | # cache of Module::Metadata objects | ||||||||||||||||||||||||||||
| 36 | 4 | my %module_files; | |||||||||||||||||||||||||||
| 37 | 21 | ▶ | sub _find_module_by_name { | ||||||||||||||||||||||||||
|
Subroutine
_find_module_by_name: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 38 | 21 | my $module = shift; | |||||||||||||||||||||||||||
| 39 | 21 | ▶ | return $module_files{$module} if exists $module_files{$module}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 17 | ▶ | $module_files{$module} = Module::Metadata->find_module_by_name($module) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | or confess "Can't locate $module"; | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 4 | around dump_config => sub | |||||||||||||||||||||||||||
| 46 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 47 | 2 | my ($orig, $self) = @_; | |||||||||||||||||||||||||||
| 48 | 2 | my $config = $self->$orig; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | ▶ | my $data = { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
__PACKAGE__->VERSION || '<self>'
MC/DC0%0/1
__PACKAGE__->VERSION || '<self>'
__PACKAGE__->VERSION
Truth table50%1/2
A
A= __PACKAGE__->VERSION
| |||||||||||||||||||||||||||||
| 51 | version => __PACKAGE__->VERSION || '<self>', | ||||||||||||||||||||||||||||
| 52 | include_dependencies => ($self->include_dependencies ? 1 : 0), | ||||||||||||||||||||||||||||
| 53 | 'Module::CoreList' => Module::CoreList->VERSION, | ||||||||||||||||||||||||||||
| 54 | }; | ||||||||||||||||||||||||||||
| 55 | 2 | $config->{+__PACKAGE__} = $data; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | return $config; | |||||||||||||||||||||||||||
| 58 | 4 | }; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 15 | ▶ | sub _get_reqs { | ||||||||||||||||||||||||||
|
Subroutine
_get_reqs: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 61 | 15 | my ($self, $reqs, $scanner, $module, $background, $blacklist) = @_; | |||||||||||||||||||||||||||
| 62 | 15 | my $module_file = _find_module_by_name($module); | |||||||||||||||||||||||||||
| 63 | 15 | my %new_reqs = %{ $scanner->scan_file($module_file)->as_string_hash }; | |||||||||||||||||||||||||||
| 64 | 15 | $self->log_debug([ 'found dependency of %s: %s %s', $module, $_, $new_reqs{$_} ]) foreach keys %new_reqs; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | my @real_reqs = grep { | ||||||||||||||||||||||||||||
| 67 | 15 | ▶ | !$blacklist->{$_} && !Module::CoreList::is_core($_, $new_reqs{$_} ? $new_reqs{$_} : undef, $background) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$blacklist->{$_} || Module::CoreList::is_core($_, $new_reqs{$_} ? $new_reqs{$_} : undef, $background)
MC/DC100%2/2
$blacklist->{$_} || Module::CoreList::is_core($_, $new_reqs{$_} ? $new_reqs{$_} : undef, $background)
$blacklist->{$_}
Module::CoreList::is_core($_, $new_reqs{$_} ? $new_reqs{$_} : undef, $background)
Truth table100%3/3
A || B
A= $blacklist->{$_}B= Module::CoreList::is_core($_, $new_reqs{$_} ? $new_reqs{$_} : undef, $background)
| |||||||||||||||||||||||||||||
| 68 | } keys %new_reqs; | ||||||||||||||||||||||||||||
| 69 | 15 | for my $req (@real_reqs) { | |||||||||||||||||||||||||||
| 70 | 64 | ▶ | if (defined $reqs->{$module}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 52 | ▶ | next if $reqs->{$module} >= $new_reqs{$req}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 6 | $reqs->{$req} = $new_reqs{$req}; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | else { | ||||||||||||||||||||||||||||
| 75 | 12 | $reqs->{$req} = $new_reqs{$req}; | |||||||||||||||||||||||||||
| 76 | 12 | $self->_get_reqs($reqs, $scanner, $req, $background, $blacklist); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | 18 | $self->log_debug([ 'adding to requirements list: %s %s', $req, $new_reqs{$req} ]); | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 15 | return; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 3 | ▶ | sub _version_normalize { | ||||||||||||||||||||||||||
|
Subroutine
_version_normalize: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 84 | 3 | my $version = shift; | |||||||||||||||||||||||||||
| 85 | 3 | ▶ | return $version >= 5.010 ? sprintf "%1.6f", $version->numify : $version->numify; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 4 | ▶ | sub include_modules { | ||||||||||||||||||||||||||
|
Subroutine
include_modules: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 4 | my ($self, $modules, $background, $options) = @_; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | my %modules = reftype($modules) eq 'HASH' ? %{$modules} : map { $_ => 0 } @{$modules}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 4 | my %reqs; | |||||||||||||||||||||||||||
| 92 | 4 | my $scanner = Perl::PrereqScanner->new; | |||||||||||||||||||||||||||
| 93 | 4 | ▶ | my %blacklist = map { ( $_ => 1 ) } 'perl', @{ $options->{blacklist} || [] }; | ||||||||||||||||||||||||||
|
Condition50%1/2
$options->{'blacklist'} || []
MC/DC0%0/1
$options->{'blacklist'} || []
$options->{'blacklist'}
Truth table50%1/2
A
A= $options->{'blacklist'}
| |||||||||||||||||||||||||||||
| 94 | 4 | ▶ | if ($self->include_dependencies) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 3 | $self->_get_reqs(\%reqs, $scanner, $_, _version_normalize($background), \%blacklist) for keys %modules; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 4 | my @modules = grep { !$modules{$_} } keys %modules; | |||||||||||||||||||||||||||
| 98 | 4 | my %location_for = map { _mod_to_filename($_) => _find_module_by_name($_) } uniq(@modules, keys %reqs); | |||||||||||||||||||||||||||
| 99 | return map { | ||||||||||||||||||||||||||||
| 100 | 3 | my $filename = $_; | |||||||||||||||||||||||||||
| 101 | 3 | $self->log_debug([ 'copying for inclusion: %s', $location_for{$filename} ]); | |||||||||||||||||||||||||||
| 102 | 3 | my $file = Dist::Zilla::File::InMemory->new({name => $filename, encoded_content => read_binary($location_for{$filename})}); | |||||||||||||||||||||||||||
| 103 | 3 | $self->add_file($file); | |||||||||||||||||||||||||||
| 104 | 3 | $file; | |||||||||||||||||||||||||||
| 105 | } keys %location_for; | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 4 | 1; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | #ABSTRACT: Include modules and their dependencies in inc/ | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | __END__ | ||||||||||||||||||||||||||||