2 package Module::Install::ReadmeFromPod;
7 use base qw(Module::Install::Base);
14 # these aren't defined until after _require_admin is run, so
15 # define them so prototypes are available during compilation.
25 # do this once to avoid redefinition warnings from IO::All
29 IO::All->import( '-binary' );
31 require Capture::Tiny;
32 Capture::Tiny->import ( 'capture' );
41 return unless $self->is_admin;
46 my $in_file = shift || $self->_all_from
47 or die "Can't determine file to make readme_from";
49 # Get optional arguments
50 my ($clean, $format, $out_file, $options);
53 # Arguments are in a hashref
54 if ( ref($args) ne 'HASH' ) {
55 die "Expected a hashref but got a ".ref($args)."\n";
57 $clean = $args->{'clean'};
58 $format = $args->{'format'};
59 $out_file = $args->{'output_file'};
60 $options = $args->{'options'};
63 # Arguments are in a list
75 print "readme_from $in_file to $format\n";
76 if ($format =~ m/te?xt/) {
77 $out_file = $self->_readme_txt($in_file, $out_file, $options);
78 } elsif ($format =~ m/html?/) {
79 $out_file = $self->_readme_htm($in_file, $out_file, $options);
80 } elsif ($format eq 'man') {
81 $out_file = $self->_readme_man($in_file, $out_file, $options);
82 } elsif ($format eq 'md') {
83 $out_file = $self->_readme_md($in_file, $out_file, $options);
84 } elsif ($format eq 'pdf') {
85 $out_file = $self->_readme_pdf($in_file, $out_file, $options);
89 $self->clean_files($out_file);
97 my ($self, $in_file, $out_file, $options) = @_;
98 $out_file ||= 'README';
100 my $parser = Pod::Text->new( @$options );
101 my $io = io->file($out_file)->open(">");
102 my $out_fh = $io->io_handle;
103 $parser->output_fh( *$out_fh );
104 $parser->parse_file( $in_file );
110 my ($self, $in_file, $out_file, $options) = @_;
111 $out_file ||= 'README.htm';
120 io->file($out_file)->print($o);
121 # Remove temporary files if needed
122 for my $file ('pod2htmd.tmp', 'pod2htmi.tmp') {
124 unlink $file or warn "Warning: Could not remove file '$file'.\n$!\n";
132 my ($self, $in_file, $out_file, $options) = @_;
133 $out_file ||= 'README.1';
135 my $parser = Pod::Man->new( @$options );
136 my $io = io->file($out_file)->open(">");
137 my $out_fh = $io->io_handle;
138 $parser->output_fh( *$out_fh );
139 $parser->parse_file( $in_file );
145 my ($self, $in_file, $out_file, $options) = @_;
146 $out_file ||= 'README.pdf';
147 eval { require App::pod2pdf; }
148 or die "Could not generate $out_file because pod2pdf could not be found\n";
149 my $parser = App::pod2pdf->new( @$options );
150 $parser->parse_from_file($in_file);
151 my ($o) = capture { $parser->output };
152 io->file($out_file)->print($o);
157 my ($self, $in_file, $out_file, $options) = @_;
158 $out_file ||= 'README.md';
159 require Pod::Markdown;
160 my $parser = Pod::Markdown->new( @$options );
161 my $io = io->file($out_file)->open(">");
162 my $out_fh = $io->io_handle;
163 $parser->output_fh( *$out_fh );
164 $parser->parse_file( $in_file );
171 return unless $self->admin->{extensions};
172 my ($metadata) = grep {
173 ref($_) eq 'Module::Install::Metadata';
174 } @{$self->admin->{extensions}};
175 return unless $metadata;
176 return $metadata->{values}{all_from} || '';