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 SCAR 28.3
CC
17
Cov
96%
process
17.0
BEGIN
1.0
BEGIN
1.0
CRAP 17.0
« lib/HTML/FormFu/Element/Checkbox.pm ↑ Summary lib/HTML/FormFu/Constraint/AllOrNone.pm »
1 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::OutputProcessor::Indent;
4 3 $HTML::FormFu::OutputProcessor::Indent::VERSION = '2.06';
5 # ABSTRACT: Nicely Indent HTML Output
6  
7 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use MooseX::Attribute::Chained;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 extends 'HTML::FormFu::OutputProcessor';
10  
11 3 ▶use HTML::FormFu::Constants qw( $EMPTY_STR $SPACE );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use HTML::TokeParser::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use List::Util 1.33 qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 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 3 lazy => 1,
26 traits => ['Chained'],
27 );
28  
29 sub process {
30 5 ▶ my ( $self, $input ) = @_;
Subroutine process: called CC=17 SCAR=28.4
Pod undocumented
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 3 __PACKAGE__->meta->make_immutable;
101  
102 3 1;
103  
104 __END__
105  
106 =pod
107  
108 =encoding UTF-8
109  
110 =head1 NAME
111  
112 HTML::FormFu::OutputProcessor::Indent - Nicely Indent HTML Output
113  
114 =head1 VERSION
115  
116 version 2.06
117  
118 =head1 SYNOPSIS
119  
120 ---
121 output_processors:
122 - Indent
123  
124 =head1 METHODS
125  
126 =head2 indent
127  
128 Arguments: $string
129  
130 Default Value: "\t"
131  
132 The string to be used to indent the HTML.
133  
134 =head2 preserve_tags
135  
136 Arguments: \@tags
137  
138 Default Value: ['pre', 'textarea']
139  
140 An arrayref of tag names who's contents should not be processed.
141  
142 =head1 SEE ALSO
143  
144 Is a sub-class of, and inherits methods from L<HTML::FormFu::OutputProcessor>
145  
146 L<HTML::FormFu>
147  
148 =head1 AUTHOR
149  
150 Carl Franks C<cfranks@cpan.org>
151  
152 =head1 LICENSE
153  
154 This library is free software, you can redistribute it and/or modify it under
155 the same terms as Perl itself.
156  
157 =head1 AUTHOR
158  
159 Carl Franks <cpan@fireartist.com>
160  
161 =head1 COPYRIGHT AND LICENSE
162  
163 This software is copyright (c) 2018 by Carl Franks.
164  
165 This is free software; you can redistribute it and/or modify it under
166 the same terms as the Perl 5 programming language system itself.
167  
168 =cut
« lib/HTML/FormFu/Element/Checkbox.pm ↑ Summary lib/HTML/FormFu/Constraint/AllOrNone.pm »