« lib/Perl/PrereqScanner/NotQuiteLite/Parser/Moose.pm
↑ Summary
lib/Perl/PrereqScanner/NotQuiteLite/Parser/ObjectPad.pm »
| 1 | package Perl::PrereqScanner::NotQuiteLite::Util::CPANfile; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use parent 'Module::CPANfile'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Perl::PrereqScanner::NotQuiteLite::Util::Prereqs; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | sub load_and_merge { | ||||||||||||||||||||||||||||
| 9 | 22 | ▶ | my ($class, $file, $prereqs, $features) = @_; | ||||||||||||||||||||||||||
|
Subroutine
load_and_merge: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 22 | ▶ | $prereqs = $prereqs->as_string_hash unless ref $prereqs eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 22 | my $self; | |||||||||||||||||||||||||||
| 14 | 22 | ▶ | if (-f $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | 6 | $self = $class->load($file); | |||||||||||||||||||||||||||
| 16 | 6 | $self->_merge_prereqs($prereqs); | |||||||||||||||||||||||||||
| 17 | } else { | ||||||||||||||||||||||||||||
| 18 | 16 | $self = $class->from_prereqs($prereqs); | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 22 | ▶ | if ($features) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 9 | for my $identifier (keys %$features) { | |||||||||||||||||||||||||||
| 23 | 9 | my $feature = $features->{$identifier}; | |||||||||||||||||||||||||||
| 24 | 9 | ▶ | next unless $feature->{prereqs}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 8 | ▶ | $self->_merge_prereqs($feature->{prereqs}, $identifier) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 7 | $self->{_prereqs}->add_feature($identifier, $feature->{description}); | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 22 | $self->_dedupe; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 22 | $self; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub features { | ||||||||||||||||||||||||||||
| 36 | 22 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
features: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 22 | map $self->feature($_), sort $self->{_prereqs}->identifiers; # TWEAKED | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub _merge_prereqs { | ||||||||||||||||||||||||||||
| 41 | 14 | ▶ | my ($self, $prereqs, $feature_id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_merge_prereqs: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 42 | 14 | ▶ | $prereqs = $prereqs->as_string_hash unless ref $prereqs eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 14 | my $current = CPAN::Meta::Prereqs->new($self->{_prereqs}->specs($feature_id)); | |||||||||||||||||||||||||||
| 45 | 14 | my $merged = $current->with_merged_prereqs(CPAN::Meta::Prereqs->new($prereqs)); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 14 | $self->__replace_prereqs($merged, $feature_id); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | sub __replace_prereqs { | ||||||||||||||||||||||||||||
| 51 | 44 | ▶ | my ($self, $prereqs, $feature_id) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__replace_prereqs: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 52 | 44 | ▶ | $prereqs = $prereqs->as_string_hash unless ref $prereqs eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 44 | ▶ | @{$self->{_prereqs}{prereqs}{$feature_id || ''}} = (); | ||||||||||||||||||||||||||
|
Condition100%2/2
$feature_id || ''
MC/DC100%1/1
$feature_id || ''
$feature_id
Truth table100%2/2
A
A= $feature_id
| |||||||||||||||||||||||||||||
| 55 | 44 | my $added = 0; | |||||||||||||||||||||||||||
| 56 | 44 | for my $phase (keys %$prereqs) { | |||||||||||||||||||||||||||
| 57 | 41 | for my $type (keys %{$prereqs->{$phase}}) { | |||||||||||||||||||||||||||
| 58 | 41 | ▶ | while (my($module, $requirement) = each %{$prereqs->{$phase}{$type}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | $self->{_prereqs}->add( | ||||||||||||||||||||||||||||
| 60 | 97 | feature => $feature_id, | |||||||||||||||||||||||||||
| 61 | phase => $phase, | ||||||||||||||||||||||||||||
| 62 | type => $type, | ||||||||||||||||||||||||||||
| 63 | module => $module, | ||||||||||||||||||||||||||||
| 64 | requirement => Module::CPANfile::Requirement->new(name => $module, version => $requirement), | ||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||
| 66 | 97 | $added++ | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | 44 | ▶ | delete $self->{_prereqs}{cpanmeta} unless $feature_id; # to rebuild cpanmeta | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 44 | $added; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub _dedupe { | ||||||||||||||||||||||||||||
| 75 | 22 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_dedupe: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 76 | 22 | my $prereqs = $self->prereqs; | |||||||||||||||||||||||||||
| 77 | 22 | my %features = map {$_ => $self->feature($_)->{prereqs} } $self->{_prereqs}->identifiers; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 22 | dedupe_prereqs_and_features($prereqs, \%features); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 22 | $self->__replace_prereqs($prereqs); | |||||||||||||||||||||||||||
| 82 | 22 | for my $feature_id (keys %features) { | |||||||||||||||||||||||||||
| 83 | 8 | $self->__replace_prereqs($features{$feature_id}, $feature_id); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | sub _dump_prereqs { | ||||||||||||||||||||||||||||
| 88 | 30 | ▶ | my($self, $prereqs, $include_empty, $base_indent) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_dump_prereqs: called CC=12 SCAR=24.9
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 30 | my $code = ''; | |||||||||||||||||||||||||||
| 91 | 30 | my @x_phases = sort grep {/^x_/i} keys %$prereqs; # TWEAKED | |||||||||||||||||||||||||||
| 92 | 30 | for my $phase (qw(runtime configure build test develop), @x_phases) { | |||||||||||||||||||||||||||
| 93 | 151 | ▶ | my $indent = $phase eq 'runtime' ? '' : ' '; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 151 | ▶ | $indent = (' ' x ($base_indent || 0)) . $indent; | ||||||||||||||||||||||||||
|
Condition100%2/2
$base_indent || 0
MC/DC100%1/1
$base_indent || 0
$base_indent
Truth table100%2/2
A
A= $base_indent
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 151 | my($phase_code, $requirements); | |||||||||||||||||||||||||||
| 97 | 151 | ▶ | $phase_code .= "on $phase => sub {\n" unless $phase eq 'runtime'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 151 | my @x_types = sort grep {/^x_/i} keys %{$prereqs->{$phase}}; # TWEAKED | |||||||||||||||||||||||||||
| 100 | 151 | for my $type (qw(requires recommends suggests conflicts), @x_types) { | |||||||||||||||||||||||||||
| 101 | 604 | for my $mod (sort keys %{$prereqs->{$phase}{$type}}) { | |||||||||||||||||||||||||||
| 102 | 75 | my $ver = $prereqs->{$phase}{$type}{$mod}; | |||||||||||||||||||||||||||
| 103 | 75 | ▶ | $phase_code .= $ver eq '0' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | ? "${indent}$type '$mod';\n" | ||||||||||||||||||||||||||||
| 105 | : "${indent}$type '$mod', '$ver';\n"; | ||||||||||||||||||||||||||||
| 106 | 75 | $requirements++; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 151 | ▶ | $phase_code .= "\n" unless $requirements; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 151 | ▶ | $phase_code .= "};\n" unless $phase eq 'runtime'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 151 | ▶ | $code .= $phase_code . "\n" if $requirements or $include_empty; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$requirements or $include_empty
MC/DC50%1/2
$requirements or $include_empty
$requirements
$include_empty
Truth table66%2/3
A or B
A= $requirementsB= $include_empty
| |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 30 | $code =~ s/\n+$/\n/s; | |||||||||||||||||||||||||||
| 117 | 30 | $code; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 10 | 1; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | __END__ | ||||||||||||||||||||||||||||