| 1 | package CSS::Watcher::ParserLess; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | |||||||||||||||||||
| 6 | 1 | ▶ | use Path::Tiny; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 7 | 1 | ▶ | use File::Which; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 1 | ▶ | use IPC::Run3; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | 1 | ▶ | use Log::Log4perl qw(:easy); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | 1 | ▶ | use CSS::Watcher::Parser; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | 5 | ▶ | sub new { | ||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 14 | 5 | my $class = shift; | |||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | 5 | return bless ({}, $class); | |||||||||||||||||
| 17 | } | ||||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | 0 | ▶ | sub parse_less { | ||||||||||||||||
|
Subroutine
parse_less: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||
| 20 | 0 | my $self = shift; | |||||||||||||||||
| 21 | 0 | my $filename = shift; | |||||||||||||||||
| 22 | |||||||||||||||||||
| 23 | 0 | my $cmd = [ $self->executable, | |||||||||||||||||
| 24 | '--no-color', | ||||||||||||||||||
| 25 | $filename | ||||||||||||||||||
| 26 | ]; | ||||||||||||||||||
| 27 | 0 | my $err; | |||||||||||||||||
| 28 | my $out; | ||||||||||||||||||
| 29 | 0 | local ($!, $?) = (0, -1); | |||||||||||||||||
| 30 | 0 | IPC::Run3::run3($cmd, undef, \$out, \$err, {return_if_system_error => 1}); | |||||||||||||||||
| 31 | |||||||||||||||||||
| 32 | 0 | ▶ | if (!$?) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 33 | 0 | $err = ''; | |||||||||||||||||
| 34 | } elsif ($! == 2) { | ||||||||||||||||||
| 35 | 0 | ERROR sprintf "Cannot execute '%s'. See http://lesscss.org/#usage", $cmd->[0]; | |||||||||||||||||
| 36 | } else { | ||||||||||||||||||
| 37 | 0 | DEBUG sprintf "Failed to run \"%s\":\n %s\n%s", join(' ', @$cmd), $err, $out; | |||||||||||||||||
| 38 | 0 | $out = ''; | |||||||||||||||||
| 39 | } | ||||||||||||||||||
| 40 | |||||||||||||||||||
| 41 | 0 | my ($classes, $ids) = ({}, {}); | |||||||||||||||||
| 42 | 0 | ▶ | if ($out ne '') { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 43 | 0 | INFO sprintf '%s: lessc done, parsing generated CSS', path($filename)->basename; | |||||||||||||||||
| 44 | 0 | ($classes, $ids) = CSS::Watcher::Parser->new->parse_css($out); | |||||||||||||||||
| 45 | } | ||||||||||||||||||
| 46 | |||||||||||||||||||
| 47 | # Find dependencies for this less file. | ||||||||||||||||||
| 48 | 0 | my @requiries; | |||||||||||||||||
| 49 | 0 | foreach (path($filename)->lines_utf8()) { | |||||||||||||||||
| 50 | 0 | ▶ | (m/^\s*?\@import\s+"(.*?.less)"/) ? push @requiries, $1 : | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 51 | (m/^\s*?\@import\s+"(.*?.css)"/) ? push @requiries, $1 : | ||||||||||||||||||
| 52 | (m/^\s*?\@import\s+"(.*?)"/) ? push @requiries, $1 . '.less' : 1; | ||||||||||||||||||
| 53 | } | ||||||||||||||||||
| 54 | |||||||||||||||||||
| 55 | 0 | ▶ | INFO sprintf "%s: imports: %s", path($filename)->basename, join(', ', @requiries) if (@requiries); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 56 | |||||||||||||||||||
| 57 | 0 | return ($classes, $ids, \@requiries); | |||||||||||||||||
| 58 | } | ||||||||||||||||||
| 59 | |||||||||||||||||||
| 60 | 0 | ▶ | sub executable { | ||||||||||||||||
|
Subroutine
executable: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||
| 61 | 0 | ▶ | File::Which::which('lessc') || 'lessc' ; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 62 | } | ||||||||||||||||||
| 63 | |||||||||||||||||||
| 64 | 1 | 1; | |||||||||||||||||
| 65 | |||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||