| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | package Pod::Elemental::Transformer::Verbatim; # git description: 8baf5a3 | ||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Transform :verbatim regions into verbatim paragraphs | ||||||||||||||||||||||||||||
| 5 | # KEYWORDS: pod transformer verbatim literal indent code text | ||||||||||||||||||||||||||||
| 6 | # vim: set ts=8 sts=4 sw=4 tw=115 et : | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | with 'Pod::Elemental::Transformer' => { -version => '0.101620' }; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Pod::Elemental::Types 'FormatName'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Pod::Elemental::Element::Pod5::Verbatim; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | has format_name => ( | |||||||||||||||||||||||||||
| 18 | is => 'ro', | ||||||||||||||||||||||||||||
| 19 | isa => FormatName, | ||||||||||||||||||||||||||||
| 20 | default => 'verbatim', | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | ## TODO? customize the number of columns used for indenting | ||||||||||||||||||||||||||||
| 24 | 4 | ▶ | sub indent_level { 4 } | ||||||||||||||||||||||||||
|
Subroutine
indent_level: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | sub transform_node | ||||||||||||||||||||||||||||
| 27 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
transform_node: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 2 | my ($self, $node) = @_; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # why do we process in reverse? it should make no difference | ||||||||||||||||||||||||||||
| 31 | 2 | for my $i (reverse(0 .. $#{ $node->children })) { | |||||||||||||||||||||||||||
| 32 | 10 | my $para = $node->children->[ $i ]; | |||||||||||||||||||||||||||
| 33 | 10 | ▶ | next unless $self->__is_xformable($para); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 2 | my @replacements = $self->_make_verbatim( $para ); | |||||||||||||||||||||||||||
| 35 | 2 | splice @{ $node->children }, $i, 1, @replacements; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | return $node; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | sub _make_verbatim | ||||||||||||||||||||||||||||
| 42 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_make_verbatim: called CC=4 SCAR=15.2
| |||||||||||||||||||||||||||||
| 43 | 2 | my ($self, $parent) = @_; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | return map { | ||||||||||||||||||||||||||||
| 46 | 3 | my $para = $_; | |||||||||||||||||||||||||||
| 47 | !$para->isa('Pod::Elemental::Element::Pod5::Ordinary') | ||||||||||||||||||||||||||||
| 48 | ? ($self->__is_xformable($para) ? $self->_make_verbatim($para) : $para) | ||||||||||||||||||||||||||||
| 49 | : length $para->content | ||||||||||||||||||||||||||||
| 50 | ? Pod::Elemental::Element::Pod5::Verbatim->new({ | ||||||||||||||||||||||||||||
| 51 | 3 | ▶ | content => join("\n", map { ' ' x $self->indent_level . $_ } split(/\n/, $para->content)), | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 52 | }) | ||||||||||||||||||||||||||||
| 53 | : (); | ||||||||||||||||||||||||||||
| 54 | 2 | } @{ $parent->children }; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # from ::List | ||||||||||||||||||||||||||||
| 58 | sub __is_xformable | ||||||||||||||||||||||||||||
| 59 | 10 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__is_xformable: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||
| 60 | 10 | my ($self, $para) = @_; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 10 | ▶ | return unless $para->isa('Pod::Elemental::Element::Pod5::Region') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$para->isa("Pod::Elemental::Element::Pod5::Region") and $para->format_name eq $self->format_name
MC/DC50%1/2
$para->isa("Pod::Elemental::Element::Pod5::Region") and $para->format_name eq $self->format_name
$para->isa("Pod::Elemental::Element::Pod5::Region")
$para->format_name eq $self->format_name
Truth table66%2/3
A and B
A= $para->isa("Pod::Elemental::Element::Pod5::Region")B= $para->format_name eq $self->format_name
| |||||||||||||||||||||||||||||
| 63 | and $para->format_name eq $self->format_name; | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | confess('verbatim regions must be pod (=begin :' . $self->format_name . ')') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | unless $para->is_pod; | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | return 1; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | 1; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||