blib/lib/Pandoc/Filter.pm

filter: Statementstmt 88.3% 53 / 60 Branchbran 50.0% 2 / 4 Conditioncond 71.4% 5 / 7 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 89.4% 17 / 19 Podpod 85.7% 6 / 7 totaltotal 84.0% 84 / 100 CC 7 SCAR 8.7
CC
7
Cov
85%
__ANON__
6.0
apply
5.2
pandoc_walk
2.0
CRAP 2.4
« blib/lib/Pod/Simple/Pandoc.pm ↑ Summary blib/lib/Pandoc/Filter/Lazy.pm »
1 package Pandoc::Filter;
2 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 our $VERSION = '0.17';
7  
8 4 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Scalar::Util 'reftype';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use List::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Pandoc::Walker;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Pandoc::Elements ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 4 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 our @EXPORT = qw(pandoc_filter pandoc_walk stringify);
17  
18 sub stringify {
19 0 ▶ $_[0]->string;
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
20 }
21  
22 sub pandoc_walk(@) { ## no critic
23 2 ▶ my $filter = Pandoc::Filter->new(@_);
Subroutine pandoc_walk: called CC=2 SCAR=7.0
Pod documented
24 2 my $ast = Pandoc::Elements::pandoc_json(<STDIN>);
25 2 ▶ binmode STDOUT, ':encoding(UTF-8)';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶ $filter->apply( $ast, @ARGV ? $ARGV[0] : '' );
Branch: 1 branch
BranchTrueFalseTotal
@ARGV ? : 0 2 2
27 }
28  
29 sub pandoc_filter(@) { ## no critic
30 2 ▶ my $ast = pandoc_walk(@_); # implies binmode STDOUT UTF-8
Subroutine pandoc_filter: called CC=1 SCAR=0.0
Pod documented
31 2 my $json = JSON->new->allow_blessed->convert_blessed->encode($ast);
32  
33 #my $json = $ast->to_json; # does not want binmode STDOUT UTF-8
34 2 say STDOUT $json;
35 }
36  
37 # constructor and methods
38  
39 sub new {
40 8 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
41 8 bless {
42 action => Pandoc::Walker::action(@_),
43 error => '',
44 }, $class;
45 }
46  
47 sub error {
48 7 ▶ $_[0]->{error};
Subroutine error: called CC=1 SCAR=0.0
Pod undocumented
49 }
50  
51 sub action {
52 1 ▶ return $_[0]->{action};
Subroutine action: called CC=1 SCAR=4.9
Pod documented
53  
54 0 my $actions = $_[0]->{actions};
55  
56 sub {
57 0 ▶ my ( $element, $format, $meta ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
58 0 foreach my $action (@$actions) {
59 0 local $_ = $element;
60 0 $action->( $element, $format, $meta );
61 }
62 }
63 0 }
64  
65 # TODO: refactor with method action
66 sub apply {
67 9 ▶ my ( $self, $ast, $format, $meta ) = @_;
Subroutine apply: called CC=5 SCAR=16.4
Pod documented
68 9 ▶ $format ||= '';
Condition100%2/2
$format ||= ""
l!l
18
MC/DC100%1/1
$format ||= ""
$format
Truth table100%2/2
A
A= $format
Aresult
11
00
69 9 ▶ $meta ||= eval { $ast->[0]->{unMeta} } || {};
Condition60%3/5
$meta ||= eval { do { $ast->[0]{"unMeta"} } } || {}
l!l&&r!l&&!r
090
eval { do { $ast->[0]{'unMeta'} } } || {}
l!l
72
MC/DC0%0/2
$meta ||= eval { do { $ast->[0]{"unMeta"} } } || {}
$meta eval { do { $ast->[0]{'unMeta'} } }
Truth table33%1/3
A ||= B
A= $metaB= eval { do { $ast->[0]{'unMeta'} } }
ABresult
1X1
011
000
70  
71 9 ▶ if ( $self->{action} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"action"}) 9 0 9
72 9 Pandoc::Walker::transform( $ast, $self->{action}, $format, $meta );
73 }
74  
75 # foreach my $action (@{$self->{actions}}) {
76 # Pandoc::Walker::transform( $ast, $action, $format, $meta );
77 # }
78 9 $ast;
79 }
80  
81 4 1;
82 __END__
« blib/lib/Pod/Simple/Pandoc.pm ↑ Summary blib/lib/Pandoc/Filter/Lazy.pm »