| 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
| |||||||||||||||||||||||||
| 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 ||= ""
MC/DC100%1/1
$format ||= ""
$format
Truth table100%2/2
A
A= $format
| |||||||||||||||||||||||||
| 69 | 9 | ▶ | $meta ||= eval { $ast->[0]->{unMeta} } || {}; | ||||||||||||||||||||||
|
Condition60%3/5
$meta ||= eval {
do {
$ast->[0]{"unMeta"}
}
} || {}
eval {
do {
$ast->[0]{'unMeta'}
}
} || {}
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'}
}
}
| |||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||
| 71 | 9 | ▶ | if ( $self->{action} ) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||