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