lib/HTML/FormFu/OutputProcessor/Indent.pm

filter: Statementstmt 98.3% 61 / 62 Branchbran 95.4% 21 / 22 Conditioncond 86.6% 13 / 15 MC/DCmcdc 80.0% 8 / 10 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 1 totaltotal 94.1% 113 / 120 CC 17 SCAR 24.4
CC
17
Cov
96%
process
17.0
BEGIN
1.0
BEGIN
1.0
CRAP 11.5
« lib/HTML/FormFu/Role/Element/MultiElement.pm ↑ Summary lib/HTML/FormFu/Constraint/AllOrNone.pm »
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
BranchTrueFalseTotal
if (my $token = $parser->get_token) 116 5 121
42  
43 116 ▶ if ( $token->is_start_tag ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token->is_start_tag) { } 33 83 116
elsif ($token->is_end_tag) { } 28 55 83
elsif ($token->is_text) { } 55 0 55
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
BranchTrueFalseTotal
if (&any(sub { $tag eq $_; } , @preserve_tags)) 7 26 33
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
BranchTrueFalseTotal
if (not defined $token->get_attrseq->[-1] or $token->get_attrseq->[-1] ne "/") 28 5 33
Condition100%3/3
not defined $token->get_attrseq->[-1] or $token->get_attrseq->[-1] ne "/"
l!l&&r!l&&!r
15135
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 "/"
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if ($output =~ / > \s* \z /x and not $in_pre) 15 13 28
Condition100%3/3
$output =~ / > \s* \z /x and not $in_pre
!ll&&!rl&&r
10315
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (&any(sub { $tag eq $_; } , @preserve_tags)) 7 21 28
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
BranchTrueFalseTotal
if (length $parser->peek and not $in_pre) 49 6 55
Condition100%3/3
length $parser->peek and not $in_pre
!ll&&!rl&&r
2449
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($text eq $HTML::FormFu::OutputProcessor::Indent::SPACE and $parser->peek =~ / < /x) 43 12 55
Condition66%2/3
$text eq $HTML::FormFu::OutputProcessor::Indent::SPACE and $parser->peek =~ / < /x
!ll&&!rl&&r
12043
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($parser->peek =~ m[ < (?!/) ]x and not $in_pre) 28 88 116
Condition66%2/3
$parser->peek =~ m[ < (?!/) ]x and not $in_pre
!ll&&!rl&&r
88028
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
ABresult
0X0
100
111
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__
« lib/HTML/FormFu/Role/Element/MultiElement.pm ↑ Summary lib/HTML/FormFu/Constraint/AllOrNone.pm »