File Coverage

blib/lib/Text/Markup/Asciidoctor.pm
Criterion Covered Total %
statement 17 29 58.6
branch 0 4 0.0
condition 0 3 0.0
subroutine 6 8 75.0
pod n/a
total 23 44 52.2


line stmt bran cond sub pod time code
1             package Text::Markup::Asciidoctor;
2              
3 1     1   2582 use 5.8.1;
  1         3  
4 1     1   4 use strict;
  1         1  
  1         15  
5 1     1   3 use warnings;
  1         1  
  1         45  
6 1     1   3 use Text::Markup;
  1         2  
  1         11  
7 1     1   3 use Text::Markup::Cmd;
  1         1  
  1         50  
8 1     1   4 use utf8;
  1         1  
  1         4  
9              
10             our $VERSION = '0.41';
11              
12             sub import {
13             # Replace Text::Markup::Asciidoc.
14 0   0 0     Text::Markup->register( asciidoc => $_[1] || qr{a(?:sc(?:iidoc)?|doc)?} );
15             }
16              
17             # Find Asciidoc.
18             my $ASCIIDOC = find_cmd([
19             (map { (WIN32 ? ("$_.exe", "$_.bat") : ($_)) } qw(asciidoctor)),
20             'asciidoctor.py',
21             ], '--version');
22              
23             # Arguments to pass to asciidoc.
24             # Restore --safe if Asciidoc ever fixes it with the XHTML back end.
25             # https://groups.google.com/forum/#!topic/asciidoc/yEr5PqHm4-o
26             my @OPTIONS = qw(
27             --no-header-footer
28             --out-file -
29             --attribute newline=\\n
30             );
31              
32             sub parser {
33 0     0     my ($file, $encoding, $opts) = @_;
34 0           my $html = do {
35 0           my $fh = open_pipe(
36             $ASCIIDOC, @OPTIONS,
37             '--attribute' => "encoding=$encoding",
38             $file
39             );
40              
41 0           binmode $fh, ":encoding($encoding)";
42 0           local $/;
43 0           <$fh>;
44             };
45              
46             # Make sure we have something.
47 0 0         return unless $html =~ /\S/;
48 0           utf8::encode $html;
49 0 0         return $html if { @{ $opts } }->{raw};
  0            
50 0           return qq{
51            
52            
53            
54            
55             $html
56            
57            
58             };
59             }
60             1;
61             __END__