line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#line 1 |
2
|
1
|
|
|
1
|
|
11
|
package Module::CPANfile; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
98
|
|
5
|
1
|
|
|
1
|
|
6
|
use Cwd; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
6
|
1
|
|
|
1
|
|
656
|
use Carp (); |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
18
|
|
7
|
1
|
|
|
1
|
|
5
|
use Module::CPANfile::Environment (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1627
|
|
8
|
|
|
|
|
|
|
use Module::CPANfile::Result; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.9034'; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
0
|
0
|
|
sub new { |
13
|
0
|
|
|
|
|
|
my($class, $file) = @_; |
14
|
|
|
|
|
|
|
bless {}, $class; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
0
|
1
|
|
sub load { |
18
|
0
|
0
|
|
|
|
|
my($proto, $file) = @_; |
19
|
0
|
|
0
|
|
|
|
my $self = ref $proto ? $proto : $proto->new; |
20
|
0
|
|
|
|
|
|
$self->{file} = $file || "cpanfile"; |
21
|
0
|
|
|
|
|
|
$self->parse; |
22
|
|
|
|
|
|
|
$self; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
0
|
1
|
|
sub save { |
26
|
|
|
|
|
|
|
my($self, $path) = @_; |
27
|
0
|
0
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
open my $out, ">", $path or die "$path: $!"; |
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
print {$out} $self->to_string; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
0
|
0
|
|
sub parse { |
33
|
|
|
|
|
|
|
my $self = shift; |
34
|
0
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
my $file = Cwd::abs_path($self->{file}); |
36
|
|
|
|
|
|
|
$self->{result} = Module::CPANfile::Environment::parse($file) or die $@; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
0
|
1
|
|
sub from_prereqs { |
40
|
|
|
|
|
|
|
my($proto, $prereqs) = @_; |
41
|
0
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $self = $proto->new; |
43
|
|
|
|
|
|
|
$self->{result} = Module::CPANfile::Result->from_prereqs($prereqs); |
44
|
0
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$self; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
0
|
1
|
|
sub features { |
49
|
0
|
|
|
|
|
|
my $self = shift; |
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
map $self->feature($_), keys %{$self->{result}{features}}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
0
|
0
|
|
sub feature { |
54
|
|
|
|
|
|
|
my($self, $identifier) = @_; |
55
|
0
|
0
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $data = $self->{result}{features}{$identifier} |
57
|
|
|
|
|
|
|
or Carp::croak("Unknown feature '$identifier'"); |
58
|
0
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
require CPAN::Meta::Feature; |
60
|
|
|
|
|
|
|
CPAN::Meta::Feature->new($data->{identifier}, { |
61
|
|
|
|
|
|
|
description => $data->{description}, |
62
|
|
|
|
|
|
|
prereqs => $data->{spec}, |
63
|
|
|
|
|
|
|
}); |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
0
|
1
|
|
|
66
|
|
|
|
|
|
|
sub prereqs { shift->prereq } |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
0
|
1
|
|
sub prereqs_with { |
69
|
|
|
|
|
|
|
my($self, @feature_identifiers) = @_; |
70
|
0
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $prereqs = $self->prereqs; |
|
0
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my @others = map { $self->feature($_)->prereqs } @feature_identifiers; |
73
|
0
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$prereqs->with_merged_prereqs(\@others); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
0
|
0
|
|
sub prereq { |
78
|
0
|
|
|
|
|
|
my $self = shift; |
79
|
0
|
|
|
|
|
|
require CPAN::Meta::Prereqs; |
80
|
|
|
|
|
|
|
CPAN::Meta::Prereqs->new($self->prereq_specs); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
0
|
1
|
|
sub prereq_specs { |
84
|
0
|
|
|
|
|
|
my $self = shift; |
85
|
|
|
|
|
|
|
$self->{result}{spec}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
0
|
1
|
|
sub merge_meta { |
89
|
|
|
|
|
|
|
my($self, $file, $version) = @_; |
90
|
0
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
require CPAN::Meta; |
92
|
0
|
0
|
0
|
|
|
|
|
93
|
|
|
|
|
|
|
$version ||= $file =~ /\.yml$/ ? '1.4' : '2'; |
94
|
0
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $prereq = $self->prereqs; |
96
|
0
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $meta = CPAN::Meta->load_file($file); |
98
|
0
|
|
|
|
|
|
my $prereqs_hash = $prereq->with_merged_prereqs($meta->effective_prereqs)->as_string_hash; |
|
0
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my $struct = { %{$meta->as_struct}, prereqs => $prereqs_hash }; |
100
|
0
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
CPAN::Meta->new($struct)->save($file, { version => $version }); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
0
|
|
|
sub _dump { |
105
|
0
|
|
|
|
|
|
my $str = shift; |
106
|
0
|
|
|
|
|
|
require Data::Dumper; |
107
|
0
|
|
|
|
|
|
chomp(my $value = Data::Dumper->new([$str])->Terse(1)->Dump); |
108
|
|
|
|
|
|
|
$value; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
0
|
1
|
|
sub to_string { |
112
|
|
|
|
|
|
|
my($self, $include_empty) = @_; |
113
|
0
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $prereqs = $self->{result}{spec}; |
115
|
0
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
my $code = ''; |
117
|
|
|
|
|
|
|
$code .= $self->_dump_prereqs($self->{result}{spec}, $include_empty); |
118
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
for my $feature (values %{$self->{result}{features}}) { |
120
|
0
|
|
|
|
|
|
$code .= sprintf "feature %s, %s => sub {\n", _dump($feature->{identifier}), _dump($feature->{description}); |
121
|
0
|
|
|
|
|
|
$code .= $self->_dump_prereqs($feature->{spec}, $include_empty, 4); |
122
|
|
|
|
|
|
|
$code .= "}\n\n"; |
123
|
|
|
|
|
|
|
} |
124
|
0
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
$code =~ s/\n+$/\n/s; |
126
|
|
|
|
|
|
|
$code; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
0
|
|
|
sub _dump_prereqs { |
130
|
|
|
|
|
|
|
my($self, $prereqs, $include_empty, $base_indent) = @_; |
131
|
0
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my $code = ''; |
133
|
0
|
0
|
|
|
|
|
for my $phase (qw(runtime configure build test develop)) { |
134
|
0
|
|
0
|
|
|
|
my $indent = $phase eq 'runtime' ? '' : ' '; |
135
|
|
|
|
|
|
|
$indent = (' ' x ($base_indent || 0)) . $indent; |
136
|
0
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
|
my($phase_code, $requirements); |
138
|
|
|
|
|
|
|
$phase_code .= "on $phase => sub {\n" unless $phase eq 'runtime'; |
139
|
0
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
for my $type (qw(requires recommends suggests conflicts)) { |
|
0
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
for my $mod (sort keys %{$prereqs->{$phase}{$type}}) { |
142
|
0
|
0
|
|
|
|
|
my $ver = $prereqs->{$phase}{$type}{$mod}; |
143
|
|
|
|
|
|
|
$phase_code .= $ver eq '0' |
144
|
|
|
|
|
|
|
? "${indent}$type '$mod';\n" |
145
|
0
|
|
|
|
|
|
: "${indent}$type '$mod', '$ver';\n"; |
146
|
|
|
|
|
|
|
$requirements++; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} |
149
|
0
|
0
|
|
|
|
|
|
150
|
0
|
0
|
|
|
|
|
$phase_code .= "\n" unless $requirements; |
151
|
|
|
|
|
|
|
$phase_code .= "};\n" unless $phase eq 'runtime'; |
152
|
0
|
0
|
0
|
|
|
|
|
153
|
|
|
|
|
|
|
$code .= $phase_code . "\n" if $requirements or $include_empty; |
154
|
|
|
|
|
|
|
} |
155
|
0
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
$code =~ s/\n+$/\n/s; |
157
|
|
|
|
|
|
|
$code; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
__END__ |