blib/lib/Text/Sass/XS.pm

filter: Statementstmt 79.2% 65 / 82 Branchbran 57.6% 15 / 26 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 77.7% 14 / 18 Podpod 90.0% 9 / 10 totaltotal 75.1% 106 / 141 CC 15 SCAR 13.5
CC
15
Cov
74%
_require_pp
12.0
_normalize_options
6.0
errstr
6.0
CRAP 3.9
↑ Summary builder/MyBuilder.pm »
1 package Text::Sass::XS;
2 7 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 our $VERSION = "0.11";
9  
10 7 my @constants = qw(
11 SASS_STYLE_NESTED
12 SASS_STYLE_EXPANDED
13 SASS_STYLE_COMPRESSED
14 SASS_SOURCE_COMMENTS_NONE
15 SASS_SOURCE_COMMENTS_DEFAULT
16 SASS_SOURCE_COMMENTS_MAP
17 );
18 7 my @functions = qw(
19 sass_compile
20 sass_compile_file
21 );
22 7 our @EXPORT_OK = ( @constants, @functions );
23 7 our %EXPORT_TAGS = (
24 'all' => [ @constants, @functions ],
25 'const' => \@constants,
26 'func' => \@functions
27 );
28  
29 7 ▶use XSLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 7 XSLoader::load( __PACKAGE__, $VERSION );
31  
32 3 ▶sub sass_compile {
Subroutine sass_compile: called CC=3 SCAR=11.0
Pod documented
33 3 my $source_string = shift;
34  
35 3 my $result;
36 3 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 2 1 3
37 2 $result = _compile( $source_string, +{ _normalize_options(@_) } );
38 }
39 else {
40 1 $result = _compile($source_string);
41 }
42  
43 wantarray
44 ? ( $result->{output_string}, $result->{error_message} )
45 3 ▶ : $result->{output_string};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
46 }
47  
48 2 ▶sub sass_compile_file {
Subroutine sass_compile_file: called CC=3 SCAR=11.0
Pod documented
49 2 my $input_path = shift;
50  
51 2 my $result;
52 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 1 1 2
53 1 $result = _compile_file( $input_path, +{ _normalize_options(@_) } );
54 }
55 else {
56 1 $result = _compile_file($input_path);
57 }
58  
59 wantarray
60 ? ( $result->{output_string}, $result->{error_message} )
61 2 ▶ : $result->{output_string};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
62 }
63  
64 8 ▶sub _normalize_options {
Subroutine _normalize_options: called CC=6 SCAR=18.0
65 8 ▶ return unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 8 8
66  
67 8 ▶ my %options = ref $_[0] eq 'HASH' ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 3 5 8
68  
69 # include_paths must be a colon separated string.
70 8 ▶ if ( $options{include_paths}
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'include_paths'} and ref $options{'include_paths'} eq 'ARRAY') { } 3 5 8
Condition66%2/3
$options{"include_paths"} and ref $options{"include_paths"} eq "ARRAY"
!ll&&!rl&&r
503
MC/DC50%1/2
$options{"include_paths"} and ref $options{"include_paths"} eq "ARRAY"
$options{"include_paths"} ref $options{"include_paths"} eq "ARRAY"
Truth table66%2/3
A and B
A= $options{"include_paths"}B= ref $options{"include_paths"} eq "ARRAY"
ABresult
0X0
100
111
71 && ref $options{include_paths} eq 'ARRAY' )
72 {
73 3 $options{include_paths} = join ':', @{ $options{include_paths} };
74 }
75 else {
76 5 $options{include_paths} = "";
77 }
78  
79 8 ▶ $options{image_path} = "" unless $options{image_path};
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"image_path"} 5 3 8
80  
81 8 return %options;
82 }
83  
84 # OO Interface
85 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
86 5 my $class = shift;
87  
88 5 my $self = bless {
89 options => {
90 output_style => SASS_STYLE_COMPRESSED(),
91 source_comments => SASS_SOURCE_COMMENTS_NONE(),
92 include_paths => undef,
93 image_path => undef,
94 @_,
95 },
96 _errstr => undef,
97 }, $class;
98  
99 5 return $self;
100 }
101  
102 5 ▶sub options {
Subroutine options: called CC=1 SCAR=0.0
Pod documented
103 5 my $self = shift;
104 5 $self->{options};
105 }
106  
107 0 ▶sub errstr {
Subroutine errstr: not called CC=2 SCAR=17.9
Pod undocumented
108 0 my $self = shift;
109 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
110 0 $self->{_errstr} = shift;
111 }
112 else {
113 0 $self->{_errstr};
114 }
115 }
116  
117 3 ▶sub compile {
Subroutine compile: called CC=2 SCAR=7.1
Pod documented
118 3 my $self = shift;
119 3 my $source_string = shift;
120  
121 3 my %options = _normalize_options( %{ $self->options } );
122 3 my $result = _compile( $source_string, \%options );
123  
124 3 ▶ if ( $result->{error_status} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{'error_status'}) { } 0 3 3
125 0 Carp::croak $result->{error_message};
126 }
127 else {
128 3 return $result->{output_string};
129 }
130 }
131  
132 2 ▶sub compile_file {
Subroutine compile_file: called CC=2 SCAR=7.1
Pod documented
133 2 my $self = shift;
134 2 my $input_path = shift;
135  
136 2 my %options = _normalize_options( %{ $self->options } );
137 2 my $result = _compile_file( $input_path, \%options );
138  
139 2 ▶ if ( $result->{error_status} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->{'error_status'}) { } 0 2 2
140 0 Carp::croak $result->{error_message};
141 }
142 else {
143 2 return $result->{output_string};
144 }
145 }
146  
147 # For Text::Sass Compatibility
148 1 ▶sub scss2css { shift->compile(@_) }
Subroutine scss2css: called CC=1 SCAR=0.0
Pod documented
149  
150 0 ▶sub sass2css {
Subroutine sass2css: not called CC=1 SCAR=6.9
Pod documented
151 0 my $self = shift;
152 0 $self->_require_pp;
153 0 Text::Sass->new->sass2css(@_);
154 }
155  
156 0 ▶sub css2sass {
Subroutine css2sass: not called CC=1 SCAR=6.9
Pod documented
157 0 my $self = shift;
158 0 $self->_require_pp;
159 0 Text::Sass->new->css2sass(@_);
160 }
161  
162 0 ▶sub _require_pp {
Subroutine _require_pp: not called CC=3 SCAR=24.8
163 0 ▶ return if $INC{"Text/Sass.pm"};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{"Text/Sass.pm"} 0 0 0
164 0 local $@;
165 0 eval 'require Text::Sass;';
166 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
167 0 Carp::croak
168 "Cannot load Text::Sass. If you want to use css2sass or sass2css method, you need to install Text::Sass first.";
169 }
170 }
171  
172 7 1;
173 __END__
↑ Summary builder/MyBuilder.pm »