line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Markup::Asciidoc; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3401
|
use 5.8.1; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
6
|
use File::Spec; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
29
|
use constant WIN32 => $^O eq 'MSWin32'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
70
|
|
8
|
1
|
|
|
1
|
|
8
|
use Symbol 'gensym'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
9
|
1
|
|
|
1
|
|
6
|
use IPC::Open3; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
10
|
1
|
|
|
1
|
|
7
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.25'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Find Asciidoc. |
15
|
|
|
|
|
|
|
my $ASCIIDOC; |
16
|
|
|
|
|
|
|
FIND: { |
17
|
|
|
|
|
|
|
my @path = ( |
18
|
|
|
|
|
|
|
File::Spec->path, |
19
|
|
|
|
|
|
|
WIN32 ? (map { "C:\\asciidoc$_" } '', '-8.6.6') : () |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
my @names = ( |
22
|
|
|
|
|
|
|
(map { (WIN32 ? ("$_.exe", "$_.bat") : ($_)) } qw(asciidoc)), |
23
|
|
|
|
|
|
|
'asciidoc.py', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
EXE: { |
26
|
|
|
|
|
|
|
for my $exe (@names) { |
27
|
|
|
|
|
|
|
for my $p (@path) { |
28
|
|
|
|
|
|
|
my $path = File::Spec->catfile($p, $exe); |
29
|
|
|
|
|
|
|
next unless -f $path && -x $path; |
30
|
|
|
|
|
|
|
$ASCIIDOC = $path; |
31
|
|
|
|
|
|
|
last EXE; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
unless ($ASCIIDOC) { |
37
|
1
|
|
|
1
|
|
211
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
210
|
|
38
|
|
|
|
|
|
|
my $sep = WIN32 ? ';' : ':'; |
39
|
|
|
|
|
|
|
my $list = join(', ', @names[0..$#names-1]) . ", or $names[-1]"; |
40
|
|
|
|
|
|
|
Carp::croak( |
41
|
|
|
|
|
|
|
"Cannot find $list in path " . join $sep => @path |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Make sure it looks like it will work. |
46
|
|
|
|
|
|
|
my $output = gensym; |
47
|
|
|
|
|
|
|
my $pid = open3 undef, $output, $output, $ASCIIDOC, '--version'; |
48
|
|
|
|
|
|
|
waitpid $pid, 0; |
49
|
|
|
|
|
|
|
if ($?) { |
50
|
1
|
|
|
1
|
|
10
|
use Carp; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
449
|
|
51
|
|
|
|
|
|
|
local $/; |
52
|
|
|
|
|
|
|
Carp::croak( |
53
|
|
|
|
|
|
|
qq{$ASCIIDOC will not execute\n}, |
54
|
|
|
|
|
|
|
<$output> |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Arguments to pass to asciidoc. |
60
|
|
|
|
|
|
|
# Restore --safe if Asciidoc ever fixes it with the XHTML back end. |
61
|
|
|
|
|
|
|
# https://groups.google.com/forum/#!topic/asciidoc/yEr5PqHm4-o |
62
|
|
|
|
|
|
|
my @OPTIONS = qw( |
63
|
|
|
|
|
|
|
--no-header-footer |
64
|
|
|
|
|
|
|
--out-file - |
65
|
|
|
|
|
|
|
--attribute newline=\\n |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub parser { |
69
|
0
|
|
|
0
|
|
|
my ($file, $encoding, $opts) = @_; |
70
|
0
|
|
|
|
|
|
my $html = do { |
71
|
0
|
|
|
|
|
|
my $fh = _fh( |
72
|
|
|
|
|
|
|
$ASCIIDOC, @OPTIONS, |
73
|
|
|
|
|
|
|
'--attribute' => "encoding=$encoding", |
74
|
|
|
|
|
|
|
$file |
75
|
|
|
|
|
|
|
); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
binmode $fh, ":encoding($encoding)"; |
78
|
0
|
|
|
|
|
|
local $/; |
79
|
0
|
|
|
|
|
|
<$fh>; |
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Make sure we have something. |
83
|
0
|
0
|
|
|
|
|
return unless $html =~ /\S/; |
84
|
0
|
|
|
|
|
|
utf8::encode $html; |
85
|
0
|
0
|
|
|
|
|
return $html if $opts->{raw}; |
86
|
0
|
|
|
|
|
|
return qq{ |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$html |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Stolen from SVN::Notify. |
98
|
|
|
|
|
|
|
sub _fh { |
99
|
0
|
|
|
0
|
|
|
if (WIN32) { |
100
|
|
|
|
|
|
|
my $cmd = q{"} . join(q{" "}, @_) . q{"|}; |
101
|
|
|
|
|
|
|
open my $fh, $cmd or die "Cannot fork: $!\n"; |
102
|
|
|
|
|
|
|
return $fh; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $pid = open my $fh, '-|'; |
106
|
0
|
0
|
|
|
|
|
die "Cannot fork: $!\n" unless defined $pid; |
107
|
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
if ($pid) { |
109
|
|
|
|
|
|
|
# Parent process, return the file handle. |
110
|
0
|
|
|
|
|
|
return $fh; |
111
|
|
|
|
|
|
|
} else { |
112
|
|
|
|
|
|
|
# Child process. Execute the commands. |
113
|
0
|
0
|
|
|
|
|
exec @_ or die "Cannot exec $_[0]: $!\n"; |
114
|
|
|
|
|
|
|
# Not reached. |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
__END__ |