blib/lib/Pandoc.pm

filter: Statementstmt 25.4% 52 / 204 Branchbran 9.0% 9 / 100 Conditioncond 10.0% 9 / 90 MC/DCmcdc 0.0% 0 / 50 Subroutinesub 43.3% 13 / 30 Podpod 94.7% 18 / 19 totaltotal 20.4% 101 / 493 SCAR 83.7
CC
87
Cov
18%
run
756.0
extensions
72.0
symlink
72.0
CRAP 4296.1
↑ Summary blib/lib/Pandoc/Release.pm »
1 package Pandoc;
2 10 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 10 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Pandoc - wrapper for the mighty Pandoc document converter
10  
11 =cut
12  
13 10 our $VERSION = '0.9.1';
14  
15 10 ▶use Pandoc::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 10 ▶use Pandoc::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 10 ▶use File::Which;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 10 ▶use File::Spec::Functions 'catdir';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 10 ▶use IPC::Run3;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 10 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 10 our @EXPORT = qw(pandoc pandoc_data_dir);
22  
23 10 our $PANDOC;
24 10 ▶our $PANDOC_PATH ||= $ENV{PANDOC_PATH} || 'pandoc';
Condition40%2/5
our $PANDOC_PATH ||= $ENV{"PANDOC_PATH"} || "pandoc"
l!l&&r!l&&!r
0100
$ENV{'PANDOC_PATH'} || 'pandoc'
l!l
010
MC/DC0%0/2
our $PANDOC_PATH ||= $ENV{"PANDOC_PATH"} || "pandoc"
our $PANDOC_PATH $ENV{'PANDOC_PATH'}
Truth table0%0/3
A ||= B
A= our $PANDOC_PATHB= $ENV{'PANDOC_PATH'}
ABresult
1X1
011
000
25  
26 sub import {
27 9 ▶ shift;
Subroutine import: called CC=6 SCAR=27.1
28  
29 9 ▶ if ( @_ and $_[0] =~ /^[v0-9.<>=!, ]+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and $_[0] =~ /^[v0-9.<>=!, ]+$/u) 0 9 9
Condition33%1/3
@_ and $_[0] =~ /^[v0-9.<>=!, ]+$/u
!ll&&!rl&&r
900
MC/DC0%0/2
@_ and $_[0] =~ /^[v0-9.<>=!, ]+$/u
@_ $_[0] =~ /^[v0-9.<>=!, ]+$/u
Truth table33%1/3
A and B
A= @_B= $_[0] =~ /^[v0-9.<>=!, ]+$/u
ABresult
0X0
100
111
30 0 ▶ $PANDOC //= Pandoc->new;
Condition0%0/3
$Pandoc::PANDOC //= "Pandoc"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$Pandoc::PANDOC //= "Pandoc"->new
$Pandoc::PANDOC "Pandoc"->new
Truth table0%0/3
A //= B
A= $Pandoc::PANDOCB= "Pandoc"->new
ABresult
1X1
011
000
31 0 $PANDOC->require(shift);
32 }
33 9 ▶ $PANDOC //= Pandoc->new(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 9 9
Condition0%0/3
$Pandoc::PANDOC //= "Pandoc"->new(@_)
l!l&&r!l&&!r
000
MC/DC0%0/2
$Pandoc::PANDOC //= "Pandoc"->new(@_)
$Pandoc::PANDOC "Pandoc"->new(@_)
Truth table0%0/3
A //= B
A= $Pandoc::PANDOCB= "Pandoc"->new(@_)
ABresult
1X1
011
000
34  
35 9 Pandoc->export_to_level( 1, 'pandoc' );
36 }
37  
38 sub VERSION {
39 0 ▶ shift;
Subroutine VERSION: not called CC=3 SCAR=24.8
Pod undocumented
40 0 ▶ $PANDOC //= Pandoc->new;
Condition0%0/3
$Pandoc::PANDOC //= "Pandoc"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$Pandoc::PANDOC //= "Pandoc"->new
$Pandoc::PANDOC "Pandoc"->new
Truth table0%0/3
A //= B
A= $Pandoc::PANDOCB= "Pandoc"->new
ABresult
1X1
011
000
41 0 ▶ $PANDOC->require(shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
42 0 $PANDOC->version;
43 }
44  
45 sub new {
46 8 ▶ my $pandoc = bless {}, shift;
Subroutine new: called CC=14 SCAR=41.4
Pod documented
47  
48 8 ▶ my $bin = ( @_ and $_[0] !~ /^-./ ) ? shift : $PANDOC_PATH;
Branch: 1 branch
BranchTrueFalseTotal
@_ && !($_[0] =~ /^-./u) ? : 0 8 8
Condition33%1/3
@_ and not $_[0] =~ /^-./u
!ll&&!rl&&r
800
MC/DC0%0/2
@_ and not $_[0] =~ /^-./u
@_ not $_[0] =~ /^-./u
Truth table33%1/3
A and not(B)
A= @_B= not $_[0] =~ /^-./u
ABresult
0X0
100
111
49  
50 8 my $bin_from_version = pandoc_data_dir( "bin", "pandoc-$bin" );
51 8 ▶ if ( !-x $bin && $bin =~ /^\d+(\.\d+)*$/ && -x $bin_from_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not -x $bin and $bin =~ /^\d+(\.\d+)*$/u and -x $bin_from_version) { } 0 8 8
Condition33%2/6
not -x $bin and $bin =~ /^\d+(\.\d+)*$/u and -x $bin_from_version
!ll&&!rl&&r
800
not -x $bin and $bin =~ /^\d+(\.\d+)*$/u
!ll&&!rl&&r
080
MC/DC0%0/3
not -x $bin and $bin =~ /^\d+(\.\d+)*$/u and -x $bin_from_version
not -x $bin $bin =~ /^\d+(\.\d+)*$/u -x $bin_from_version
Truth table25%1/4
not(A) and B and C
A= not -x $binB= $bin =~ /^\d+(\.\d+)*$/uC= -x $bin_from_version
ABCresult
0XX0
10X0
1100
1111
52 0 $pandoc->{bin} = $bin_from_version;
53 }
54 else {
55 8 $pandoc->{bin} = which($bin);
56 }
57  
58 8 $pandoc->{arguments} = [];
59 8 ▶ $pandoc->arguments(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 8 8
60  
61 8 my ( $in, $out, $err );
62  
63 8 ▶ if ( $pandoc->{bin} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pandoc->{"bin"}) 0 8 8
64 0 run3 [ $pandoc->{bin}, '-v' ], \$in, \$out, \$err,
65 { return_if_system_error => 1 };
66 }
67 8 ▶ unless ( $out and $out =~ /^[^ ]+ (\d+(\.\d+)+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($out and $out =~ /^[^ ]+ (\d+(\.\d+)+)/u) 8 0 8
Condition33%1/3
$out and $out =~ /^[^ ]+ (\d+(\.\d+)+)/u
!ll&&!rl&&r
800
MC/DC0%0/2
$out and $out =~ /^[^ ]+ (\d+(\.\d+)+)/u
$out $out =~ /^[^ ]+ (\d+(\.\d+)+)/u
Truth table33%1/3
A and B
A= $outB= $out =~ /^[^ ]+ (\d+(\.\d+)+)/u
ABresult
0X0
100
111
68 8 Pandoc::Error->throw(
69 message => "pandoc executable not found",
70 out => $out,
71 err => $err,
72 );
73 }
74  
75 0 $pandoc->{version} = Pandoc::Version->new($1);
76 0 ▶ $pandoc->{data_dir} = $1 if $out =~ /^Default user data directory: (.+)$/m;
Branch: 1 branch
BranchTrueFalseTotal
if $out =~ /^Default user data directory: (.+)$/mu 0 0 0
77  
78 # before pandoc supported --list-highlight-languages
79 0 ▶ if ( $out =~ /^Syntax highlighting is supported/m ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out =~ /^Syntax highlighting is supported/mu) 0 0 0
80 $pandoc->{highlight_languages} =
81 0 [ map { split /\s*,\s*/, $_ } ( $out =~ /^ (.+)$/mg ) ];
82 }
83  
84 0 my %libs;
85 0 my $LIBRARY_VERSION = qr/\s+(\pL\w*(?:-\pL\w*)*)\s+(\d+(?:\.\d+)*),?/;
86 0 ▶ if ( $out =~ /^Compiled with($LIBRARY_VERSION+)/m ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($out =~ /^Compiled with($LIBRARY_VERSION+)/mu) 0 0 0
87 0 %libs = $1 =~ /$LIBRARY_VERSION/g;
88 0 for my $name ( keys %libs ) {
89 0 $libs{$name} = Pandoc::Version->new( $libs{$name} );
90 }
91 }
92 0 $pandoc->{libs} = \%libs;
93  
94 0 return $pandoc;
95 }
96  
97 sub pandoc(@) { ## no critic
98 8 ▶ $PANDOC //= eval { Pandoc->new } // 0;
Subroutine pandoc: called CC=5 SCAR=20.9
Pod documented
Condition40%2/5
$Pandoc::PANDOC //= eval { do { "Pandoc"->new } } // 0
l!l&&r!l&&!r
080
eval { do { "Pandoc"->new } } // 0
l!l
08
MC/DC0%0/2
$Pandoc::PANDOC //= eval { do { "Pandoc"->new } } // 0
$Pandoc::PANDOC eval { do { "Pandoc"->new } }
Truth table0%0/3
A //= B
A= $Pandoc::PANDOCB= eval { do { "Pandoc"->new } }
ABresult
1X1
011
000
99  
100 8 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 8 8
101 0 ▶ return $PANDOC ? $PANDOC->run(@_) : -1;
Branch: 1 branch
BranchTrueFalseTotal
$Pandoc::PANDOC ? : 0 0 0
102 }
103 else {
104 8 return $PANDOC;
105 }
106 }
107  
108 sub run {
109 0 ▶ my $pandoc = shift;
Subroutine run: not called CC=27 SCAR=66.3
Pod documented
110  
111 0 ▶ my $args = 'ARRAY' eq ref $_[0] ? \@{ shift @_ } : undef; # \@args [ ... ]
Branch: 1 branch
BranchTrueFalseTotal
'ARRAY' eq ref $_[0] ? : 0 0 0
112 0 ▶ my $opts = 'HASH' eq ref $_[-1] ? \%{ pop @_ } : undef; # [ ... ] \%opts
Branch: 1 branch
BranchTrueFalseTotal
'HASH' eq ref $_[-1] ? : 0 0 0
113  
114 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
115 0 ▶ if ( !$args ) { # @args
Branch: 2 branches
BranchTrueFalseTotal
if (not $args) { } 0 0 0
elsif ($args and not $opts and @_ % 2 == 0) { } 0 0 0
116 0 ▶ if ( $_[0] =~ /^-/ or $opts or @_ % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^-/u or $opts or @_ % 2) { } 0 0 0
Condition0%0/6
$_[0] =~ /^-/u or $opts or @_ % 2
l!l&&r!l&&!r
000
$_[0] =~ /^-/u or $opts
l!l&&r!l&&!r
000
MC/DC0%0/3
$_[0] =~ /^-/u or $opts or @_ % 2
$_[0] =~ /^-/u $opts @_ % 2
Truth table0%0/4
A or B or C
A= $_[0] =~ /^-/uB= $optsC= @_ % 2
ABCresult
1XX1
01X1
0011
0000
117 0 $args = \@_;
118 }
119 else { # %opts
120 0 $opts = {@_};
121 }
122 }
123 ▶ elsif ( $args and !$opts and ( @_ % 2 == 0 ) ) { # \@args [, %opts ]
Condition0%0/6
$args and not $opts and @_ % 2 == 0
!ll&&!rl&&r
000
$args and not $opts
!ll&&!rl&&r
000
MC/DC0%0/3
$args and not $opts and @_ % 2 == 0
$args not $opts @_ % 2 == 0
Truth table0%0/4
A and not(B) and C
A= $argsB= not $optsC= @_ % 2 == 0
ABCresult
0XX0
10X0
1100
1111
124 0 $opts = {@_};
125 }
126 else {
127 # passed both the args and opts by ref,
128 # so other arguments don't make sense;
129 # or passed args by ref and an odd-length list
130 0 Pandoc::Error->throw('Too many or ambiguous arguments');
131 }
132 }
133  
134 0 ▶ $args //= [];
Condition0%0/2
$args //= []
l!l
00
MC/DC0%0/1
$args //= []
$args
Truth table0%0/2
A
A= $args
Aresult
11
00
135 0 ▶ $opts //= {};
Condition0%0/2
$opts //= {}
l!l
00
MC/DC0%0/1
$opts //= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
136  
137 0 for my $io (qw(in out err)) {
138 0 ▶ $opts->{"binmode_std$io"} //= $opts->{binmode} if $opts->{binmode};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"binmode"} 0 0 0
Condition0%0/3
$$opts{"binmode_std$io"} //= $opts->{"binmode"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$$opts{"binmode_std$io"} //= $opts->{"binmode"}
$$opts{"binmode_std$io"} $opts->{"binmode"}
Truth table0%0/3
A //= B
A= $$opts{"binmode_std$io"}B= $opts->{"binmode"}
ABresult
1X1
011
000
139 0 ▶ if ( 'SCALAR' eq ref $opts->{$io} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("SCALAR" eq ref $opts->{$io}) 0 0 0
140 0 ▶ next unless utf8::is_utf8( ${ $opts->{$io} } );
Branch: 1 branch
BranchTrueFalseTotal
unless utf8::is_utf8(${$$opts{$io};}) 0 0 0
141 0 ▶ $opts->{"binmode_std$io"} //= ':encoding(UTF-8)';
Condition0%0/2
$$opts{"binmode_std$io"} //= ":encoding(UTF-8)"
l!l
00
MC/DC0%0/1
$$opts{"binmode_std$io"} //= ":encoding(UTF-8)"
$$opts{"binmode_std$io"}
Truth table0%0/2
A
A= $$opts{"binmode_std$io"}
Aresult
11
00
142 }
143 }
144  
145 0 ▶ my $throw = $opts->{throw} || !( $opts->{return_if_system_error} // 1 );
Condition0%0/5
$opts->{'throw'} || !($opts->{'return_if_system_error'} // 1)
l!l&&r!l&&!r
000
$opts->{"return_if_system_error"} // 1
l!l
00
MC/DC0%0/2
$opts->{'throw'} || !($opts->{'return_if_system_error'} // 1)
$opts->{'throw'} $opts->{"return_if_system_error"}
Truth table0%0/3
A || not(B)
A= $opts->{'throw'}B= $opts->{"return_if_system_error"}
ABresult
1X1
001
010
146 0 ▶ $opts->{out} //= \( my $out );
Condition0%0/2
$opts->{"out"} //= \my $out
l!l
00
MC/DC0%0/1
$opts->{"out"} //= \my $out
$opts->{"out"}
Truth table0%0/2
A
A= $opts->{"out"}
Aresult
11
00
147 0 ▶ $opts->{err} //= \( my $err );
Condition0%0/2
$opts->{"err"} //= \my $err
l!l
00
MC/DC0%0/1
$opts->{"err"} //= \my $err
$opts->{"err"}
Truth table0%0/2
A
A= $opts->{"err"}
Aresult
11
00
148  
149 0 $opts->{return_if_system_error} = 1;
150 0 run3 [ $pandoc->{bin}, @{ $pandoc->{arguments} }, @$args ],
151 0 $opts->{in}, $opts->{out}, $opts->{err}, $opts;
152  
153 0 ▶ my $status = $? == -1 ? -1 : $? >> 8;
Branch: 1 branch
BranchTrueFalseTotal
$? == -1 ? : 0 0 0
154  
155 0 ▶ if ( $status && $throw ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status and $throw) { } 0 0 0
Condition0%0/3
$status and $throw
!ll&&!rl&&r
000
MC/DC0%0/2
$status and $throw
$status $throw
Truth table0%0/3
A and B
A= $statusB= $throw
ABresult
0X0
100
111
156 Pandoc::Error->throw(
157 system => $!,
158 0 out => ${ $opts->{out} },
159 0 ▶ err => ${ $opts->{err} },
Condition0%0/2
${$opts->{'err'};} || 'pandoc execution failed'
l!l
00
MC/DC0%0/1
${$opts->{'err'};} || 'pandoc execution failed'
${$opts->{'err'};}
Truth table0%0/2
A
A= ${$opts->{'err'};}
Aresult
11
00
160 status => $status,
161 0 message => ${ $opts->{err} } || 'pandoc execution failed'
162 );
163 }
164 else {
165 0 $status;
166 }
167 }
168  
169 sub convert {
170 0 ▶ my $pandoc = shift;
Subroutine convert: not called CC=2 SCAR=17.9
Pod documented
171 0 my $from = shift;
172 0 my $to = shift;
173 0 my $in = shift;
174 0 my $out = "";
175  
176 0 my $utf8 = utf8::is_utf8($in);
177  
178 0 $pandoc->run(
179 [ @_, '-f' => $from, '-t' => $to, '-o' => '-' ],
180 { in => \$in, out => \$out, throw => 1 }
181 );
182  
183 0 ▶ utf8::decode($out) if $utf8;
Branch: 1 branch
BranchTrueFalseTotal
if $utf8 0 0 0
184  
185 0 chomp $out;
186 0 return $out;
187 }
188  
189 sub parse {
190 0 ▶ my $pandoc = shift;
Subroutine parse: not called CC=2 SCAR=17.9
Pod documented
191 0 my $format = shift;
192 0 my $json = "";
193  
194 0 ▶ if ( $format eq 'json' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq 'json') { } 0 0 0
195 0 $json = shift;
196 }
197 else {
198 0 $pandoc->require('1.12.1');
199 0 $json = $pandoc->convert( $format => 'json', @_ );
200 }
201  
202 0 require Pandoc::Elements;
203 0 Pandoc::Elements::pandoc_json($json);
204 }
205  
206 sub file {
207 0 ▶ my $pandoc = shift;
Subroutine file: not called CC=1 SCAR=6.9
Pod documented
208 0 $pandoc->require('1.12.1');
209  
210 0 my @args = ( @_, '-t' => 'json', '-o' => '-' );
211 0 $pandoc->run( \@args, out => \( my $json ), throw => 1 );
212  
213 0 require Pandoc::Elements;
214 0 Pandoc::Elements::pandoc_json($json);
215 }
216  
217 sub require {
218 0 ▶ my $pandoc = shift;
Subroutine require: not called CC=4 SCAR=30.0
Pod documented
219 0 ▶ $pandoc = do { $PANDOC //= Pandoc->new } if $pandoc eq 'Pandoc';
Branch: 1 branch
BranchTrueFalseTotal
if $pandoc eq "Pandoc" 0 0 0
Condition0%0/3
$Pandoc::PANDOC //= "Pandoc"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$Pandoc::PANDOC //= "Pandoc"->new
$Pandoc::PANDOC "Pandoc"->new
Truth table0%0/3
A //= B
A= $Pandoc::PANDOCB= "Pandoc"->new
ABresult
1X1
011
000
220 0 ▶ unless ( $pandoc->version(@_) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pandoc->version(@_)) 0 0 0
221 Pandoc::Error->throw(
222 message => "pandoc $_[0] required, only found "
223 . $pandoc->{version},
224 version => $pandoc->{version},
225 0 require => $_[0],
226 );
227 }
228 0 return $pandoc;
229 }
230  
231 sub version {
232 0 ▶ my $pandoc = shift or return;
Subroutine version: not called CC=5 SCAR=34.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $pandoc = shift() or return 0 0 0
233 0 ▶ my $version = $pandoc->{version} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $version = $pandoc->{"version"} or return 0 0 0
234  
235 # compare against given version
236 0 ▶ return if @_ and not $version->fulfills(@_);
Branch: 1 branch
BranchTrueFalseTotal
if @_ and not $version->fulfills(@_) 0 0 0
Condition0%0/3
@_ and not $version->fulfills(@_)
!ll&&!rl&&r
000
MC/DC0%0/2
@_ and not $version->fulfills(@_)
@_ not $version->fulfills(@_)
Truth table0%0/3
A and not(B)
A= @_B= not $version->fulfills(@_)
ABresult
0X0
100
111
237  
238 0 return $version;
239 }
240  
241 sub data_dir {
242 0 ▶ catdir( shift->{data_dir}, @_ );
Subroutine data_dir: not called CC=1 SCAR=6.9
Pod documented
243 }
244  
245 sub pandoc_data_dir {
246 9 ▶ if ( $^O eq 'MSWin32' ) {
Subroutine pandoc_data_dir: called CC=2 SCAR=8.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 9 9
247 0 catdir( $ENV{APPDATA}, 'pandoc', @_ );
248 }
249 else {
250 9 catdir( $ENV{HOME}, '.pandoc', @_ );
251 }
252 }
253  
254 sub bin {
255 0 ▶ my $pandoc = shift;
Subroutine bin: not called CC=3 SCAR=24.8
Pod documented
256 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
257 0 my $new = Pandoc->new(shift);
258 0 $pandoc->{$_} = $new->{$_} for (qw(version bin data_dir));
259 }
260 0 $pandoc->{bin};
261 }
262  
263 sub arguments {
264 0 ▶ my $pandoc = shift;
Subroutine arguments: not called CC=5 SCAR=34.0
Pod documented
265 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
266 0 ▶ my $args = 'ARRAY' eq ref $_[0] ? shift : \@_;
Branch: 1 branch
BranchTrueFalseTotal
'ARRAY' eq ref $_[0] ? : 0 0 0
267 0 ▶ Pandoc::Error->throw("first default argument must be an -option")
Branch: 1 branch
BranchTrueFalseTotal
if @$args and not $args->[0] =~ /^-./u 0 0 0
Condition0%0/3
@$args and not $args->[0] =~ /^-./u
!ll&&!rl&&r
000
MC/DC0%0/2
@$args and not $args->[0] =~ /^-./u
@$args not $args->[0] =~ /^-./u
Truth table0%0/3
A and not(B)
A= @$argsB= not $args->[0] =~ /^-./u
ABresult
0X0
100
111
268 if @$args and $args->[0] !~ /^-./;
269 0 $pandoc->{arguments} = $args;
270 }
271 0 @{ $pandoc->{arguments} };
272 }
273  
274 sub _list {
275 0 ▶ my ( $pandoc, $which ) = @_;
Subroutine _list: not called CC=7 SCAR=40.3
276 0 ▶ if ( !$pandoc->{$which} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pandoc->{$which}) 0 0 0
277 0 ▶ if ( $pandoc->version('1.18') ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pandoc->version('1.18')) { } 0 0 0
elsif (not defined $pandoc->{'help'}) { } 0 0 0
278 0 my $list = "";
279 0 my $command = $which;
280 0 $command =~ s/_/-/g;
281 0 $pandoc->run( "--list-$command", { out => \$list } );
282 0 $pandoc->{$which} = [ split /\n/, $list ];
283 }
284 elsif ( !defined $pandoc->{help} ) {
285 0 my $help;
286 0 $pandoc->run( '--help', { out => \$help } );
287 0 for my $inout (qw(Input Output)) {
288 0 ▶ $help =~ /^$inout formats:\s+([a-z_0-9,\+\s*]+)/m or next;
Branch: 1 branch
BranchTrueFalseTotal
$help =~ /^$inout formats:\s+([a-z_0-9,\+\s*]+)/mu or next 0 0 0
289 0 $pandoc->{ lc($inout) . '_formats' } =
290 [ split /\*?,\s+|\*?\s+/, $1 ];
291 }
292 0 $pandoc->{help} = $help;
293 }
294 }
295 0 ▶ @{ $pandoc->{$which} // [] };
Condition0%0/2
$pandoc->{$which} // []
l!l
00
MC/DC0%0/1
$pandoc->{$which} // []
$pandoc->{$which}
Truth table0%0/2
A
A= $pandoc->{$which}
Aresult
11
00
296 }
297  
298 sub input_formats {
299 0 ▶ $_[0]->_list('input_formats');
Subroutine input_formats: not called CC=1 SCAR=6.9
Pod documented
300 }
301  
302 sub output_formats {
303 0 ▶ $_[0]->_list('output_formats');
Subroutine output_formats: not called CC=1 SCAR=6.9
Pod documented
304 }
305  
306 sub highlight_languages {
307 0 ▶ $_[0]->_list('highlight_languages');
Subroutine highlight_languages: not called CC=1 SCAR=6.9
Pod documented
308 }
309  
310 sub extensions {
311 0 ▶ my $pandoc = shift;
Subroutine extensions: not called CC=8 SCAR=42.8
Pod documented
312 0 ▶ my $format = shift // '';
Condition0%0/2
shift() // ""
l!l
00
MC/DC0%0/1
shift() // ""
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
313 0 my $out = "";
314 0 my %ext;
315  
316 0 ▶ if ( $pandoc->version < 1.18 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pandoc->version < 1.18) { } 0 0 0
317 0 warn "pandoc >= 1.18 required for --list-extensions\n";
318 }
319 else {
320 0 ▶ if ($format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format) 0 0 0
321 0 ▶ if ( $format =~ /^[a-z0-9_]$/ and $pandoc->version >= '2.0.6' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format =~ /^[a-z0-9_]$/u and $pandoc->version >= '2.0.6') { } 0 0 0
Condition0%0/3
$format =~ /^[a-z0-9_]$/u and $pandoc->version >= "2.0.6"
!ll&&!rl&&r
000
MC/DC0%0/2
$format =~ /^[a-z0-9_]$/u and $pandoc->version >= "2.0.6"
$format =~ /^[a-z0-9_]$/u $pandoc->version >= "2.0.6"
Truth table0%0/3
A and B
A= $format =~ /^[a-z0-9_]$/uB= $pandoc->version >= "2.0.6"
ABresult
0X0
100
111
322 0 $format = "=$format";
323 }
324 else {
325 0 warn "ignoring format argument to Pandoc->extensions\n";
326 0 $format = '';
327 }
328 }
329 0 $pandoc->run( "--list-extensions$format", { out => \$out } );
330 %ext = map {
331 0 $_ =~ /^([+-]?)\s*([^-+ ]+)\s*([+-]?)$/;
332 0 ▶ ( $2 => ( $1 || $3 ) eq '+' ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
($1 || $3) eq '+' ? : 0 0 0
Condition0%0/3
$1 || $3
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 || $3
$1 $3
Truth table0%0/3
A || B
A= $1B= $3
ABresult
1X1
011
000
333 } split /\n/, $out;
334 }
335  
336 0 %ext;
337 }
338  
339 sub libs {
340 0 ▶ $_[0]->{libs};
Subroutine libs: not called CC=1 SCAR=6.9
Pod documented
341 }
342  
343 sub symlink {
344 0 ▶ my $self = shift;
Subroutine symlink: not called CC=8 SCAR=42.8
Pod documented
345 0 ▶ my ( $name, %opts ) = @_ % 2 ? @_ : ( '', @_ );
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 0 0 0
346  
347 0 ▶ if ( '' eq $name // '' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ('' eq $name // '') { } 0 0 0
elsif (-d $name) { } 0 0 0
Condition0%0/2
"" eq $name // ""
l!l
00
MC/DC0%0/1
"" eq $name // ""
"" eq $name
Truth table0%0/2
A
A= "" eq $name
Aresult
11
00
348 0 $name = pandoc_data_dir( 'bin', 'pandoc' );
349 }
350 elsif ( -d $name ) {
351 0 $name = "$name/pandoc";
352 }
353  
354 0 my $bin = $self->bin;
355  
356 0 ▶ unlink $name if -l $name;
Branch: 1 branch
BranchTrueFalseTotal
if -l $name 0 0 0
357 0 ▶ if ( symlink $bin, $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (CORE::symlink $bin, $name) { } 0 0 0
358 0 ▶ say "symlinked $name -> $bin" if $opts{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"verbose"} 0 0 0
359 0 $self->bin($name);
360 }
361 else {
362 0 die "failed to create symlink $name -> $bin\n";
363 }
364  
365 0 $self;
366 }
367  
368 10 1;
369  
370 __END__
↑ Summary blib/lib/Pandoc/Release.pm »