Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 113 lines (82 sloc) 2.9 KB
#! /usr/bin/perl
use strict;
use warnings;
use File::Basename;
use File::Path;
use FindBin qw/$Bin/;
use Getopt::Long;
use lib "$Bin/lib";
use Perldoc::Config;
#--Set config options-----------------------------------------------------
my %specifiers = (
'output-path' => '=s',
'perl' => '=s',
my %options;
GetOptions( \%options, optionspec(%specifiers) );
#--Check mandatory options have been given--------------------------------
my @mandatory_options = qw/ output-path /;
foreach (@mandatory_options) {
(my $option = $_) =~ tr/-/_/;
unless ($options{$option}) {
die "Option '$_' must be specified!\n";
#--Check the output path exists-------------------------------------------
unless (-d $options{output_path}) {
die "Output path '$options{output_path}' does not exist!\n";
$Perldoc::Config::option{output_path} = $options{output_path};
#--Check if we are using a different perl----------------------------------
if ($options{perl}) {
#warn "Setting perl to $options{perl}\n";
my $version_cmd = 'printf("%vd",$^V)';
my $perl_version = `$options{perl} -e '$version_cmd'`;
my $inc_cmd = 'print "$_\n" foreach @INC';
my $perl_inc = `$options{perl} -e '$inc_cmd'`;
my $bin_cmd = 'use Config; print $Config{bin}';
my $perl_bin = `$options{perl} -e '$bin_cmd'`;
$Perldoc::Config::option{perl_version} = $perl_version;
$Perldoc::Config::option{perl5_version} = substr($perl_version,2);
$Perldoc::Config::option{inc} = [split /\n/,$perl_inc];
$Perldoc::Config::option{bin} = $perl_bin;
#warn Dumper(\%Perldoc::Config::option);
eval <<EOT;
use Perldoc::Page;
use Perldoc::Page::Convert;
use Perldoc::Section;
die $@ if $@;
#--Convert pages to PDF---------------------------------------------------
my @pages = grep {exists $Perldoc::Page::CoreList{$_}} Perldoc::Page::list();
foreach my $section (Perldoc::Section::list()) {
push @pages,Perldoc::Section::pages($section);
my %pages = map {$_,1} @pages;
@pages = keys %pages;
foreach my $page (@pages) {
(my $filename = "$Perldoc::Config::option{output_path}/$page.pdf") =~ s!::!/!g;
#print "$page\n";
warn("Converting $page to PDF as $filename\n");
open OUTPUT,'>',$filename or die("Cannot open file '$filename': $!\n");
print OUTPUT Perldoc::Page::Convert::pdf($page);
close OUTPUT;
sub check_filepath {
my $filename = shift;
my $directory = dirname($filename);
mkpath $directory unless (-d $directory);
sub optionspec {
my %option_specs = @_;
my @getopt_list;
while (my ($option_name,$spec) = each %option_specs) {
(my $variable_name = $option_name) =~ tr/-/_/;
(my $nospace_name = $option_name) =~ s/-//g;
my $getopt_name = ($variable_name ne $option_name) ? "$variable_name|$option_name|$nospace_name" : $option_name;
push @getopt_list,"$getopt_name$spec";
return @getopt_list;
Jump to Line
Something went wrong with that request. Please try again.