line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::CPANfile2OPML; |
2
|
2
|
|
|
2
|
|
29267
|
use 5.008001; |
|
2
|
|
|
|
|
8
|
|
3
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
46
|
|
4
|
2
|
|
|
2
|
|
20
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
98
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
2185
|
use Module::CPANfile; |
|
2
|
|
|
|
|
48614
|
|
|
2
|
|
|
|
|
76
|
|
7
|
2
|
|
|
2
|
|
8776
|
use XML::Simple; |
|
2
|
|
|
|
|
26016
|
|
|
2
|
|
|
|
|
19
|
|
8
|
2
|
|
|
2
|
|
5274
|
use Path::Class; |
|
2
|
|
|
|
|
152677
|
|
|
2
|
|
|
|
|
124
|
|
9
|
2
|
|
|
2
|
|
260354
|
use File::Path::Expand; |
|
2
|
|
|
|
|
362827
|
|
|
2
|
|
|
|
|
137
|
|
10
|
2
|
|
|
2
|
|
18
|
use Cwd; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
164
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
13
|
use constant ALL_PHASES => [qw(configure build test runtime develop)]; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1592
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
1
|
|
|
1
|
0
|
15
|
my ($class) = @_; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
5
|
bless {}, $class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub convert_file { |
23
|
2
|
|
|
2
|
0
|
5149
|
my ($self, $file, $target_phases) = @_; |
24
|
|
|
|
|
|
|
|
25
|
2
|
100
|
66
|
|
|
15
|
unless ($target_phases && @$target_phases) { |
26
|
1
|
|
|
|
|
3
|
$target_phases = ALL_PHASES; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
7
|
my $title = $self->_title($file, $target_phases); |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
|
|
22
|
my $cpanfile = Module::CPANfile->load($file); |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
182
|
my @folders; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
10
|
for my $phase_name (@$target_phases) { |
36
|
6
|
|
|
|
|
24
|
my $folder = $self->_phase_to_folder($cpanfile, $phase_name); |
37
|
6
|
100
|
|
|
|
27
|
next unless $folder; |
38
|
3
|
|
|
|
|
10
|
push @folders, $folder; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
17
|
my $opml = { |
42
|
|
|
|
|
|
|
opml => { |
43
|
|
|
|
|
|
|
version => '2.0', |
44
|
|
|
|
|
|
|
head => { |
45
|
|
|
|
|
|
|
title => [$title], |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
body => { |
48
|
|
|
|
|
|
|
outline => \@folders, |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
15
|
my $header = XMLout($opml, RootName => '', XmlDecl => ''); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _title { |
57
|
2
|
|
|
2
|
|
4
|
my ($self, $file, $target_phases) = @_; |
58
|
|
|
|
|
|
|
|
59
|
2
|
|
|
|
|
107
|
my $application = Path::Class::file(Cwd::realpath($file))->parent->basename; |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
439
|
my $phases = join ', ', @$target_phases; |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
|
|
|
8
|
"$application/cpanfile($phases)"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _phase_to_folder { |
67
|
6
|
|
|
6
|
|
19
|
my ($self, $cpanfile, $phase_name) = @_; |
68
|
|
|
|
|
|
|
|
69
|
6
|
|
|
|
|
21
|
my @packages = $self->_collect_packages($cpanfile, $phase_name); |
70
|
6
|
100
|
|
|
|
31
|
return unless @packages; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my @outlines = map { |
73
|
3
|
|
|
|
|
8
|
$self->_package_name_to_outline($_); |
|
7
|
|
|
|
|
24
|
|
74
|
|
|
|
|
|
|
} @packages; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
return { |
77
|
3
|
|
|
|
|
20
|
title => $phase_name, |
78
|
|
|
|
|
|
|
outline => \@outlines, |
79
|
|
|
|
|
|
|
}; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _collect_packages { |
83
|
6
|
|
|
6
|
|
12
|
my ($self, $cpanfile, $phase) = @_; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# TODO: Better access to retrieve CPAN::Meta::Requirements |
86
|
6
|
|
|
|
|
31
|
my $requirements = $cpanfile->prereqs->{prereqs}->{$phase}; |
87
|
6
|
100
|
|
|
|
1945
|
return unless $requirements; |
88
|
|
|
|
|
|
|
|
89
|
3
|
|
|
|
|
16
|
my @package_names = $requirements->{requires}->required_modules; |
90
|
|
|
|
|
|
|
|
91
|
3
|
|
|
|
|
73
|
return @package_names; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub _package_name_to_outline { |
95
|
7
|
|
|
7
|
|
16
|
my ($self, $package_name) = @_; |
96
|
|
|
|
|
|
|
|
97
|
7
|
|
|
|
|
24
|
my $distribution_name = $package_name; |
98
|
7
|
|
|
|
|
39
|
$distribution_name =~ s/(::)/-/g; |
99
|
|
|
|
|
|
|
return { |
100
|
7
|
|
|
|
|
60
|
title => $package_name, |
101
|
|
|
|
|
|
|
htmlUrl => "https://metacpan.org/pod/$package_name", |
102
|
|
|
|
|
|
|
xmlUrl => "https://metacpan.org/feed/distribution/$distribution_name", |
103
|
|
|
|
|
|
|
}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
__END__ |