script/pod2markdown

filter: Statementstmt 100% 33 / 33 Branchbran 60.0% 6 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 92.8% 52 / 56 CC 4 SCAR 7.4
CC
4
Cov
91%
get_handle
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.1
« lib/Pod/Markdown.pm ↑ Summary lib/Pod/Perldoc/ToMarkdown.pm »
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
BranchTrueFalseTotal
&GetOptions(\%opts, ("help|h", "html_encode_chars|html-encode-chars=s", "local_module_url_prefix|local-module-url-prefix=s", "match_encoding|match-encoding|m", "man_url_prefix|man-url-prefix=s", "perldoc_url_prefix|perldoc-url-prefix=s", "output_encoding|output-encoding|e=s", "utf8|utf-8|u")) or pod2usage(2) 11 0 11
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
BranchTrueFalseTotal
if $opts{"help"} 0 11 11
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
BranchTrueFalseTotal
if delete $opts{"utf8"} 0 11 11
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
BranchTrueFalseTotal
!defined($path) || $path eq '-' ? : 6 16 22
Condition100%3/3
not defined $path or $path eq "-"
l!l&&r!l&&!r
3316
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 "-"
ABresult
1X1
011
000
64 16 ▶ open(my $fh, $op, $path)
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $op, $path or die "Failed to open '${path}': $!\n" 16 0 16
65 or die "Failed to open '$path': $!\n";
66 16 $fh;
67 };
68 }
69  
70 __END__
« lib/Pod/Markdown.pm ↑ Summary lib/Pod/Perldoc/ToMarkdown.pm »