File Coverage

blib/lib/Text/Markup/Asciidoc.pm
Criterion Covered Total %
statement 17 29 58.6
branch 0 6 0.0
condition n/a
subroutine 6 8 75.0
pod n/a
total 23 43 53.4


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