| 1 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package HTML::FormFu::OutputProcessor::Indent; | ||||||||||||||||||||||||||||
| 4 | 5 | $HTML::FormFu::OutputProcessor::Indent::VERSION = '2.09'; | |||||||||||||||||||||||||||
| 5 | # ABSTRACT: Nicely Indent HTML Output | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use MooseX::Attribute::Chained; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | extends 'HTML::FormFu::OutputProcessor'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use HTML::FormFu::Constants qw( $EMPTY_STR $SPACE ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use HTML::TokeParser::Simple; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use List::Util 1.33 qw( any ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 5 | has indent => ( | |||||||||||||||||||||||||||
| 16 | is => 'rw', | ||||||||||||||||||||||||||||
| 17 | default => "\t", | ||||||||||||||||||||||||||||
| 18 | lazy => 1, | ||||||||||||||||||||||||||||
| 19 | traits => ['Chained'], | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | has preserve_tags => ( | ||||||||||||||||||||||||||||
| 23 | is => 'rw', | ||||||||||||||||||||||||||||
| 24 | 2 | ▶ | default => sub { [qw( pre textarea )] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 5 | lazy => 1, | |||||||||||||||||||||||||||
| 26 | traits => ['Chained'], | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 5 | ▶ | sub process { | ||||||||||||||||||||||||||
|
Subroutine
process: called CC=17 SCAR=28.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 5 | my ( $self, $input ) = @_; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 5 | my $indent = $self->indent; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 5 | my $parser = HTML::TokeParser::Simple->new( \$input ); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 5 | my @preserve_tags = @{ $self->preserve_tags }; | |||||||||||||||||||||||||||
| 37 | 5 | my $count = 0; | |||||||||||||||||||||||||||
| 38 | 5 | my $in_pre = 0; | |||||||||||||||||||||||||||
| 39 | 5 | my $output = $EMPTY_STR; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 5 | ▶ | while ( my $token = $parser->get_token ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 116 | ▶ | if ( $token->is_start_tag ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 44 | 33 | my $tag = $token->get_tag; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 33 | ▶ | if ( any { $tag eq $_ } @preserve_tags ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 7 | $in_pre = 1; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 33 | $output .= $indent x $count; | |||||||||||||||||||||||||||
| 51 | 33 | $output .= $token->as_is; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 33 | ▶ | if ( !defined $token->get_attrseq->[-1] | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $token->get_attrseq->[-1] or $token->get_attrseq->[-1] ne "/"
MC/DC100%2/2
not defined $token->get_attrseq->[-1] or $token->get_attrseq->[-1] ne "/"
not defined $token->get_attrseq->[-1]
$token->get_attrseq->[-1] ne "/"
Truth table100%3/3
not(A) or B
A= not defined $token->get_attrseq->[-1]B= $token->get_attrseq->[-1] ne "/"
| |||||||||||||||||||||||||||||
| 54 | || $token->get_attrseq->[-1] ne "/" ) | ||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||
| 56 | 28 | $count++; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | elsif ( $token->is_end_tag ) { | ||||||||||||||||||||||||||||
| 60 | 28 | my $tag = $token->get_tag; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 28 | $count--; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 28 | ▶ | if ( $output =~ m/ > \s* \z /x && !$in_pre ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$output =~ / > \s* \z /x and not $in_pre
MC/DC100%2/2
$output =~ / > \s* \z /x and not $in_pre
$output =~ / > \s* \z /x
not $in_pre
Truth table100%3/3
A and not(B)
A= $output =~ / > \s* \z /xB= not $in_pre
| |||||||||||||||||||||||||||||
| 65 | 15 | $output .= "\n" . $indent x $count; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 28 | ▶ | if ( any { $tag eq $_ } @preserve_tags ) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 7 | $in_pre = 0; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 28 | $output .= $token->as_is; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | elsif ( $token->is_text ) { | ||||||||||||||||||||||||||||
| 75 | 55 | my $text = $token->as_is; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 55 | ▶ | if ( length $parser->peek && !$in_pre ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $parser->peek and not $in_pre
MC/DC100%2/2
length $parser->peek and not $in_pre
length $parser->peek
not $in_pre
Truth table100%3/3
A and not(B)
A= length $parser->peekB= not $in_pre
| |||||||||||||||||||||||||||||
| 78 | 49 | $text =~ s/\A\s+/ /; | |||||||||||||||||||||||||||
| 79 | 49 | $text =~ s/\s+\z/ /; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 55 | ▶ | if ( $text eq $SPACE && $parser->peek =~ m/ < /x ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$text eq $HTML::FormFu::OutputProcessor::Indent::SPACE and $parser->peek =~ / < /x
MC/DC50%1/2
$text eq $HTML::FormFu::OutputProcessor::Indent::SPACE and $parser->peek =~ / < /x
$text eq $HTML::FormFu::OutputProcessor::Indent::SPACE
$parser->peek =~ / < /x
Truth table66%2/3
A and B
A= $text eq $HTML::FormFu::OutputProcessor::Indent::SPACEB= $parser->peek =~ / < /x
| |||||||||||||||||||||||||||||
| 83 | 43 | $text = $EMPTY_STR; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 55 | $output .= $text; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||||||||
| 89 | 0 | $output .= $token->as_is; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 116 | ▶ | if ( $parser->peek =~ m{ < (?!/) }x && !$in_pre ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$parser->peek =~ m[ < (?!/) ]x and not $in_pre
MC/DC50%1/2
$parser->peek =~ m[ < (?!/) ]x and not $in_pre
$parser->peek =~ m[ < (?!/) ]x
not $in_pre
Truth table66%2/3
A and not(B)
A= $parser->peek =~ m[ < (?!/) ]xB= not $in_pre
| |||||||||||||||||||||||||||||
| 93 | 28 | $output .= "\n"; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 5 | return $output; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 5 | 1; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | __END__ | ||||||||||||||||||||||||||||