line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Module::Install::ReadmeFromPod; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
13564
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
15
|
|
5
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
25
|
|
6
|
1
|
|
|
1
|
|
3
|
use base qw(Module::Install::Base); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
393
|
|
7
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
800
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$VERSION = '0.30'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
{ |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# these aren't defined until after _require_admin is run, so |
14
|
|
|
|
|
|
|
# define them so prototypes are available during compilation. |
15
|
|
|
|
|
|
|
sub io; |
16
|
|
|
|
|
|
|
sub capture(&;@); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=pod |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=begin quiet_pod_coverage |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head2 io |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head2 capture |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=end quiet_pod_coverage |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=cut |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $done = 0; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _require_admin { |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# do this once to avoid redefinition warnings from IO::All |
35
|
0
|
0
|
|
0
|
|
|
return if $done; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
require IO::All; |
38
|
0
|
|
|
|
|
|
IO::All->import( '-binary' ); |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
require Capture::Tiny; |
41
|
0
|
|
|
|
|
|
Capture::Tiny->import ( 'capture' ); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub readme_from { |
49
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
50
|
0
|
0
|
|
|
|
|
return unless $self->is_admin; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
_require_admin; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Input file |
55
|
0
|
0
|
0
|
|
|
|
my $in_file = shift || $self->_all_from |
56
|
|
|
|
|
|
|
or die "Can't determine file to make readme_from"; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Get optional arguments |
59
|
0
|
|
|
|
|
|
my ($clean, $format, $out_file, $options); |
60
|
0
|
|
|
|
|
|
my $args = shift; |
61
|
0
|
0
|
|
|
|
|
if ( ref $args ) { |
62
|
|
|
|
|
|
|
# Arguments are in a hashref |
63
|
0
|
0
|
|
|
|
|
if ( ref($args) ne 'HASH' ) { |
64
|
0
|
|
|
|
|
|
die "Expected a hashref but got a ".ref($args)."\n"; |
65
|
|
|
|
|
|
|
} else { |
66
|
0
|
|
|
|
|
|
$clean = $args->{'clean'}; |
67
|
0
|
|
|
|
|
|
$format = $args->{'format'}; |
68
|
0
|
|
|
|
|
|
$out_file = $args->{'output_file'}; |
69
|
0
|
|
|
|
|
|
$options = $args->{'options'}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} else { |
72
|
|
|
|
|
|
|
# Arguments are in a list |
73
|
0
|
|
|
|
|
|
$clean = $args; |
74
|
0
|
|
|
|
|
|
$format = shift; |
75
|
0
|
|
|
|
|
|
$out_file = shift; |
76
|
0
|
|
|
|
|
|
$options = \@_; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Default values; |
80
|
0
|
|
0
|
|
|
|
$clean ||= 0; |
81
|
0
|
|
0
|
|
|
|
$format ||= 'txt'; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Generate README |
84
|
0
|
|
|
|
|
|
print "readme_from $in_file to $format\n"; |
85
|
0
|
0
|
|
|
|
|
if ($format =~ m/te?xt/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$out_file = $self->_readme_txt($in_file, $out_file, $options); |
87
|
|
|
|
|
|
|
} elsif ($format =~ m/html?/) { |
88
|
0
|
|
|
|
|
|
$out_file = $self->_readme_htm($in_file, $out_file, $options); |
89
|
|
|
|
|
|
|
} elsif ($format eq 'man') { |
90
|
0
|
|
|
|
|
|
$out_file = $self->_readme_man($in_file, $out_file, $options); |
91
|
|
|
|
|
|
|
} elsif ($format eq 'md') { |
92
|
0
|
|
|
|
|
|
$out_file = $self->_readme_md($in_file, $out_file, $options); |
93
|
|
|
|
|
|
|
} elsif ($format eq 'pdf') { |
94
|
0
|
|
|
|
|
|
$out_file = $self->_readme_pdf($in_file, $out_file, $options); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
if ($clean) { |
98
|
0
|
|
|
|
|
|
$self->clean_files($out_file); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return 1; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _readme_txt { |
106
|
0
|
|
|
0
|
|
|
my ($self, $in_file, $out_file, $options) = @_; |
107
|
0
|
|
0
|
|
|
|
$out_file ||= 'README'; |
108
|
0
|
|
|
|
|
|
require Pod::Text; |
109
|
0
|
|
|
|
|
|
my $parser = Pod::Text->new( @$options ); |
110
|
0
|
|
|
|
|
|
my $io = io->file($out_file)->open(">"); |
111
|
0
|
|
|
|
|
|
my $out_fh = $io->io_handle; |
112
|
0
|
|
|
|
|
|
$parser->output_fh( *$out_fh ); |
113
|
0
|
|
|
|
|
|
$parser->parse_file( $in_file ); |
114
|
0
|
|
|
|
|
|
return $out_file; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub _readme_htm { |
119
|
0
|
|
|
0
|
|
|
my ($self, $in_file, $out_file, $options) = @_; |
120
|
0
|
|
0
|
|
|
|
$out_file ||= 'README.htm'; |
121
|
0
|
|
|
|
|
|
require Pod::Html; |
122
|
|
|
|
|
|
|
my ($o) = capture { |
123
|
0
|
|
|
0
|
|
|
Pod::Html::pod2html( |
124
|
|
|
|
|
|
|
"--infile=$in_file", |
125
|
|
|
|
|
|
|
"--outfile=-", |
126
|
|
|
|
|
|
|
@$options, |
127
|
|
|
|
|
|
|
); |
128
|
0
|
|
|
|
|
|
}; |
129
|
0
|
|
|
|
|
|
io->file($out_file)->print($o); |
130
|
|
|
|
|
|
|
# Remove temporary files if needed |
131
|
0
|
|
|
|
|
|
for my $file ('pod2htmd.tmp', 'pod2htmi.tmp') { |
132
|
0
|
0
|
|
|
|
|
if (-e $file) { |
133
|
0
|
0
|
|
|
|
|
unlink $file or warn "Warning: Could not remove file '$file'.\n$!\n"; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
0
|
|
|
|
|
|
return $out_file; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub _readme_man { |
141
|
0
|
|
|
0
|
|
|
my ($self, $in_file, $out_file, $options) = @_; |
142
|
0
|
|
0
|
|
|
|
$out_file ||= 'README.1'; |
143
|
0
|
|
|
|
|
|
require Pod::Man; |
144
|
0
|
|
|
|
|
|
my $parser = Pod::Man->new( @$options ); |
145
|
0
|
|
|
|
|
|
my $io = io->file($out_file)->open(">"); |
146
|
0
|
|
|
|
|
|
my $out_fh = $io->io_handle; |
147
|
0
|
|
|
|
|
|
$parser->output_fh( *$out_fh ); |
148
|
0
|
|
|
|
|
|
$parser->parse_file( $in_file ); |
149
|
0
|
|
|
|
|
|
return $out_file; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub _readme_pdf { |
154
|
0
|
|
|
0
|
|
|
my ($self, $in_file, $out_file, $options) = @_; |
155
|
0
|
|
0
|
|
|
|
$out_file ||= 'README.pdf'; |
156
|
0
|
0
|
|
|
|
|
eval { require App::pod2pdf; } |
|
0
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
or die "Could not generate $out_file because pod2pdf could not be found\n"; |
158
|
0
|
|
|
|
|
|
my $parser = App::pod2pdf->new( @$options ); |
159
|
0
|
|
|
|
|
|
$parser->parse_from_file($in_file); |
160
|
0
|
|
|
0
|
|
|
my ($o) = capture { $parser->output }; |
|
0
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
io->file($out_file)->print($o); |
162
|
0
|
|
|
|
|
|
return $out_file; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub _readme_md { |
166
|
0
|
|
|
0
|
|
|
my ($self, $in_file, $out_file, $options) = @_; |
167
|
0
|
|
0
|
|
|
|
$out_file ||= 'README.md'; |
168
|
0
|
|
|
|
|
|
require Pod::Markdown; |
169
|
0
|
|
|
|
|
|
my $parser = Pod::Markdown->new( @$options ); |
170
|
0
|
|
|
|
|
|
my $io = io->file($out_file)->open(">"); |
171
|
0
|
|
|
|
|
|
my $out_fh = $io->io_handle; |
172
|
0
|
|
|
|
|
|
$parser->output_fh( *$out_fh ); |
173
|
0
|
|
|
|
|
|
$parser->parse_file( $in_file ); |
174
|
0
|
|
|
|
|
|
return $out_file; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub _all_from { |
179
|
0
|
|
|
0
|
|
|
my $self = shift; |
180
|
0
|
0
|
|
|
|
|
return unless $self->admin->{extensions}; |
181
|
|
|
|
|
|
|
my ($metadata) = grep { |
182
|
0
|
|
|
|
|
|
ref($_) eq 'Module::Install::Metadata'; |
183
|
0
|
|
|
|
|
|
} @{$self->admin->{extensions}}; |
|
0
|
|
|
|
|
|
|
184
|
0
|
0
|
|
|
|
|
return unless $metadata; |
185
|
0
|
|
0
|
|
|
|
return $metadata->{values}{all_from} || ''; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
'Readme!'; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
__END__ |