File Coverage

blib/lib/App/pod2pandoc.pm
Criterion Covered Total %
statement 40 58 68.9
branch 5 20 25.0
condition 2 9 22.2
subroutine 11 12 91.6
pod 2 2 100.0
total 60 101 59.4


line stmt bran cond sub pod time code
1             package App::pod2pandoc;
2 3     3   26799 use strict;
  3         5  
  3         113  
3 3     3   10 use warnings;
  3         2  
  3         103  
4 3     3   46 use 5.010;
  3         9  
5              
6             our $VERSION = '0.3.2';
7              
8 3     3   1940 use Getopt::Long qw(:config pass_through);
  3         24872  
  3         14  
9 3     3   1869 use Pod::Usage;
  3         81779  
  3         339  
10 3     3   1051 use Pod::Simple::Pandoc;
  3         6  
  3         89  
11 3     3   13 use Pandoc;
  3         3  
  3         17  
12 3     3   211 use Pandoc::Elements;
  3         5  
  3         571  
13 3     3   14 use List::Util qw(all);
  3         4  
  3         188  
14              
15 3     3   11 use parent 'Exporter';
  3         3  
  3         34  
16             our @EXPORT = qw(pod2pandoc);
17             our @EXPORT_OK = qw(pod2pandoc parse_arguments);
18              
19             sub parse_arguments {
20 2     2 1 7 my %opt;
21 2 50       10 Getopt::Long::GetOptionsFromArray(
22             \@_, \%opt, 'help|h|?', 'data-sections',
23             'podurl=s', 'ext=s', 'index=s', 'wiki',
24             'update', 'quiet'
25             ) or exit 1;
26 2 50       847 pod2usage(1) if delete $opt{help};
27              
28 2 50       5 my @input = @_ ? () : '-';
29              
30 2         5 my ($index) = grep { $_[$_] eq '--' } ( 0 .. @_ - 1 );
  9         11  
31              
32 2 100       5 if ( defined $index ) {
33 1         5 push @input, shift @_ for 0 .. $index - 1;
34 1         2 shift @_; # --
35             }
36             else {
37 1   66     15 push( @input, shift @_ ) while @_ and $_[0] !~ /^-./;
38             }
39              
40 2         18 return ( \@input, \%opt, @_ );
41             }
42              
43             sub pod2pandoc {
44 0     0 1   my $input = shift;
45 0 0         my $opt = ref $_[0] ? shift : {};
46 0           my @args = @_;
47              
48             # directories
49 0 0 0       if ( @$input > 0 and -d $input->[0] ) {
50 0 0         my $target = @$input > 1 ? pop @$input : $input->[0];
51              
52 0           my $modules = Pod::Pandoc::Modules->new;
53 0           foreach my $dir (@$input) {
54 0           my $found = Pod::Simple::Pandoc->new->parse_modules($dir);
55             warn "no .pm, .pod or Perl script found in $dir\n"
56 0 0 0       unless %$found or $opt->{quiet};
57 0           $modules->add( $_ => $found->{$_} ) for keys %$found;
58             }
59 0           $modules->serialize( $target, $opt, @args );
60             }
61              
62             # files and/or module names
63             else {
64 0           my $parser = Pod::Simple::Pandoc->new(%$opt);
65 0 0         my $doc = $parser->parse_and_merge( @$input ? @$input : '-' );
66              
67 0 0         if (@args) {
68 0           pandoc->require('1.12.1');
69 0           $doc->pandoc_version( pandoc->version );
70 0           print $doc->to_pandoc(@args);
71             }
72             else {
73 0           print $doc->to_json, "\n";
74             }
75             }
76             }
77              
78             1;
79             __END__