| 1 | # Copyright (c) 2013-2014 David Caldwell. | ||||||||||||||||||||||||||||
| 2 | # Copyright (c) 2014-2017 Marcel Greter. | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||||||||||||||||||||||||
| 5 | # of this software and associated documentation files (the "Software"), to deal | ||||||||||||||||||||||||||||
| 6 | # in the Software without restriction, including without limitation the rights | ||||||||||||||||||||||||||||
| 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||||||||||||||||||||||||||
| 8 | # copies of the Software, and to permit persons to whom the Software is | ||||||||||||||||||||||||||||
| 9 | # furnished to do so, subject to the following conditions: | ||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||
| 11 | # The above copyright notice and this permission notice shall be included in | ||||||||||||||||||||||||||||
| 12 | # all copies or substantial portions of the Software. | ||||||||||||||||||||||||||||
| 13 | # | ||||||||||||||||||||||||||||
| 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||||||||||||||||||||||||||
| 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||||||||||||||||||||||||||
| 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||||||||||||||||||||||||||
| 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||||||||||||||||||||||||||
| 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||||||||||||||||||||||||||
| 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||||||||||||||||||||||||||
| 20 | # THE SOFTWARE. | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | package CSS::Sass; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | require Exporter; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | our @ISA = qw(Exporter); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | our @EXPORT_OK = qw( | ||||||||||||||||||||||||||||
| 33 | quote | ||||||||||||||||||||||||||||
| 34 | unquote | ||||||||||||||||||||||||||||
| 35 | auto_quote | ||||||||||||||||||||||||||||
| 36 | need_quotes | ||||||||||||||||||||||||||||
| 37 | resolve_file | ||||||||||||||||||||||||||||
| 38 | sass2scss | ||||||||||||||||||||||||||||
| 39 | import_sv | ||||||||||||||||||||||||||||
| 40 | sass_compile | ||||||||||||||||||||||||||||
| 41 | sass_compile_file | ||||||||||||||||||||||||||||
| 42 | libsass_version | ||||||||||||||||||||||||||||
| 43 | sass2scss_version | ||||||||||||||||||||||||||||
| 44 | sass_operation | ||||||||||||||||||||||||||||
| 45 | sass_stringify | ||||||||||||||||||||||||||||
| 46 | SASS_COMMA | ||||||||||||||||||||||||||||
| 47 | SASS_SPACE | ||||||||||||||||||||||||||||
| 48 | SASS_ERROR | ||||||||||||||||||||||||||||
| 49 | SASS_NULL | ||||||||||||||||||||||||||||
| 50 | SASS_BOOLEAN | ||||||||||||||||||||||||||||
| 51 | SASS_NUMBER | ||||||||||||||||||||||||||||
| 52 | SASS_STRING | ||||||||||||||||||||||||||||
| 53 | SASS_COLOR | ||||||||||||||||||||||||||||
| 54 | SASS_LIST | ||||||||||||||||||||||||||||
| 55 | SASS_MAP | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | our @EXPORT = qw( | ||||||||||||||||||||||||||||
| 59 | SASS_STYLE_NESTED | ||||||||||||||||||||||||||||
| 60 | SASS_STYLE_EXPANDED | ||||||||||||||||||||||||||||
| 61 | SASS_STYLE_COMPACT | ||||||||||||||||||||||||||||
| 62 | SASS_STYLE_COMPRESSED | ||||||||||||||||||||||||||||
| 63 | SASS2SCSS_PRETTIFY_0 | ||||||||||||||||||||||||||||
| 64 | SASS2SCSS_PRETTIFY_1 | ||||||||||||||||||||||||||||
| 65 | SASS2SCSS_PRETTIFY_2 | ||||||||||||||||||||||||||||
| 66 | SASS2SCSS_PRETTIFY_3 | ||||||||||||||||||||||||||||
| 67 | SASS2SCSS_KEEP_COMMENT | ||||||||||||||||||||||||||||
| 68 | SASS2SCSS_STRIP_COMMENT | ||||||||||||||||||||||||||||
| 69 | SASS2SCSS_CONVERT_COMMENT | ||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | our $VERSION = "3.6.4"; | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | require XSLoader; | ||||||||||||||||||||||||||||
| 75 | XSLoader::load('CSS::Sass', $VERSION); | ||||||||||||||||||||||||||||
| 76 | 12 | ▶ | use CSS::Sass::Plugins qw(@ppaths); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | require CSS::Sass::Value; | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | sub new | ||||||||||||||||||||||||||||
| 80 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||
| 81 | 1 | my ($class, %options) = @_; | |||||||||||||||||||||||||||
| 82 | # Ensure initial sub structures on options | ||||||||||||||||||||||||||||
| 83 | 1 | ▶ | $options{plugin_paths} = [] unless exists $options{plugin_paths}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 1 | ▶ | $options{include_paths} = [] unless exists $options{include_paths}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 1 | ▶ | $options{sass_functions} = {} unless exists $options{sass_functions}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | # Create and return new object with options | ||||||||||||||||||||||||||||
| 87 | 1 | bless { options => \%options }, $class; | |||||||||||||||||||||||||||
| 88 | }; | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | sub options | ||||||||||||||||||||||||||||
| 91 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 92 | shift->{options} | ||||||||||||||||||||||||||||
| 93 | 0 | } | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | sub last_error | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
last_error: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 97 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 98 | $self->{last_error} | ||||||||||||||||||||||||||||
| 99 | 0 | } | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | my @path_types = ( | ||||||||||||||||||||||||||||
| 102 | 'plugin_paths', | ||||||||||||||||||||||||||||
| 103 | 'include_paths' | ||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | # directory delimiter according to platform | ||||||||||||||||||||||||||||
| 107 | my $dir_delim = $^O eq 'MSWin32' ? ';' : ':'; | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | # normalize option hash | ||||||||||||||||||||||||||||
| 110 | my $normalize_options = sub | ||||||||||||||||||||||||||||
| 111 | { | ||||||||||||||||||||||||||||
| 112 | my ($options) = @_; | ||||||||||||||||||||||||||||
| 113 | # gather all functions | ||||||||||||||||||||||||||||
| 114 | # they need to be hashes | ||||||||||||||||||||||||||||
| 115 | my %functions = | ||||||||||||||||||||||||||||
| 116 | ( | ||||||||||||||||||||||||||||
| 117 | %{$options->{'functions'} || {}}, | ||||||||||||||||||||||||||||
| 118 | %{$options->{'sass_functions'} || {}} | ||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||
| 120 | # create functions array | ||||||||||||||||||||||||||||
| 121 | # help the c code a little | ||||||||||||||||||||||||||||
| 122 | my @functions = map { [ | ||||||||||||||||||||||||||||
| 123 | $_, $functions{$_} | ||||||||||||||||||||||||||||
| 124 | ] } keys %functions; | ||||||||||||||||||||||||||||
| 125 | # gather all importers | ||||||||||||||||||||||||||||
| 126 | # they need to be arrays | ||||||||||||||||||||||||||||
| 127 | my @importers = | ||||||||||||||||||||||||||||
| 128 | map { | ||||||||||||||||||||||||||||
| 129 | ref($_) eq "ARRAY" ? | ||||||||||||||||||||||||||||
| 130 | $_ : [ $_, 0 ]; | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | grep { defined } | ||||||||||||||||||||||||||||
| 133 | ( | ||||||||||||||||||||||||||||
| 134 | $options->{'importer'}, | ||||||||||||||||||||||||||||
| 135 | @{$options->{'importers'} || []}, | ||||||||||||||||||||||||||||
| 136 | @{$options->{'sass_importers'} || []} | ||||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||
| 138 | # gather all paths strings | ||||||||||||||||||||||||||||
| 139 | foreach my $type (@path_types) | ||||||||||||||||||||||||||||
| 140 | { | ||||||||||||||||||||||||||||
| 141 | $options->{$type} = join $dir_delim, | ||||||||||||||||||||||||||||
| 142 | map { split $dir_delim, $_ } | ||||||||||||||||||||||||||||
| 143 | @{$options->{$type} || []}; | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | # now normalize the original hash | ||||||||||||||||||||||||||||
| 146 | $options->{'functions'} = \@functions; | ||||||||||||||||||||||||||||
| 147 | $options->{'importers'} = \@importers; | ||||||||||||||||||||||||||||
| 148 | # remove importer from options | ||||||||||||||||||||||||||||
| 149 | # it is now included in importers | ||||||||||||||||||||||||||||
| 150 | delete $options->{'importer'}; | ||||||||||||||||||||||||||||
| 151 | # return pointer | ||||||||||||||||||||||||||||
| 152 | return $options; | ||||||||||||||||||||||||||||
| 153 | }; | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # install the fix right before calling libsass | ||||||||||||||||||||||||||||
| 156 | # make sure you local'd the env variable before | ||||||||||||||||||||||||||||
| 157 | my $fix_lib_loading = sub { | ||||||||||||||||||||||||||||
| 158 | # only do work on windows | ||||||||||||||||||||||||||||
| 159 | return if $^O ne 'MSWin32'; | ||||||||||||||||||||||||||||
| 160 | # get path to our own module file | ||||||||||||||||||||||||||||
| 161 | # libsass will be near somewhere | ||||||||||||||||||||||||||||
| 162 | my $rpath = $INC{"CSS/Sass.pm"}; | ||||||||||||||||||||||||||||
| 163 | die "Module path not found" unless $rpath; | ||||||||||||||||||||||||||||
| 164 | # normalize all slashes | ||||||||||||||||||||||||||||
| 165 | $rpath =~ s/[\\\/]+/\//g; | ||||||||||||||||||||||||||||
| 166 | # remove our own file from path | ||||||||||||||||||||||||||||
| 167 | $rpath =~ s/CSS\/Sass\.pm$//; | ||||||||||||||||||||||||||||
| 168 | # remove perl path parts | ||||||||||||||||||||||||||||
| 169 | $rpath =~ s/(?:b?lib\/+)+//g; | ||||||||||||||||||||||||||||
| 170 | # remove trailing slash | ||||||||||||||||||||||||||||
| 171 | $rpath =~ s/[\\\/]+$//g; | ||||||||||||||||||||||||||||
| 172 | # find lib and add path for loader | ||||||||||||||||||||||||||||
| 173 | map { $ENV{'PATH'} .= ';' . $_ } | ||||||||||||||||||||||||||||
| 174 | grep { -f join '/', $_, 'libsass.dll' } | ||||||||||||||||||||||||||||
| 175 | map { join '/', $rpath, $_, 'CSS/Sass' } | ||||||||||||||||||||||||||||
| 176 | @ppaths; # imported from plugins module | ||||||||||||||||||||||||||||
| 177 | }; | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | sub sass_compile | ||||||||||||||||||||||||||||
| 180 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
sass_compile: called CC=2 SCAR=9.7
| |||||||||||||||||||||||||||||
| 181 | 1 | local $ENV{'PATH'}; | |||||||||||||||||||||||||||
| 182 | 1 | $fix_lib_loading->(); | |||||||||||||||||||||||||||
| 183 | 0 | my ($sass_code, %options) = @_; | |||||||||||||||||||||||||||
| 184 | 12 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 185 | 0 | $normalize_options->(\%options); | |||||||||||||||||||||||||||
| 186 | 0 | my $r = compile_sass($sass_code, \%options); | |||||||||||||||||||||||||||
| 187 | wantarray ? ($r->{output_string}, $r->{error_message}, $r) : $r->{output_string} | ||||||||||||||||||||||||||||
| 188 | 0 | ▶ | } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | sub sass_compile_file | ||||||||||||||||||||||||||||
| 191 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
sass_compile_file: not called CC=2 SCAR=12.6
| |||||||||||||||||||||||||||||
| 192 | 0 | local $ENV{'PATH'}; | |||||||||||||||||||||||||||
| 193 | 0 | $fix_lib_loading->(); | |||||||||||||||||||||||||||
| 194 | 0 | my ($input_path, %options) = @_; | |||||||||||||||||||||||||||
| 195 | 12 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 196 | 0 | $normalize_options->(\%options); | |||||||||||||||||||||||||||
| 197 | 0 | my $r = compile_sass_file($input_path, \%options); | |||||||||||||||||||||||||||
| 198 | wantarray ? ($r->{output_string}, $r->{error_message}, $r) : $r->{output_string} | ||||||||||||||||||||||||||||
| 199 | 0 | ▶ | } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | sub compile | ||||||||||||||||||||||||||||
| 202 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
compile: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 203 | 0 | local $ENV{'PATH'}; | |||||||||||||||||||||||||||
| 204 | 0 | $fix_lib_loading->(); | |||||||||||||||||||||||||||
| 205 | 0 | my ($self, $sass_code) = @_; | |||||||||||||||||||||||||||
| 206 | 0 | my ($compiled, $stats); | |||||||||||||||||||||||||||
| 207 | 0 | ($compiled, $self->{last_error}, $stats) = sass_compile($sass_code, %{$self->options}); | |||||||||||||||||||||||||||
| 208 | 0 | ▶ | croak $self->{last_error} if $self->{last_error} && !$self->options->{dont_die}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"last_error"} and not $self->options->{"dont_die"}
MC/DC0%0/2
$self->{"last_error"} and not $self->options->{"dont_die"}
$self->{"last_error"}
not $self->options->{"dont_die"}
Truth table0%0/3
A and not(B)
A= $self->{"last_error"}B= not $self->options->{"dont_die"}
| |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | wantarray ? ($compiled, $stats) : $compiled | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | sub compile_file | ||||||||||||||||||||||||||||
| 213 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
compile_file: called CC=4 SCAR=26.7
| |||||||||||||||||||||||||||||
| 214 | 1 | local $ENV{'PATH'}; | |||||||||||||||||||||||||||
| 215 | 1 | $fix_lib_loading->(); | |||||||||||||||||||||||||||
| 216 | 0 | my ($self, $sass_file) = @_; | |||||||||||||||||||||||||||
| 217 | 0 | my ($compiled, $stats); | |||||||||||||||||||||||||||
| 218 | 0 | ($compiled, $self->{last_error}, $stats) = sass_compile_file($sass_file, %{$self->options}); | |||||||||||||||||||||||||||
| 219 | 0 | ▶ | croak $self->{last_error} if $self->{last_error} && !$self->options->{dont_die}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"last_error"} and not $self->options->{"dont_die"}
MC/DC0%0/2
$self->{"last_error"} and not $self->options->{"dont_die"}
$self->{"last_error"}
not $self->options->{"dont_die"}
Truth table0%0/3
A and not(B)
A= $self->{"last_error"}B= not $self->options->{"dont_die"}
| |||||||||||||||||||||||||||||
| 220 | 0 | ▶ | wantarray ? ($compiled, $stats) : $compiled | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 1; | ||||||||||||||||||||||||||||
| 224 | __END__ | ||||||||||||||||||||||||||||