| 1 | package P5U::Command::Deps; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 1 | ▶ | use utf8; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 1 | ▶ | use P5U-command; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 1 | ▶ | BEGIN { | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | 1 | $P5U::Command::Deps::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||
| 10 | 1 | $P5U::Command::Deps::VERSION = '0.005'; | |||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||
| 12 | |||||||||||||||||||||||
| 13 | 1 | ▶ | use constant abstract => q <scan Perl source code for dependencies>; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 14 | 1 | ▶ | use constant command_names => qw <deps dependencies scandeps>; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 15 | 1 | ▶ | use constant usage_desc => q <%c deps %o FILE(s)?>; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | sub opt_spec | ||||||||||||||||||||||
| 18 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
opt_spec: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 19 | return ( | ||||||||||||||||||||||
| 20 | 0 | [ 'format|f=s' => 'output format (text, mi, pretdsl)' ], | |||||||||||||||||||||
| 21 | [ 'skip-core|skipcore|c' => 'skip core modules' ], | ||||||||||||||||||||||
| 22 | [ 'keep-provided|k' => "don't skip provided modules" ], | ||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | sub execute | ||||||||||||||||||||||
| 27 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
execute: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||
| 28 | 0 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||
| 29 | |||||||||||||||||||||||
| 30 | my @files = map { | ||||||||||||||||||||||
| 31 | 0 | ▶ | -d $_ | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 32 | ? $self->_mk_rule->all($_) | ||||||||||||||||||||||
| 33 | : "Path::Tiny"->new($_) | ||||||||||||||||||||||
| 34 | } @$args; | ||||||||||||||||||||||
| 35 | 0 | ▶ | @files = $self->_mk_rule->all unless @$args; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 36 | |||||||||||||||||||||||
| 37 | 0 | my $deps = $self->_get_deps(@files); | |||||||||||||||||||||
| 38 | 0 | ▶ | $self->_whittle_provides($deps, \@files) unless $opt->keep_provided; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 39 | 0 | ▶ | $self->_whittle_corelist($deps) if $opt->skip_core; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 40 | 0 | print $self->_output($deps, $opt->{format}); | |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | sub _mk_rule | ||||||||||||||||||||||
| 44 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
_mk_rule: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 45 | 0 | require Path::Iterator::Rule; | |||||||||||||||||||||
| 46 | 0 | "Path::Iterator::Rule"->new->skip_vcs->nonempty->perl_file; | |||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | sub _get_deps | ||||||||||||||||||||||
| 50 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
_get_deps: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||
| 51 | 0 | my ($self, @files) = @_; | |||||||||||||||||||||
| 52 | |||||||||||||||||||||||
| 53 | 0 | require CPAN::Meta::Requirements; | |||||||||||||||||||||
| 54 | |||||||||||||||||||||||
| 55 | my ($BUILD, $TEST, $XTEST, $RUNTIME) = map { | ||||||||||||||||||||||
| 56 | 0 | "CPAN::Meta::Requirements"->new; | |||||||||||||||||||||
| 57 | } 1..4; | ||||||||||||||||||||||
| 58 | |||||||||||||||||||||||
| 59 | 0 | require Perl::PrereqScanner; | |||||||||||||||||||||
| 60 | 0 | my $scan = "Perl::PrereqScanner"->new; | |||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | 0 | for (@files) | |||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||
| 64 | 0 | ▶ | my $R | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 65 | = m{\.PL$} ? $BUILD | ||||||||||||||||||||||
| 66 | : m{(^|[/\\])xt[/\\]} ? $XTEST | ||||||||||||||||||||||
| 67 | : m{(^|[/\\])t[/\\]} ? $TEST | ||||||||||||||||||||||
| 68 | : m{\.t$} ? $TEST | ||||||||||||||||||||||
| 69 | : $RUNTIME; | ||||||||||||||||||||||
| 70 | 0 | $R->add_requirements( $scan->scan_file("$_") ); | |||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | +{ | ||||||||||||||||||||||
| 74 | 0 | BUILD => $BUILD, | |||||||||||||||||||||
| 75 | TEST => $TEST, | ||||||||||||||||||||||
| 76 | XTEST => $XTEST, | ||||||||||||||||||||||
| 77 | RUNTIME => $RUNTIME, | ||||||||||||||||||||||
| 78 | }; | ||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||
| 80 | |||||||||||||||||||||||
| 81 | sub _whittle_corelist | ||||||||||||||||||||||
| 82 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
_whittle_corelist: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||
| 83 | 0 | my ($self, $deps, $perlver) = @_; | |||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | 0 | require Module::CoreList; | |||||||||||||||||||||
| 86 | |||||||||||||||||||||||
| 87 | 0 | ▶ | $perlver //= 0 + $deps->{RUNTIME}->as_string_hash->{perl}; | ||||||||||||||||||||
|
Condition0%0/3
$perlver //= 0 + $deps->{"RUNTIME"}->as_string_hash->{"perl"}
MC/DC0%0/2
$perlver //= 0 + $deps->{"RUNTIME"}->as_string_hash->{"perl"}
$perlver
0 + $deps->{"RUNTIME"}->as_string_hash->{"perl"}
Truth table0%0/3
A //= B
A= $perlverB= 0 + $deps->{"RUNTIME"}->as_string_hash->{"perl"}
| |||||||||||||||||||||||
| 88 | $self->usage_error("no Perl version listed, so cannot --skip-core") | ||||||||||||||||||||||
| 89 | 0 | ▶ | unless $Module::CoreList::version{$perlver}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 90 | 0 | my $core = bless $Module::CoreList::version{$perlver}, 'Module::CoreList'; | |||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | 0 | for my $d (values %$deps) | |||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||
| 94 | 0 | for my $module ($d->required_modules) | |||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||
| 96 | # whittle magic Module::Install stuff | ||||||||||||||||||||||
| 97 | 0 | ▶ | if ($module =~ /^inc::Module::/) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||
| 99 | 0 | $d->clear_requirement($module); | |||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||
| 101 | |||||||||||||||||||||||
| 102 | # skip modules never in core, or ever removed from core | ||||||||||||||||||||||
| 103 | 0 | ▶ | next unless $core->first_release($module); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 104 | 0 | ▶ | next if $core->removed_from($module); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | # whittle modules if the core version meets requirement | ||||||||||||||||||||||
| 107 | 0 | ▶ | if ($d->accepts_module($module, $core->{$module})) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||
| 109 | 0 | $d->clear_requirement($module); | |||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | sub _whittle_provides | ||||||||||||||||||||||
| 116 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
_whittle_provides: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||
| 117 | 0 | my ($self, $deps, $files) = @_; | |||||||||||||||||||||
| 118 | |||||||||||||||||||||||
| 119 | 0 | require Class::Discover; | |||||||||||||||||||||
| 120 | 0 | require List::MoreUtils; | |||||||||||||||||||||
| 121 | |||||||||||||||||||||||
| 122 | 0 | my @keywords = qw( package ); | |||||||||||||||||||||
| 123 | |||||||||||||||||||||||
| 124 | 0 | for my $d (values %$deps) | |||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||
| 126 | 0 | my $hashref = $d->as_string_hash; | |||||||||||||||||||||
| 127 | push @keywords => qw( class role ) | ||||||||||||||||||||||
| 128 | 0 | ▶ | if exists $hashref->{"MooseX::Declare"}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 129 | push @keywords => qw( class role exception ) | ||||||||||||||||||||||
| 130 | 0 | ▶ | if exists $hashref->{"MooseX::DeclareX"}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 131 | push @keywords => qw( class role application controller controller_role view model ) | ||||||||||||||||||||||
| 132 | 0 | ▶ | if exists $hashref->{"CatalystX::Declare"}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||
| 134 | |||||||||||||||||||||||
| 135 | 0 | my $packages = "Class::Discover"->discover_classes({ | |||||||||||||||||||||
| 136 | files => $files, | ||||||||||||||||||||||
| 137 | keywords => [ List::MoreUtils::uniq(@keywords) ], | ||||||||||||||||||||||
| 138 | }); | ||||||||||||||||||||||
| 139 | |||||||||||||||||||||||
| 140 | my $modules = [ | ||||||||||||||||||||||
| 141 | 0 | map { s{/}{::}g; $_ } | |||||||||||||||||||||
| 142 | 0 | ▶ | map { m{^lib/(.+)\.pm$} ? $1 : () } | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 143 | @$files | ||||||||||||||||||||||
| 144 | ]; | ||||||||||||||||||||||
| 145 | |||||||||||||||||||||||
| 146 | 0 | for my $d (values %$deps) | |||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||
| 148 | 0 | $d->clear_requirement($_) for map { keys %$_ } @$packages; | |||||||||||||||||||||
| 149 | 0 | $d->clear_requirement($_) for @$modules; | |||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||
| 152 | |||||||||||||||||||||||
| 153 | sub _output | ||||||||||||||||||||||
| 154 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
_output: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||
| 155 | 0 | my ($self, $deps, $format) = @_; | |||||||||||||||||||||
| 156 | 0 | ▶ | $format =~ /pret/i and return $self->_output_pretdsl($deps); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 157 | 0 | ▶ | $format =~ /mi/i and return $self->_output_mi($deps); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 158 | |||||||||||||||||||||||
| 159 | 0 | for my $key (sort keys %$deps) | |||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||
| 161 | 0 | ▶ | next unless $deps->{$key}->required_modules; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 162 | 0 | print "# $key\n"; | |||||||||||||||||||||
| 163 | 0 | for my $mod (sort $deps->{$key}->required_modules) | |||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||
| 165 | 0 | printf "%s %s\n", $mod, $deps->{$key}->requirements_for_module($mod); | |||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||
| 169 | |||||||||||||||||||||||
| 170 | 1 | my %term = ( | |||||||||||||||||||||
| 171 | TEST => 'test_requires', | ||||||||||||||||||||||
| 172 | BUILD => 'configure_requires', | ||||||||||||||||||||||
| 173 | RUNTIME => 'requires', | ||||||||||||||||||||||
| 174 | ); | ||||||||||||||||||||||
| 175 | |||||||||||||||||||||||
| 176 | sub _output_pretdsl | ||||||||||||||||||||||
| 177 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
_output_pretdsl: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||
| 178 | 0 | my ($self, $deps) = @_; | |||||||||||||||||||||
| 179 | |||||||||||||||||||||||
| 180 | 0 | print "[\n"; | |||||||||||||||||||||
| 181 | 0 | for my $key (sort keys %$deps) | |||||||||||||||||||||
| 182 | { | ||||||||||||||||||||||
| 183 | 0 | ▶ | next unless exists $term{$key}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 184 | 0 | for my $mod (sort $deps->{$key}->required_modules) | |||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||
| 186 | 0 | ▶ | next if $mod eq 'perl'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 187 | printf | ||||||||||||||||||||||
| 188 | "\t%s p`%s %s`;\n", | ||||||||||||||||||||||
| 189 | $term{$key}, | ||||||||||||||||||||||
| 190 | $mod, | ||||||||||||||||||||||
| 191 | 0 | $deps->{$key}->requirements_for_module($mod), | |||||||||||||||||||||
| 192 | ; | ||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||
| 195 | 0 | print "].\n"; | |||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||
| 197 | |||||||||||||||||||||||
| 198 | sub _output_mi | ||||||||||||||||||||||
| 199 | 0 | ▶ | { | ||||||||||||||||||||
|
Subroutine
_output_mi: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||
| 200 | 0 | my ($self, $deps) = @_; | |||||||||||||||||||||
| 201 | |||||||||||||||||||||||
| 202 | 0 | for my $key (sort keys %$deps) | |||||||||||||||||||||
| 203 | { | ||||||||||||||||||||||
| 204 | 0 | ▶ | next unless exists $term{$key}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 205 | 0 | for my $mod (sort $deps->{$key}->required_modules) | |||||||||||||||||||||
| 206 | { | ||||||||||||||||||||||
| 207 | 0 | ▶ | next if $mod eq 'perl'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 208 | printf | ||||||||||||||||||||||
| 209 | "%s \"%s\" => %s;\n", | ||||||||||||||||||||||
| 210 | $term{$key}, | ||||||||||||||||||||||
| 211 | $mod, | ||||||||||||||||||||||
| 212 | 0 | $deps->{$key}->requirements_for_module($mod), | |||||||||||||||||||||
| 213 | ; | ||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||
| 217 | |||||||||||||||||||||||
| 218 | 1 | 1; | |||||||||||||||||||||
| 219 | |||||||||||||||||||||||
| 220 | __END__ | ||||||||||||||||||||||