| 1 | #!/usr/local/bin/perl | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # This file is part of Pod-Markdown | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2011 by Randy Stauner. | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | # PODNAME: pod2markdown | ||||||||||||||||||||||||||||
| 14 | # ABSTRACT: Convert POD text to Markdown | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use Pod::Markdown; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 11 | ▶ | use Pod::Usage; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 11 | my %opts = ( | |||||||||||||||||||||||||||
| 21 | # Since we're writing to a file the module needs to know that it has to do | ||||||||||||||||||||||||||||
| 22 | # some kind of encoding. Default to UTF-8. | ||||||||||||||||||||||||||||
| 23 | output_encoding => 'UTF-8', | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 11 | ▶ | GetOptions(\%opts, qw( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | help|h | ||||||||||||||||||||||||||||
| 28 | html_encode_chars|html-encode-chars=s | ||||||||||||||||||||||||||||
| 29 | local_module_url_prefix|local-module-url-prefix=s | ||||||||||||||||||||||||||||
| 30 | match_encoding|match-encoding|m | ||||||||||||||||||||||||||||
| 31 | man_url_prefix|man-url-prefix=s | ||||||||||||||||||||||||||||
| 32 | perldoc_url_prefix|perldoc-url-prefix=s | ||||||||||||||||||||||||||||
| 33 | output_encoding|output-encoding|e=s | ||||||||||||||||||||||||||||
| 34 | utf8|utf-8|u | ||||||||||||||||||||||||||||
| 35 | )) or pod2usage(2); | ||||||||||||||||||||||||||||
| 36 | 11 | ▶ | pod2usage(1) if $opts{help}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # TODO: Test PERL_UNICODE and/or layers on the handle? | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # Expand alias (-u is an alias for -e UTF-8). | ||||||||||||||||||||||||||||
| 41 | 11 | ▶ | $opts{output_encoding} = 'UTF-8' if delete $opts{utf8}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # TODO: Pod::Simple::parse_from_file(@ARGV[0,1]); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 11 | my $in_fh = get_handle(shift(@ARGV), '<', \*STDIN); | |||||||||||||||||||||||||||
| 46 | 11 | my $out_fh = get_handle(shift(@ARGV), '>', \*STDOUT); | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | # Undo any PERL_UNICODE effects. | ||||||||||||||||||||||||||||
| 49 | # Pod::Simple expects to receive bytes, and we're going to return bytes. | ||||||||||||||||||||||||||||
| 50 | 11 | binmode($_, ':bytes') for ($in_fh, $out_fh); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 11 | convert($in_fh, $out_fh); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 11 | ▶ | sub convert { | ||||||||||||||||||||||||||
|
Subroutine
convert: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 11 | my ($in_file, $out_file) = @_; | |||||||||||||||||||||||||||
| 56 | 11 | my $parser = Pod::Markdown->new(%opts); | |||||||||||||||||||||||||||
| 57 | 11 | $parser->output_fh($out_file); | |||||||||||||||||||||||||||
| 58 | 11 | $parser->parse_file($in_file); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 22 | ▶ | sub get_handle { | ||||||||||||||||||||||||||
|
Subroutine
get_handle: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 62 | 22 | my ($path, $op, $default) = @_; | |||||||||||||||||||||||||||
| 63 | 22 | ▶ | (!defined($path) || $path eq '-') ? $default : do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $path or $path eq "-"
MC/DC100%2/2
not defined $path or $path eq "-"
not defined $path
$path eq "-"
Truth table100%3/3
not(A) or B
A= not defined $pathB= $path eq "-"
| |||||||||||||||||||||||||||||
| 64 | 16 | ▶ | open(my $fh, $op, $path) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | or die "Failed to open '$path': $!\n"; | ||||||||||||||||||||||||||||
| 66 | 16 | $fh; | |||||||||||||||||||||||||||
| 67 | }; | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||||||||||