blib/lib/Pandoc/Filter.pm

filter: Statementstmt 86.5% 58 / 67 Branchbran 40.0% 4 / 10 Conditioncond 76.9% 10 / 13 MC/DCmcdc 33.3% 2 / 6 Subroutinesub 94.4% 17 / 18 Podpod 66.6% 4 / 6 totaltotal 79.1% 95 / 120 SCAR 24.8
CC
11
Cov
80%
_pod2usage_if_help
8.3
new
4.1
apply
4.0
CRAP 12.0
« blib/lib/Pandoc/Filter/HeaderIdentifiers.pm ↑ Summary Build »
1 package Pandoc::Filter;
2 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 our $VERSION = '0.34';
7  
8 7 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Scalar::Util 'reftype';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Pandoc::Walker;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 ▶use Pandoc::Elements qw(Image Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 7 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 our @EXPORT = qw(pandoc_filter pandoc_filter_document pandoc_walk);
17  
18 # FUNCTIONS
19  
20 sub pandoc_walk(@) { ## no critic
21 3 ▶ my $filter = Pandoc::Filter->new(@_);
Subroutine pandoc_walk: called CC=2 SCAR=7.0
Pod undocumented
22 3 my $ast = Pandoc::Elements::pandoc_json(<STDIN>);
23 3 ▶ binmode STDOUT, ':encoding(UTF-8)';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶ $filter->apply( $ast->content, @ARGV ? $ARGV[0] : '', $ast->meta );
Branch: 1 branch
BranchTrueFalseTotal
@ARGV ? : 0 3 3
25 3 return $ast;
26 }
27  
28 sub _pod2usage_if_help {
29 2 ▶ require Getopt::Long;
Subroutine _pod2usage_if_help: called CC=4 SCAR=21.1
30 2 my %opt;
31 2 Getopt::Long::GetOptions(\%opt, 'help|?');
32 2 ▶ return unless $opt{help};
Branch: 1 branch
BranchTrueFalseTotal
unless $opt{"help"} 2 0 2
33  
34 ## no critic
35 0 ▶ my $module = -t STDOUT ? 'Pod::Text::Termcap' : 'Pod::Text';
Branch: 1 branch
BranchTrueFalseTotal
-t STDOUT ? : 0 0 0
36 0 ▶ eval "require $module" or die "Can't locate $module in \@INC\n";
Branch: 1 branch
BranchTrueFalseTotal
eval "require $module" or die "Can't locate $module in \@INC\n" 0 0 0
37 0 $module->new( indent => 2, nourls => 1 )->parse_file($0);
38  
39 0 exit;
40 }
41  
42 sub pandoc_filter(@) { ## no critic
43 2 ▶ _pod2usage_if_help();
Subroutine pandoc_filter: called CC=1 SCAR=0.0
Pod documented
44  
45 2 my $ast = pandoc_walk(@_); # implies binmode STDOUT UTF-8
46 2 my $json = JSON->new->allow_blessed->convert_blessed->encode($ast);
47  
48 #my $json = $ast->to_json; # does not want binmode STDOUT UTF-8
49 2 say STDOUT $json;
50 }
51  
52 sub pandoc_filter_document($) { ## no critic
53 0 ▶ _pod2usage_if_help();
Subroutine pandoc_filter_document: not called CC=1 SCAR=6.9
Pod undocumented
54  
55 0 my $filter = shift;
56 0 my $doc = Pandoc::Elements::pandoc_json(<STDIN>);
57 0 $filter->apply( $doc, $ARGV[0] );
58  
59 0 say $doc->to_json;
60 }
61  
62 # METHODS
63  
64 sub new {
65 10 ▶ my $class = shift;
Subroutine new: called CC=4 SCAR=14.1
Pod documented
66 10 ▶ my $action = (@_ < 2 or @_ % 2 or ref $_[0])
Branch: 1 branch
BranchTrueFalseTotal
@_ < 2 || @_ % 2 || ref $_[0] ? : 6 4 10
Condition66%4/6
@_ < 2 or @_ % 2 or ref $_[0]
l!l&&r!l&&!r
604
@_ < 2 or @_ % 2
l!l&&r!l&&!r
604
MC/DC33%1/3
@_ < 2 or @_ % 2 or ref $_[0]
@_ < 2 @_ % 2 ref $_[0]
Truth table50%2/4
A or B or C
A= @_ < 2B= @_ % 2C= ref $_[0]
ABCresult
1XX1
01X1
0011
0000
67 ? Pandoc::Walker::action(@_) # @actions
68 : Pandoc::Walker::action({ @_ }); # %actions
69 10 bless {
70 action => $action,
71 error => '',
72 }, $class;
73 }
74  
75 sub action {
76 11 ▶ $_[0]->{action};
Subroutine action: called CC=1 SCAR=0.0
Pod documented
77 }
78  
79 sub apply {
80 10 ▶ my ( $self, $ast, $format, $meta ) = @_;
Subroutine apply: called CC=4 SCAR=13.9
Pod documented
81 10 ▶ $format ||= '';
Condition100%2/2
$format ||= ""
l!l
19
MC/DC100%1/1
$format ||= ""
$format
Truth table100%2/2
A
A= $format
Aresult
11
00
82 10 ▶ $meta ||= eval { $ast->meta } || {};
Condition80%4/5
$meta ||= eval { do { $ast->meta } } || {}
l!l&&r!l&&!r
370
eval { do { $ast->meta } } || {}
l!l
43
MC/DC0%0/2
$meta ||= eval { do { $ast->meta } } || {}
$meta eval { do { $ast->meta } }
Truth table66%2/3
A ||= B
A= $metaB= eval { do { $ast->meta } }
ABresult
1X1
011
000
83  
84 10 Pandoc::Walker::transform( $ast, $self->action, $format, $meta );
85  
86 10 $ast;
87 }
88  
89 7 1;
90 __END__
« blib/lib/Pandoc/Filter/HeaderIdentifiers.pm ↑ Summary Build »