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