line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Hazy; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
338156
|
use strict; |
|
6
|
|
|
|
|
49
|
|
|
6
|
|
|
|
|
129
|
|
4
|
6
|
|
|
6
|
|
24
|
use warnings; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
113
|
|
5
|
6
|
|
|
6
|
|
99
|
use 5.012; |
|
6
|
|
|
|
|
25
|
|
6
|
6
|
|
|
6
|
|
29
|
use Cwd qw/abs_path/; |
|
6
|
|
|
|
|
6
|
|
|
6
|
|
|
|
|
6314
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
6
|
|
|
6
|
0
|
5134
|
my ( $pkg, @new ) = @_; |
11
|
6
|
50
|
|
|
|
26
|
my %args = scalar @new == 1 ? @{ shift @new } : @new; |
|
0
|
|
|
|
|
0
|
|
12
|
6
|
|
100
|
|
|
33
|
$args{file_name} //= 'test'; |
13
|
6
|
|
100
|
|
|
21
|
$args{find} //= 'css'; |
14
|
6
|
|
|
|
|
163
|
my $path = abs_path( [caller()]->[1] ); |
15
|
6
|
|
|
|
|
40
|
$args{abs_path} = substr($path, 0, rindex($path, '/')); |
16
|
6
|
100
|
|
|
|
16
|
if ($args{write_dir}) { |
17
|
1
|
|
|
|
|
4
|
$args{write_dir} = sprintf "%s/%s", $args{abs_path}, $args{write_dir}; |
18
|
1
|
50
|
|
|
|
17
|
unless(-d $args{write_dir}) { |
19
|
1
|
|
|
|
|
3
|
my $dir = ''; |
20
|
|
|
|
|
|
|
map { |
21
|
8
|
100
|
|
|
|
155
|
(-e ($dir .= "/$_")) or mkdir $dir; |
22
|
1
|
|
|
|
|
5
|
} (split /\//, $args{write_dir}); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
6
|
|
|
|
|
44
|
bless {%args}, $pkg; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub process { |
29
|
1
|
|
50
|
1
|
0
|
11
|
$_[1] //= $_[0]->{read_dir} // die 'No read_dir provided'; |
|
|
|
33
|
|
|
|
|
30
|
1
|
|
|
|
|
5
|
$_[1] = sprintf "%s/%s", $_[0]->{abs_path}, $_[1]; |
31
|
1
|
|
|
|
|
3
|
my ( $spec, @files ) = $_[0]->lookup_dir( $_[1] ); |
32
|
1
|
|
|
|
|
2
|
my $build_css; |
33
|
1
|
|
|
|
|
3
|
for my $css_file (@files) { |
34
|
2
|
50
|
|
|
|
63
|
open my $fh, "<$css_file" or die "Cannot open $css_file"; |
35
|
2
|
|
|
|
|
5
|
my $css = do { local $/; <$fh> }; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
41
|
|
36
|
2
|
|
|
|
|
11
|
$css = $_[0]->make_replacements( $spec, $css ); |
37
|
2
|
|
|
|
|
20
|
$build_css .= $css; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
my $write = exists $_[0]->{write_dir} |
40
|
|
|
|
|
|
|
? sprintf "%s/%s", $_[0]->{write_dir}, $_[0]->{file_name} |
41
|
1
|
50
|
|
|
|
9
|
: $_[0]->{file_name}; |
42
|
1
|
|
|
|
|
4
|
write_file( "$write.css", $build_css ); |
43
|
1
|
|
|
|
|
7
|
write_file( "$write.min.css", $_[0]->min_css($build_css) ); |
44
|
1
|
|
|
|
|
6
|
return 1; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub write_file { |
48
|
2
|
50
|
|
2
|
0
|
100
|
open( my $fh, '>', $_[0] ) or die "could not open file $_[0]"; |
49
|
2
|
|
|
|
|
18
|
print $fh $_[1]; |
50
|
2
|
|
|
|
|
51
|
close $fh; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub make_replacements { |
54
|
5
|
|
|
5
|
0
|
2140
|
my $regx = join "|", map { quotemeta($_) } keys %{ $_[1] }; |
|
12
|
|
|
|
|
25
|
|
|
5
|
|
|
|
|
16
|
|
55
|
5
|
50
|
|
|
|
14
|
return $_[2] unless $regx; |
56
|
5
|
|
|
|
|
140
|
$_[2] =~ s/($regx)/$_[1]->{$1}/g; |
57
|
5
|
50
|
|
|
|
22
|
( !$_[2] =~ m/\n$/ ) and $_[2] .= "\n"; |
58
|
5
|
|
|
|
|
18
|
return $_[2]; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub lookup_dir { |
62
|
4
|
|
|
4
|
0
|
16
|
my $look = $_[0]->{find}; |
63
|
4
|
50
|
|
|
|
105
|
opendir( my $dh, $_[1] ) or die "Could not open dir - $_[1]"; |
64
|
22
|
|
|
|
|
61
|
my %files = map { $_ => sprintf "%s/%s", $_[1], $_ } |
65
|
4
|
|
|
|
|
90
|
grep { /config|\.$look$/ } readdir $dh; |
|
30
|
|
|
|
|
232
|
|
66
|
4
|
|
|
|
|
48
|
closedir($dh); |
67
|
4
|
50
|
|
|
|
16
|
my $spec = delete $files{config} or die 'no config found'; |
68
|
4
|
|
|
|
|
31
|
return ( _read_spec($spec), sort values %files ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub min_css { |
72
|
4
|
|
|
4
|
0
|
2029
|
$_[1] =~ s/[\s]{2,}|[\t\r\n]+//g; |
73
|
4
|
|
|
|
|
26
|
my %minify = (' {', '{', '{ ', '{', ' }', '}', '} ', '}', ': ', |
74
|
|
|
|
|
|
|
':', ';}', '}', ' ,', ',', ', ', ',', '( ', '(', ' )', ')' ); |
75
|
4
|
|
|
|
|
22
|
my $regx = join "|", map { quotemeta($_) } sort keys %minify; |
|
40
|
|
|
|
|
53
|
|
76
|
4
|
|
|
|
|
151
|
$_[1] =~ s/($regx)/$minify{$1}/g; |
77
|
4
|
|
|
|
|
26
|
$_[1]; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _read_spec { |
81
|
9
|
|
|
9
|
|
1157
|
my ( %spec, %arg ); |
82
|
9
|
|
|
|
|
257
|
open( my $fh, "<$_[0]" ); |
83
|
9
|
|
|
|
|
36
|
$arg{end} = ';'; |
84
|
9
|
|
|
|
|
69
|
while ( sysread( $fh, $arg{buffer}, 1 ) ) { |
85
|
235
|
100
|
100
|
|
|
767
|
if ( ! exists $arg{value} && $arg{buffer} =~ m/\s/ ) { next } |
|
30
|
|
|
|
|
206
|
|
86
|
205
|
100
|
66
|
|
|
458
|
if ( !$arg{flag} && !$arg{multi} && $arg{buffer} eq ':' ) { $arg{flag} = 1; next; } |
|
15
|
|
100
|
|
|
20
|
|
|
15
|
|
|
|
|
84
|
|
87
|
190
|
100
|
|
|
|
244
|
if ($arg{buffer} eq $arg{end}) { |
88
|
15
|
|
|
|
|
21
|
map { $arg{$_} =~ s/^\s+|\s+$// } qw/key value/; |
|
30
|
|
|
|
|
111
|
|
89
|
15
|
|
|
|
|
32
|
$spec{"$arg{key}"} = $arg{value}; |
90
|
15
|
|
|
|
|
27
|
map { delete $arg{$_} } qw/key value flag multi/; |
|
60
|
|
|
|
|
73
|
|
91
|
15
|
|
|
|
|
16
|
$arg{end} = ';'; |
92
|
15
|
|
|
|
|
89
|
next; |
93
|
|
|
|
|
|
|
} |
94
|
175
|
100
|
100
|
|
|
347
|
if ( exists $arg{flag} && ! exists $arg{value} ) { |
95
|
16
|
50
|
|
|
|
26
|
next if ($arg{buffer} =~ m/\s/); |
96
|
16
|
100
|
|
|
|
25
|
if ($arg{buffer} =~ m/[\@\$\^\&\*\{\/\\\~\`\>\<\+\_\]\[\?\|\"\'\=\!]/ ) { |
97
|
1
|
|
|
|
|
2
|
$arg{multi} = 1; |
98
|
1
|
|
|
|
|
2
|
$arg{end} = $arg{buffer}; |
99
|
1
|
|
|
|
|
6
|
next; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
174
|
100
|
|
|
|
1042
|
exists $arg{flag} ? ( $arg{value} .= $arg{buffer} ) : ( $arg{key} .= $arg{buffer} ); |
103
|
|
|
|
|
|
|
} |
104
|
9
|
|
|
|
|
65
|
close($fh); |
105
|
9
|
|
|
|
|
79
|
return \%spec; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |