| 1 | #!/usr/bin/perl | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | |||||||||||||||||||
| 6 | 3 | ▶ | use Pod::Manual; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | 3 | ▶ | use Getopt::Long; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 3 | ▶ | use Pod::Usage; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | 3 | my $VERSION = '0.08'; | |||||||||||||||||
| 11 | |||||||||||||||||||
| 12 | 3 | my $title; | |||||||||||||||||
| 13 | 3 | my $output_file = 'manual'; | |||||||||||||||||
| 14 | 3 | my $format = 'pdf'; | |||||||||||||||||
| 15 | 3 | my $silent = 0; | |||||||||||||||||
| 16 | 3 | my $opt_help = 0; | |||||||||||||||||
| 17 | 3 | my $opt_man = 0; | |||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | 3 | ▶ | GetOptions( | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 20 | 'title=s' => \$title, | ||||||||||||||||||
| 21 | 'output=s' => \$output_file, | ||||||||||||||||||
| 22 | 'format=s' => \$format, | ||||||||||||||||||
| 23 | 'silent!' => \$silent, | ||||||||||||||||||
| 24 | 'man' => \$opt_man, | ||||||||||||||||||
| 25 | 'help' => \$opt_help, | ||||||||||||||||||
| 26 | ) or pod2usage(1); | ||||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | 3 | ▶ | pod2usage(1) if $opt_help; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 29 | 3 | ▶ | pod2usage( -verbose => 2 ) if $opt_man; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 30 | |||||||||||||||||||
| 31 | 3 | my $manual = Pod::Manual->new( { title => $title } ); | |||||||||||||||||
| 32 | |||||||||||||||||||
| 33 | # the chapters are either passed as arguments, | ||||||||||||||||||
| 34 | # or taken from STDIN | ||||||||||||||||||
| 35 | 3 | ▶ | $manual->add_chapters( @ARGV ? @ARGV : split /\r?\n/, join q{}, <> ); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 36 | |||||||||||||||||||
| 37 | 3 | ▶ | if ( $format eq 'pdf' ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 38 | 0 | $output_file =~ s/(\.pdf)?$/.pdf/; # add .pdf, if missing | |||||||||||||||||
| 39 | 0 | $manual->save_as_pdf($output_file); | |||||||||||||||||
| 40 | } | ||||||||||||||||||
| 41 | elsif ( $format eq 'docbook' ) { | ||||||||||||||||||
| 42 | 3 | my $output_fh; | |||||||||||||||||
| 43 | 3 | ▶ | if ( $output_file eq 'stdout' ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 44 | 3 | ▶ | open $output_fh, '>-' | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 45 | or die "can't pipe to stdout: $!\n"; | ||||||||||||||||||
| 46 | } | ||||||||||||||||||
| 47 | else { | ||||||||||||||||||
| 48 | 0 | ▶ | $output_file .= '.docbook' unless $output_file =~ /\.\w+$/; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 49 | 0 | ▶ | die "$output_file already exists\n" if -e $output_file; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 50 | 0 | ▶ | open $output_fh, '>', $output_file | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 51 | or die "can't write to $output_file: $!\n"; | ||||||||||||||||||
| 52 | } | ||||||||||||||||||
| 53 | 3 | print {$output_fh} $manual->as_docbook; | |||||||||||||||||
| 54 | } | ||||||||||||||||||
| 55 | elsif ( lc($format) eq 'latex' ) { | ||||||||||||||||||
| 56 | 0 | my $output_fh; | |||||||||||||||||
| 57 | 0 | ▶ | if ( $output_file eq 'stdout' ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 58 | 0 | ▶ | open $output_fh, '>-' | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 59 | or die "can't pipe to stdout: $!\n"; | ||||||||||||||||||
| 60 | } | ||||||||||||||||||
| 61 | else { | ||||||||||||||||||
| 62 | 0 | ▶ | $output_file .= '.tex' unless $output_file =~ /\.\w+$/; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 63 | 0 | ▶ | die "$output_file already exists\n" if -e $output_file; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 64 | 0 | ▶ | open $output_fh, '>', $output_file | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 65 | or die "can't write to $output_file: $!\n"; | ||||||||||||||||||
| 66 | } | ||||||||||||||||||
| 67 | 0 | print {$output_fh} $manual->as_latex; | |||||||||||||||||
| 68 | } | ||||||||||||||||||
| 69 | else { | ||||||||||||||||||
| 70 | 0 | die "format must be 'pdf', 'docbook' or 'LaTeX'\n"; | |||||||||||||||||
| 71 | } | ||||||||||||||||||
| 72 | |||||||||||||||||||
| 73 | 3 | ▶ | warn "document '$output_file' created\n" unless $silent; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | 3 | exit; | |||||||||||||||||
| 76 | |||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||