blib/lib/CSS/Struct/Output/Indent.pm

filter: Statementstmt 100% 110 / 110 Branchbran 100% 14 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 16 / 16 Podpod 100% 1 / 1 totaltotal 100% 146 / 146 CC 10 SCAR 11.0
CC
10
Cov
100%
_flush_tmp
6.0
_put_comment
5.0
BEGIN
1.0
CRAP 3.0
↑ Summary
1 package CSS::Struct::Output::Indent;
2  
3 14 ▶use base qw(CSS::Struct::Output);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 14 ▶use Indent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Constants.
11 14 Readonly::Scalar my $EMPTY_STR => q{};
12 14 Readonly::Scalar my $SPACE => q{ };
13  
14 14 our $VERSION = 0.01;
15  
16 # Resets internal variables.
17 sub reset {
18 38 ▶ my $self = shift;
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
19  
20 # Reset internal variables from *::Core.
21 38 $self->SUPER::reset;
22  
23 # Comment after selector.
24 38 $self->{'comment_after_selector'} = 0;
25  
26 # Indent object.
27 $self->{'indent'} = Indent->new(
28 38 'next_indent' => $self->{'next_indent'},
29 );
30  
31 # Any processed selector.
32 38 $self->{'processed'} = 0;
33  
34 38 return;
35 }
36  
37 # Default parameters.
38 sub _default_parameters {
39 23 ▶ my $self = shift;
Subroutine _default_parameters: called CC=1 SCAR=0.0
40  
41 # Default parameters from SUPER.
42 23 $self->SUPER::_default_parameters;
43  
44 # Indent string.
45 23 $self->{'next_indent'} = "\t";
46  
47 23 return;
48 }
49  
50 # Flush $self->{'tmp_code'}.
51 sub _flush_tmp {
52 49 ▶ my $self = shift;
Subroutine _flush_tmp: called CC=6 SCAR=17.9
53 49 ▶ if (@{$self->{'tmp_code'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"tmp_code"};}) 29 20 49
54 29 $self->{'indent'}->add;
55 29 my @comment;
56 29 ▶ if ($self->{'comment_after_selector'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'comment_after_selector'}) { } 2 27 29
57 2 @comment = splice @{$self->{'tmp_code'}},
58 2 -$self->{'comment_after_selector'};
59 2 pop @comment;
60 2 foreach my $com (@comment) {
61 10 ▶ if ($com ne $EMPTY_STR && $com ne "\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($com ne $EMPTY_STR and $com ne "\n") 3 7 10
Condition100%3/3
$com ne $EMPTY_STR and $com ne "\n"
!ll&&!rl&&r
253
MC/DC100%2/2
$com ne $EMPTY_STR and $com ne "\n"
$com ne $EMPTY_STR $com ne "\n"
Truth table100%3/3
A and B
A= $com ne $EMPTY_STRB= $com ne "\n"
ABresult
0X0
100
111
62 3 $com = $self->{'indent'}->get.$com;
63 }
64 }
65 } else {
66 27 pop @{$self->{'tmp_code'}};
67 }
68 29 pop @{$self->{'tmp_code'}};
69 29 push @{$self->{'flush_code'}},
70 29 (join $EMPTY_STR, @{$self->{'tmp_code'}}).' {'.
71 (join $EMPTY_STR, @comment);
72 29 $self->{'tmp_code'} = [];
73 29 $self->{'processed'} = 1;
74 }
75 49 return;
76 }
77  
78 # At-rules.
79 sub _put_at_rules {
80 1 ▶ my ($self, $at_rule, $file) = @_;
Subroutine _put_at_rules: called CC=1 SCAR=0.0
81 1 push @{$self->{'flush_code'}}, $at_rule.' "'.$file.'";';
82 1 $self->{'processed'} = 1;
83 1 return;
84 }
85  
86 # Comment.
87 sub _put_comment {
88 26 ▶ my ($self, @comments) = @_;
Subroutine _put_comment: called CC=5 SCAR=16.1
89 26 ▶ if (! $self->{'skip_comments'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"skip_comments"}) 13 13 26
90 13 push @comments, $SPACE.$self->{'comment_delimeters'}->[1];
91 13 unshift @comments, $self->{'comment_delimeters'}->[0].$SPACE;
92 13 ▶ if ($self->{'processed'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"processed"}) 3 10 13
93 3 push @{$self->{'flush_code'}}, $EMPTY_STR;
94 }
95 13 my $comment = (join $EMPTY_STR, @comments);
96 13 ▶ if (@{$self->{'tmp_code'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'tmp_code'};}) { } 4 9 13
97 4 my $sep = $EMPTY_STR;
98 4 ▶ if ($self->{'comment_after_selector'} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"comment_after_selector"} == 0) 3 1 4
99 3 $sep = $self->{'output_sep'};
100 3 pop @{$self->{'tmp_code'}};
101 }
102 4 push @{$self->{'tmp_code'}}, ($sep) x 2, $comment,
103 4 $self->{'output_sep'};
104 4 $self->{'comment_after_selector'} += 4;
105 } else {
106 9 push @{$self->{'flush_code'}},
107 9 $self->{'indent'}->get.$comment;
108 }
109 13 $self->{'processed'} = 0;
110 }
111 26 return;
112 }
113  
114 # Definition.
115 sub _put_definition {
116 20 ▶ my ($self, $key, $value) = @_;
Subroutine _put_definition: called CC=1 SCAR=0.0
117 20 $self->_check_opened_selector;
118 20 $self->_flush_tmp;
119 20 push @{$self->{'flush_code'}}, $self->{'indent'}->get.$key.':'.
120 $SPACE.$value.';';
121 20 $self->{'processed'} = 1;
122 20 return;
123 }
124  
125 # End of selector.
126 sub _put_end_of_selector {
127 30 ▶ my $self = shift;
Subroutine _put_end_of_selector: called CC=1 SCAR=0.0
128 30 $self->_check_opened_selector;
129 29 $self->_flush_tmp;
130 29 $self->{'indent'}->remove;
131 29 push @{$self->{'flush_code'}}, '}';
132 29 $self->{'open_selector'} = 0;
133 29 $self->{'processed'} = 1;
134 29 return;
135 }
136  
137 # Instruction.
138 sub _put_instruction {
139 2 ▶ my ($self, $target, $code) = @_;
Subroutine _put_instruction: called CC=1 SCAR=0.0
140 2 $self->_put_comment($target, $code);
141 2 return;
142 }
143  
144 # Raw data.
145 sub _put_raw {
146 1 ▶ my ($self, @raw_data) = @_;
Subroutine _put_raw: called CC=1 SCAR=0.0
147  
148 # To flush code.
149 1 push @{$self->{'flush_code'}}, (join $EMPTY_STR, @raw_data);
150  
151 1 return;
152 }
153  
154 # Selectors.
155 sub _put_selector {
156 34 ▶ my ($self, $selector) = @_;
Subroutine _put_selector: called CC=1 SCAR=0.0
157 34 push @{$self->{'tmp_code'}}, $selector, ',', ' ';
158 34 $self->{'comment_after_selector'} = 0;
159 34 $self->{'open_selector'} = 1;
160 34 return;
161 }
162  
163 # Reset flush code.
164 sub _reset_flush_code {
165 39 ▶ my $self = shift;
Subroutine _reset_flush_code: called CC=1 SCAR=0.0
166 39 $self->{'flush_code'} = [];
167 39 return;
168 }
169  
170 14 1;
171  
172 __END__
↑ Summary