File Coverage

lib/App/pandoc/preprocess.pm
Criterion Covered Total %
statement 21 44 47.7
branch n/a
condition n/a
subroutine 8 13 61.5
pod 0 2 0.0
total 29 59 49.1


line stmt bran cond sub pod time code
1             package App::pandoc::preprocess;
2             BEGIN {
3 1     1   85152 $App::pandoc::preprocess::AUTHORITY = 'cpan:DBR';
4             }
5             {
6             $App::pandoc::preprocess::VERSION = '0.1.0_1';
7             }
8              
9             # PODNAME: pdoc
10             # ABSTRACT: typeset pandoc documents with document-specific, default options
11              
12 1     1   27 use v5.14;
  1         4  
13 1     1   5 use strict;
  1         1  
  1         35  
14 1     1   5 use warnings;
  1         2  
  1         31  
15 1     1   639 use Moo;
  1         12099  
  1         5  
16 1     1   1549 use Moo;
  1         2  
  1         6  
17 1     1   812 use MooX::Options;
  1         4000  
  1         6  
18              
19             option 'show_this_file' => (
20             is => 'ro',
21             format => 's',
22             required => 1,
23             doc => 'the file to display'
24             );
25              
26             sub main {
27 0     0 0   state $file = 0;
28              
29             sub gen {
30             my $cmd = {
31             dot => sub {
32 0     0     my ($file, $filename) = @_;
33 0           `dot -Tpng -Gsize=1,2\\! -o image-$file.png $filename`;
34             },
35             ditaa => sub {
36 0     0     my ($file, $filename) = @_;
37 0           `ditaa $filename image-$file.png`; #--no-shadows --scale 0.4
38             },
39             rdfdot => sub {
40 0     0     my ($file, $filename) = @_;
41 0           `rdfdot -ttl $filename image-$file.png`; #--no-shadows --scale 0.4
42             },
43 0     0 0   };
44              
45 0           my ($format, $content) = @_;
46 0           my $filename = "image-". ++$file .".$format";
47 0           open my $outfile, '>', $filename;
48 0           print {$outfile} $content;
  0            
49 0           $cmd->{$format}($file, $filename);
50 0           `mogrify -scale 75% image-$file.png`;
51 0           return "![](image-$file.png)" #\\
52             }
53              
54 0           $_ = do { local (@ARGV, $/) = @ARGV; <> };
  0            
  0            
55              
56 0           my $RE = {
57             begin_of_line => qr/^/sm,
58             codeblock_begin => qr/^~+/sm,
59             codeblock_content => qr/.*?/sm,
60             codeblock_end => qr/^~+/sm,
61             format_specification => qr/(?:dot|ditaa|rdfdot)/sm,
62             random_stuff_nongreedy => qr/.*?/sm,
63             possibly_spaces => qr/\s*/sm,
64             };
65              
66              
67             # This regex matches lines similar to:
68             # ~~~~ {.ditaa}
69             # <.ditaa content here>
70             # ~~~~
71 0           s[
72             (?
73             $RE->{codeblock_begin} $RE->{possibly_spaces} \{
74             $RE->{random_stuff_nongreedy}
75             \.(? $RE->{format_specification} )
76             $RE->{random_stuff_nongreedy}
77             \}
78             $RE->{random_stuff_nongreedy}
79             $RE->{begin_of_line}(? $RE->{codeblock_content} )
80             $RE->{codeblock_end}
81             )
82             ][
83 1     1   128978 gen( $+{format} => $+{content} )
  1         473  
  1         98  
84 0           ]gosemix;
85              
86 0           say $_
87             }
88              
89             1;
90              
91             __END__