line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CSS::Struct::Output; |
2
|
|
|
|
|
|
|
|
3
|
21
|
|
|
21
|
|
77355
|
use strict; |
|
21
|
|
|
|
|
97
|
|
|
21
|
|
|
|
|
656
|
|
4
|
21
|
|
|
21
|
|
123
|
use warnings; |
|
21
|
|
|
|
|
50
|
|
|
21
|
|
|
|
|
655
|
|
5
|
|
|
|
|
|
|
|
6
|
21
|
|
|
21
|
|
11037
|
use Class::Utils qw(set_params); |
|
21
|
|
|
|
|
664376
|
|
|
21
|
|
|
|
|
429
|
|
7
|
21
|
|
|
21
|
|
1606
|
use Error::Pure qw(err); |
|
21
|
|
|
|
|
43
|
|
|
21
|
|
|
|
|
867
|
|
8
|
21
|
|
|
21
|
|
122
|
use List::MoreUtils qw(none); |
|
21
|
|
|
|
|
38
|
|
|
21
|
|
|
|
|
84
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.04; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Constructor. |
13
|
|
|
|
|
|
|
sub new { |
14
|
39
|
|
|
39
|
1
|
72981
|
my ($class, @params) = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Create object. |
17
|
39
|
|
|
|
|
120
|
my $self = bless {}, $class; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Get default parameters. |
20
|
39
|
|
|
|
|
411
|
$self->_default_parameters; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Process params. |
23
|
39
|
|
|
|
|
207
|
set_params($self, @params); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Check parameters to right values. |
26
|
36
|
|
|
|
|
602
|
$self->_check_params; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Reset. |
29
|
26
|
|
|
|
|
127
|
$self->reset; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Object. |
32
|
26
|
|
|
|
|
189
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Flush CSS structure in object. |
36
|
|
|
|
|
|
|
sub flush { |
37
|
41
|
|
|
41
|
1
|
377
|
my ($self, $reset_flag) = @_; |
38
|
41
|
|
|
|
|
75
|
my $ouf = $self->{'output_handler'}; |
39
|
41
|
|
|
|
|
55
|
my $ret; |
40
|
41
|
100
|
|
|
|
129
|
if (ref $self->{'flush_code'} eq 'ARRAY') { |
41
|
9
|
|
|
|
|
33
|
$ret = join $self->{'output_sep'}, @{$self->{'flush_code'}}; |
|
9
|
|
|
|
|
32
|
|
42
|
|
|
|
|
|
|
} else { |
43
|
32
|
|
|
|
|
67
|
$ret = $self->{'flush_code'}; |
44
|
|
|
|
|
|
|
} |
45
|
41
|
100
|
|
|
|
100
|
if ($ouf) { |
46
|
21
|
|
|
21
|
|
16436
|
no warnings; |
|
21
|
|
|
|
|
44
|
|
|
21
|
|
|
|
|
24191
|
|
47
|
6
|
100
|
|
|
|
12
|
print {$ouf} $ret or err 'Cannot write to output handler.'; |
|
6
|
|
|
|
|
209
|
|
48
|
4
|
|
|
|
|
16
|
undef $ret; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Reset. |
52
|
39
|
100
|
|
|
|
100
|
if ($reset_flag) { |
53
|
2
|
|
|
|
|
8
|
$self->reset; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Return string. |
57
|
39
|
|
|
|
|
112
|
return $ret; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Put CSS structure code. |
61
|
|
|
|
|
|
|
sub put { |
62
|
50
|
|
|
50
|
1
|
15695
|
my ($self, @data) = @_; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# For every data. |
65
|
50
|
|
|
|
|
128
|
foreach my $css_structure_ar (@data) { |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# Bad data. |
68
|
135
|
100
|
|
|
|
334
|
if (ref $css_structure_ar ne 'ARRAY') { |
69
|
2
|
|
|
|
|
10
|
err 'Bad data.'; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Split to type and main CSS structure. |
73
|
133
|
|
|
|
|
191
|
my ($type, @css_struct) = @{$css_structure_ar}; |
|
133
|
|
|
|
|
292
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Attributes. |
76
|
133
|
100
|
|
|
|
611
|
if ($type eq 'a') { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
77
|
2
|
|
|
|
|
10
|
$self->_check_arguments(\@css_struct, 1, 2); |
78
|
2
|
|
|
|
|
8
|
$self->_put_at_rules(@css_struct); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Comment. |
81
|
|
|
|
|
|
|
} elsif ($type eq 'c') { |
82
|
20
|
|
|
|
|
53
|
$self->_put_comment(@css_struct); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Definition. |
85
|
|
|
|
|
|
|
} elsif ($type eq 'd') { |
86
|
24
|
|
|
|
|
71
|
$self->_check_arguments(\@css_struct, 1, 2); |
87
|
24
|
|
|
|
|
68
|
$self->_put_definition(@css_struct); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# End of selector. |
90
|
|
|
|
|
|
|
} elsif ($type eq 'e') { |
91
|
35
|
|
|
|
|
101
|
$self->_check_arguments(\@css_struct, 0, 0); |
92
|
35
|
|
|
|
|
93
|
$self->_put_end_of_selector; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Instruction. |
95
|
|
|
|
|
|
|
} elsif ($type eq 'i') { |
96
|
3
|
|
|
|
|
15
|
$self->_check_arguments(\@css_struct, 1, 2); |
97
|
3
|
|
|
|
|
11
|
$self->_put_instruction(@css_struct); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Raw data. |
100
|
|
|
|
|
|
|
} elsif ($type eq 'r') { |
101
|
2
|
|
|
|
|
20
|
$self->_put_raw(@css_struct); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Selector. |
104
|
|
|
|
|
|
|
} elsif ($type eq 's') { |
105
|
43
|
|
|
|
|
152
|
$self->_check_arguments(\@css_struct, 1, 1); |
106
|
39
|
|
|
|
|
117
|
$self->_put_selector(@css_struct); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# Other. |
109
|
|
|
|
|
|
|
} else { |
110
|
4
|
100
|
|
|
|
68
|
if (! $self->{'skip_bad_types'}) { |
111
|
2
|
|
|
|
|
7
|
err 'Bad type of data.', 'type', $type; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Auto-flush. |
117
|
41
|
100
|
|
|
|
116
|
if ($self->{'auto_flush'}) { |
118
|
2
|
|
|
|
|
8
|
$self->flush; |
119
|
2
|
|
|
|
|
10
|
$self->_reset_flush_code; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
41
|
|
|
|
|
108
|
return; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Resets internal variables. |
127
|
|
|
|
|
|
|
sub reset { |
128
|
46
|
|
|
46
|
1
|
1377
|
my $self = shift; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Tmp code. |
131
|
46
|
|
|
|
|
127
|
$self->{'tmp_code'} = []; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# Flush code. |
134
|
46
|
|
|
|
|
154
|
$self->_reset_flush_code; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# Open selector flag. |
137
|
46
|
|
|
|
|
86
|
$self->{'open_selector'} = 0; |
138
|
|
|
|
|
|
|
|
139
|
46
|
|
|
|
|
81
|
return; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# Check arguments. |
143
|
|
|
|
|
|
|
sub _check_arguments { |
144
|
107
|
|
|
107
|
|
220
|
my ($self, $css_structure_ar, $min_arg_num, $max_arg_num) = @_; |
145
|
107
|
|
|
|
|
134
|
my $arg_num = scalar @{$css_structure_ar}; |
|
107
|
|
|
|
|
181
|
|
146
|
107
|
100
|
100
|
|
|
419
|
if ($arg_num < $min_arg_num || $arg_num > $max_arg_num) { |
147
|
|
|
|
|
|
|
err 'Bad number of arguments.', |
148
|
|
|
|
|
|
|
'\'CSS::Struct\' structure', |
149
|
4
|
|
|
|
|
8
|
join ', ', @{$css_structure_ar}; |
|
4
|
|
|
|
|
16
|
|
150
|
|
|
|
|
|
|
} |
151
|
103
|
|
|
|
|
169
|
return; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# Check to opened selector. |
155
|
|
|
|
|
|
|
sub _check_opened_selector { |
156
|
43
|
|
|
43
|
|
60
|
my $self = shift; |
157
|
43
|
100
|
|
|
|
106
|
if (! $self->{'open_selector'}) { |
158
|
1
|
|
|
|
|
7
|
err 'No opened selector.'; |
159
|
|
|
|
|
|
|
} |
160
|
42
|
|
|
|
|
72
|
return; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# Default parameters. |
164
|
|
|
|
|
|
|
sub _default_parameters { |
165
|
39
|
|
|
39
|
|
89
|
my $self = shift; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# Auto flush flag. |
168
|
39
|
|
|
|
|
153
|
$self->{'auto_flush'} = 0; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
# CSS comment delimeters. |
171
|
39
|
|
|
|
|
129
|
$self->{'comment_delimeters'} = [q{/*}, q{*/}]; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# Set output handler. |
174
|
39
|
|
|
|
|
94
|
$self->{'output_handler'} = undef; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# Output separator. |
177
|
39
|
|
|
|
|
85
|
$self->{'output_sep'} = "\n"; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# Skip bad 'CSS::Struct' types. |
180
|
39
|
|
|
|
|
100
|
$self->{'skip_bad_types'} = 0; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# Skip comments. |
183
|
39
|
|
|
|
|
82
|
$self->{'skip_comments'} = 0; |
184
|
|
|
|
|
|
|
|
185
|
39
|
|
|
|
|
71
|
return; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# Check parameters to rigth values. |
189
|
|
|
|
|
|
|
sub _check_params { |
190
|
36
|
|
|
36
|
|
67
|
my $self = shift; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# Check to output handler. |
193
|
36
|
100
|
100
|
|
|
199
|
if (defined $self->{'output_handler'} |
194
|
|
|
|
|
|
|
&& ref $self->{'output_handler'} ne 'GLOB') { |
195
|
|
|
|
|
|
|
|
196
|
2
|
|
|
|
|
10
|
err 'Output handler is bad file handler.'; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
# Check auto-flush only with output handler. |
199
|
34
|
100
|
100
|
|
|
161
|
if ($self->{'auto_flush'} && ! defined $self->{'output_handler'}) { |
200
|
2
|
|
|
|
|
9
|
err 'Auto-flush can\'t use without output handler.'; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# Check to comment delimeters. |
204
|
32
|
100
|
100
|
|
|
365
|
if (ref $self->{'comment_delimeters'} ne 'ARRAY' |
|
|
|
100
|
|
|
|
|
205
|
32
|
|
|
32
|
|
335
|
|| (none { $_ eq $self->{'comment_delimeters'}->[0] } |
206
|
|
|
|
|
|
|
(q{/*}, ''))) { |
209
|
|
|
|
|
|
|
|
210
|
6
|
|
|
|
|
18
|
err 'Bad comment delimeters.'; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
26
|
|
|
|
|
119
|
return; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
# At-rules. |
217
|
|
|
|
|
|
|
sub _put_at_rules { |
218
|
1
|
|
|
1
|
|
4
|
my ($self, $at_rule, $file) = @_; |
219
|
1
|
|
|
|
|
2
|
push @{$self->{'flush_code'}}, 'At-rule'; |
|
1
|
|
|
|
|
3
|
|
220
|
1
|
|
|
|
|
15
|
return; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
# Comment. |
224
|
|
|
|
|
|
|
sub _put_comment { |
225
|
1
|
|
|
1
|
|
3
|
my ($self, @comments) = @_; |
226
|
1
|
|
|
|
|
3
|
push @{$self->{'flush_code'}}, 'Comment'; |
|
1
|
|
|
|
|
2
|
|
227
|
1
|
|
|
|
|
3
|
return; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# Definition. |
231
|
|
|
|
|
|
|
sub _put_definition { |
232
|
8
|
|
|
8
|
|
29
|
my ($self, $key, $value) = @_; |
233
|
8
|
|
|
|
|
13
|
push @{$self->{'flush_code'}}, 'Definition'; |
|
8
|
|
|
|
|
17
|
|
234
|
8
|
|
|
|
|
15
|
return; |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# End of selector. |
238
|
|
|
|
|
|
|
sub _put_end_of_selector { |
239
|
8
|
|
|
8
|
|
23
|
my $self = shift; |
240
|
8
|
|
|
|
|
21
|
push @{$self->{'flush_code'}}, 'End of selector'; |
|
8
|
|
|
|
|
18
|
|
241
|
8
|
|
|
|
|
19
|
return; |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
# Instruction. |
245
|
|
|
|
|
|
|
sub _put_instruction { |
246
|
1
|
|
|
1
|
|
2
|
my ($self, $target, $code) = @_; |
247
|
1
|
|
|
|
|
3
|
push @{$self->{'flush_code'}}, 'Instruction'; |
|
1
|
|
|
|
|
2
|
|
248
|
1
|
|
|
|
|
2
|
return; |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
# Raw data. |
252
|
|
|
|
|
|
|
sub _put_raw { |
253
|
1
|
|
|
1
|
|
4
|
my ($self, @raw_data) = @_; |
254
|
1
|
|
|
|
|
2
|
push @{$self->{'flush_code'}}, 'Raw data'; |
|
1
|
|
|
|
|
15
|
|
255
|
1
|
|
|
|
|
5
|
return; |
256
|
|
|
|
|
|
|
} |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
# Selectors. |
259
|
|
|
|
|
|
|
sub _put_selector { |
260
|
8
|
|
|
8
|
|
19
|
my ($self, $selector) = @_; |
261
|
8
|
|
|
|
|
13
|
push @{$self->{'flush_code'}}, 'Selector'; |
|
8
|
|
|
|
|
22
|
|
262
|
8
|
|
|
|
|
20
|
return; |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
# Reset flush code. |
266
|
|
|
|
|
|
|
sub _reset_flush_code { |
267
|
12
|
|
|
12
|
|
22
|
my $self = shift; |
268
|
12
|
|
|
|
|
32
|
$self->{'flush_code'} = []; |
269
|
12
|
|
|
|
|
18
|
return; |
270
|
|
|
|
|
|
|
} |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
1; |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
__END__ |