blib/lib/Inline/C.pm

filter: Statementstmt 82.7% 446 / 539 Branchbran 62.4% 196 / 314 Conditioncond 56.1% 46 / 82 MC/DCmcdc 29.1% 14 / 48 Subroutinesub 90.2% 46 / 51 Podpod 5.2% 2 / 38 totaltotal 69.9% 750 / 1072 CC 200 SCAR 45.4
CC
200
Cov
74%
validate
325.3
add_text
30.0
info
30.0
CRAP 93.5
↑ Summary blib/lib/Inline/C/Parser/RegExp.pm »
1 30 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Inline::C;
3 30 our $VERSION = '0.78';
4  
5 30 ▶use Inline 0.56;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 30 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 30 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 30 ▶use Cwd qw(cwd abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 30 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 30 ▶use constant IS_WIN32 => $^O eq 'MSWin32';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 30 ▶use if !IS_WIN32, Fcntl => ':flock';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 30 ▶use if IS_WIN32, 'Win32::Mutex';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 30 our @ISA = qw(Inline);
16  
17 #==============================================================================
18 # Register this module as an Inline language support module
19 #==============================================================================
20 sub register {
21 return {
22 language => 'C',
23 # XXX Breaking this on purpose; let's see who screams
24 # aliases => ['c'],
25 type => 'compiled',
26 suffix => $Config{dlext},
27 0 ▶ };
Subroutine register: not called CC=1 SCAR=6.9
Pod undocumented
28 }
29  
30 #==============================================================================
31 # Validate the C config options
32 #==============================================================================
33 sub usage_validate {
34 0 ▶ my $key = shift;
Subroutine usage_validate: not called CC=1 SCAR=6.9
Pod undocumented
35 0 return <<END;
36 The value of config option '$key' must be a string or an array ref
37  
38 END
39 }
40  
41 sub validate {
42 54 ▶ my $o = shift;
Subroutine validate: called CC=66 SCAR=57.8
Pod undocumented
43  
44 54 ▶ print STDERR "validate Stage\n" if $o->{CONFIG}{BUILD_NOISY};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"CONFIG"}{"BUILD_NOISY"} 0 54 54
45 54 ▶ $o->{ILSM} ||= {};
Condition100%2/2
$o->{"ILSM"} ||= {}
l!l
252
MC/DC100%1/1
$o->{"ILSM"} ||= {}
$o->{"ILSM"}
Truth table100%2/2
A
A= $o->{"ILSM"}
Aresult
11
00
46 54 ▶ $o->{ILSM}{XS} ||= {};
Condition100%2/2
$o->{"ILSM"}{"XS"} ||= {}
l!l
153
MC/DC100%1/1
$o->{"ILSM"}{"XS"} ||= {}
$o->{"ILSM"}{"XS"}
Truth table100%2/2
A
A= $o->{"ILSM"}{"XS"}
Aresult
11
00
47 54 ▶ $o->{ILSM}{MAKEFILE} ||= {};
Condition100%2/2
$o->{"ILSM"}{"MAKEFILE"} ||= {}
l!l
252
MC/DC100%1/1
$o->{"ILSM"}{"MAKEFILE"} ||= {}
$o->{"ILSM"}{"MAKEFILE"}
Truth table100%2/2
A
A= $o->{"ILSM"}{"MAKEFILE"}
Aresult
11
00
48 54 ▶ if (not $o->UNTAINT) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($o->UNTAINT) 50 4 54
49 50 require FindBin;
50 $o->{ILSM}{MAKEFILE}{INC} = "-I\"$FindBin::Bin\""
51 50 ▶ if not defined $o->{ILSM}{MAKEFILE}{INC};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o->{"ILSM"}{"MAKEFILE"}{"INC"} 48 2 50
52 }
53 54 ▶ $o->{ILSM}{AUTOWRAP} = 0 if not defined $o->{ILSM}{AUTOWRAP};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o->{"ILSM"}{"AUTOWRAP"} 53 1 54
54 54 ▶ $o->{ILSM}{XSMODE} = 0 if not defined $o->{ILSM}{XSMODE};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o->{"ILSM"}{"XSMODE"} 53 1 54
55 54 ▶ $o->{ILSM}{AUTO_INCLUDE} ||= <<END;
Condition100%2/2
$o->{"ILSM"}{"AUTO_INCLUDE"} ||= qq[#include "EXTERN.h"\n#include "perl.h"\n#include "XSUB.h"\n#include "INLINE.h"\n]
l!l
153
MC/DC100%1/1
$o->{"ILSM"}{"AUTO_INCLUDE"} ||= qq[#include "EXTERN.h"\n#include "perl.h"\n#include "XSUB.h"\n#include "INLINE.h"\n]
$o->{"ILSM"}{"AUTO_INCLUDE"}
Truth table100%2/2
A
A= $o->{"ILSM"}{"AUTO_INCLUDE"}
Aresult
11
00
56 #include "EXTERN.h"
57 #include "perl.h"
58 #include "XSUB.h"
59 #include "INLINE.h"
60 END
61 54 ▶ $o->{ILSM}{FILTERS} ||= [];
Condition100%2/2
$o->{"ILSM"}{"FILTERS"} ||= []
l!l
153
MC/DC100%1/1
$o->{"ILSM"}{"FILTERS"} ||= []
$o->{"ILSM"}{"FILTERS"}
Truth table100%2/2
A
A= $o->{"ILSM"}{"FILTERS"}
Aresult
11
00
62 $o->{STRUCT} ||= {
63 54 ▶ '.macros' => '',
Condition100%2/2
$o->{"STRUCT"} ||= {".macros", "", ".xs", "", ".any", 0, ".all", 0}
l!l
153
MC/DC100%1/1
$o->{"STRUCT"} ||= {".macros", "", ".xs", "", ".any", 0, ".all", 0}
$o->{"STRUCT"}
Truth table100%2/2
A
A= $o->{"STRUCT"}
Aresult
11
00
64 '.xs' => '',
65 '.any' => 0,
66 '.all' => 0,
67 };
68  
69 54 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 22 51 73
70 22 my ($key, $value) = (shift, shift);
71 22 ▶ if ($key eq 'PRE_HEAD') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "PRE_HEAD") 1 21 22
72 1 ▶ unless( -f $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $value) { } 1 0 1
73 $o->{ILSM}{AUTO_INCLUDE} = $value . "\n" .
74 0 $o->{ILSM}{AUTO_INCLUDE};
75 }
76 else {
77 1 my $insert;
78 1 ▶ open RD, '<', $value
Branch: 1 branch
BranchTrueFalseTotal
open RD, "<", $value or die "Couldn't open $value for reading: $!" 0 1 1
79 or die "Couldn't open $value for reading: $!";
80 1 ▶ while (<RD>) {$insert .= $_}
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline RD)) 5 1 6
81 1 ▶ close RD
Branch: 1 branch
BranchTrueFalseTotal
close RD or die "Couldn't close $value after reading: $!" 0 1 1
82 or die "Couldn't close $value after reading: $!";
83 $o->{ILSM}{AUTO_INCLUDE} =
84 1 $insert . "\n" . $o->{ILSM}{AUTO_INCLUDE};
85 }
86 1 next;
87 }
88 21 ▶ if ($key eq 'MAKE' or
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "MAKE" or $key eq "AUTOWRAP" or $key eq "XSMODE") 2 19 21
Condition83%5/6
$key eq "MAKE" or $key eq "AUTOWRAP" or $key eq "XSMODE"
l!l&&r!l&&!r
1119
$key eq "MAKE" or $key eq "AUTOWRAP"
l!l&&r!l&&!r
0120
MC/DC66%2/3
$key eq "MAKE" or $key eq "AUTOWRAP" or $key eq "XSMODE"
$key eq "MAKE" $key eq "AUTOWRAP" $key eq "XSMODE"
Truth table75%3/4
A or B or C
A= $key eq "MAKE"B= $key eq "AUTOWRAP"C= $key eq "XSMODE"
ABCresult
1XX1
01X1
0011
0000
89 $key eq 'AUTOWRAP' or
90 $key eq 'XSMODE'
91 ) {
92 2 $o->{ILSM}{$key} = $value;
93 2 next;
94 }
95 19 ▶ if ($key eq 'CC' or
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "CC" or $key eq "LD") 1 18 19
Condition66%2/3
$key eq "CC" or $key eq "LD"
l!l&&r!l&&!r
1018
MC/DC50%1/2
$key eq "CC" or $key eq "LD"
$key eq "CC" $key eq "LD"
Truth table66%2/3
A or B
A= $key eq "CC"B= $key eq "LD"
ABresult
1X1
011
000
96 $key eq 'LD'
97 ) {
98 1 $o->{ILSM}{MAKEFILE}{$key} = $value;
99 1 next;
100 }
101 18 ▶ if ($key eq 'LIBS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "LIBS") 0 18 18
102 0 $o->add_list($o->{ILSM}{MAKEFILE}, $key, $value, []);
103 0 next;
104 }
105 18 ▶ if ($key eq 'INC') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "INC") 3 15 18
106 $o->add_string(
107 $o->{ILSM}{MAKEFILE},
108 3 $key,
109 quote_space($value),
110 '',
111 );
112 3 next;
113 }
114 15 ▶ if ($key eq 'MYEXTLIB' or
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "MYEXTLIB" or $key eq "OPTIMIZE" or $key eq "CCFLAGS" or $key eq "LDDLFLAGS") 2 13 15
Condition55%5/9
$key eq "MYEXTLIB" or $key eq "OPTIMIZE" or $key eq "CCFLAGS" or $key eq "LDDLFLAGS"
l!l&&r!l&&!r
2013
$key eq "MYEXTLIB" or $key eq "OPTIMIZE" or $key eq "CCFLAGS"
l!l&&r!l&&!r
0213
$key eq "MYEXTLIB" or $key eq "OPTIMIZE"
l!l&&r!l&&!r
0015
MC/DC25%1/4
$key eq "MYEXTLIB" or $key eq "OPTIMIZE" or $key eq "CCFLAGS" or $key eq "LDDLFLAGS"
$key eq "MYEXTLIB" $key eq "OPTIMIZE" $key eq "CCFLAGS" $key eq "LDDLFLAGS"
Truth table40%2/5
A or B or C or D
A= $key eq "MYEXTLIB"B= $key eq "OPTIMIZE"C= $key eq "CCFLAGS"D= $key eq "LDDLFLAGS"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
115 $key eq 'OPTIMIZE' or
116 $key eq 'CCFLAGS' or
117 $key eq 'LDDLFLAGS'
118 ) {
119 2 $o->add_string($o->{ILSM}{MAKEFILE}, $key, $value, '');
120 2 next;
121 }
122 13 ▶ if ($key eq 'CCFLAGSEX') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "CCFLAGSEX") 1 12 13
123 $o->add_string(
124 $o->{ILSM}{MAKEFILE},
125 'CCFLAGS',
126 1 $Config{ccflags} . ' ' . $value, '',
127 );
128 1 next;
129 }
130 12 ▶ if ($key eq 'TYPEMAPS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "TYPEMAPS") 2 10 12
131 2 ▶ unless(ref($value) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 1 1 2
132 1 ▶ croak "TYPEMAPS file '$value' not found"
Branch: 1 branch
BranchTrueFalseTotal
unless -f $value 0 1 1
133 unless -f $value;
134 1 $value = File::Spec->rel2abs($value);
135 }
136 else {
137 1 ▶ for (my $i = 0; $i < scalar(@$value); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @$value) 2 1 3
138 0 croak "TYPEMAPS file '${$value}[$i]' not found"
139 2 ▶ unless -f ${$value}[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless -f do { $value }->[$i] 0 2 2
140 2 ${$value}[$i] = File::Spec->rel2abs(${$value}[$i]);
141 }
142 }
143 2 $o->add_list($o->{ILSM}{MAKEFILE}, $key, $value, []);
144 2 next;
145 }
146 10 ▶ if ($key eq 'AUTO_INCLUDE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "AUTO_INCLUDE") 0 10 10
147 0 $o->add_text($o->{ILSM}, $key, $value, '');
148 0 next;
149 }
150 10 ▶ if ($key eq 'BOOT') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "BOOT") 0 10 10
151 0 $o->add_text($o->{ILSM}{XS}, $key, $value, '');
152 0 next;
153 }
154 10 ▶ if ($key eq 'PREFIX') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "PREFIX") 2 8 10
155 2 ▶ croak "Invalid value for 'PREFIX' option"
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^\w*$/ and not $value =~ /\n/ 0 2 2
Condition33%1/3
$value =~ /^\w*$/ and not $value =~ /\n/
!ll&&!rl&&r
002
MC/DC0%0/2
$value =~ /^\w*$/ and not $value =~ /\n/
$value =~ /^\w*$/ not $value =~ /\n/
Truth table33%1/3
A and not(B)
A= $value =~ /^\w*$/B= not $value =~ /\n/
ABresult
0X0
100
111
156 unless ($value =~ /^\w*$/ and
157 $value !~ /\n/);
158 2 $o->{ILSM}{XS}{PREFIX} = $value;
159 2 next;
160 }
161 8 ▶ if ($key eq 'FILTERS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "FILTERS") 0 8 8
162 0 ▶ next if $value eq '1' or $value eq '0'; # ignore ENABLE, DISABLE
Branch: 1 branch
BranchTrueFalseTotal
if $value eq 1 or $value eq 0 0 0 0
Condition0%0/3
$value eq 1 or $value eq 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$value eq 1 or $value eq 0
$value eq 1 $value eq 0
Truth table0%0/3
A or B
A= $value eq 1B= $value eq 0
ABresult
1X1
011
000
163 0 ▶ $value = [$value] unless ref($value) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" 0 0 0
164 0 my %filters;
165 0 for my $val (@$value) {
166 0 ▶ if (ref($val) eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val eq 'CODE') { } 0 0 0
elsif (ref $val eq 'ARRAY') { } 0 0 0
167 0 $o->add_list($o->{ILSM}, $key, $val, []);
168 }
169 elsif (ref($val) eq 'ARRAY') {
170 0 my ($filter_plugin, @args) = @$val;
171  
172 0 ▶ croak "Bad format for filter plugin name: '$filter_plugin'"
Branch: 1 branch
BranchTrueFalseTotal
unless $filter_plugin =~ /^[\w:]+$/ 0 0 0
173 unless $filter_plugin =~ m/^[\w:]+$/;
174  
175 0 eval "require Inline::Filters::${filter_plugin}";
176 0 ▶ croak "Filter plugin Inline::Filters::$filter_plugin not installed"
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
177 if $@;
178  
179 croak "No Inline::Filters::${filter_plugin}::filter sub found"
180 0 ▶ unless defined &{"Inline::Filters::${filter_plugin}::filter"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"Inline::Filters::${filter_plugin}::filter";} 0 0 0
181  
182 0 my $filter_factory = \&{"Inline::Filters::${filter_plugin}::filter"};
183  
184 0 $o->add_list($o->{ILSM}, $key, $filter_factory->(@args), []);
185 }
186 else {
187 0 eval { require Inline::Filters };
188 0 ▶ croak "'FILTERS' option requires Inline::Filters to be installed."
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
189 if $@;
190 %filters = Inline::Filters::get_filters($o->{API}{language})
191 0 ▶ unless keys %filters;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %filters 0 0 0
192 0 ▶ if (defined $filters{$val}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $filters{$val}) { } 0 0 0
193 my $filter = Inline::Filters->new(
194 $val,
195 0 $filters{$val});
196 0 $o->add_list($o->{ILSM}, $key, $filter, []);
197 }
198 else {
199 0 croak "Invalid filter $val specified.";
200 }
201 }
202 }
203 0 next;
204 }
205 8 ▶ if ($key eq 'STRUCTS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "STRUCTS") 0 8 8
206 # A list of struct names
207 0 ▶ if (ref($value) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 0 0
elsif ($value =~ /^\d+$/) { } 0 0 0
208 0 for my $val (@$value) {
209 0 ▶ croak "Invalid value for 'STRUCTS' option"
Branch: 1 branch
BranchTrueFalseTotal
unless $val =~ /^[_a-z][_0-9a-z]*$/i 0 0 0
210 unless ($val =~ /^[_a-z][_0-9a-z]*$/i);
211 0 $o->{STRUCT}{$val}++;
212 }
213 }
214 # Enable or disable
215 elsif ($value =~ /^\d+$/) {
216 0 $o->{STRUCT}{'.any'} = $value;
217 }
218 # A single struct name
219 else {
220 0 ▶ croak "Invalid value for 'STRUCTS' option"
Branch: 1 branch
BranchTrueFalseTotal
unless $value =~ /^[_a-z][_0-9a-z]*$/i 0 0 0
221 unless ($value =~ /^[_a-z][_0-9a-z]*$/i);
222 0 $o->{STRUCT}{$value}++;
223 }
224 0 eval { require Inline::Struct };
225 0 ▶ croak "'STRUCTS' option requires Inline::Struct to be installed."
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
226 if $@;
227 0 $o->{STRUCT}{'.any'} = 1;
228 0 next;
229 }
230 8 ▶ if ($key eq 'PROTOTYPES') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "PROTOTYPES") 3 5 8
231 3 $o->{CONFIG}{PROTOTYPES} = $value;
232 3 ▶ next if $value eq 'ENABLE';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "ENABLE" 2 1 3
233 1 ▶ next if $value eq 'DISABLE';
Branch: 1 branch
BranchTrueFalseTotal
if $value eq "DISABLE" 0 1 1
234 1 die "PROTOTYPES can be only either 'ENABLE' or 'DISABLE' - not $value";
235 }
236 5 ▶ if ($key eq 'PROTOTYPE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "PROTOTYPE") 3 2 5
237 3 ▶ die "PROTOTYPE configure arg must specify a hash reference"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" 1 2 3
238 unless ref($value) eq 'HASH';
239 2 $o->{CONFIG}{PROTOTYPE} = $value;
240 2 next;
241 }
242 2 ▶ if ($key eq 'CPPFLAGS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "CPPFLAGS") 1 1 2
243 # C preprocessor flags, used by Inline::Filters::Preprocess()
244 1 next;
245 }
246  
247 1 my $class = ref $o; # handles subclasses correctly.
248 1 croak "'$key' is not a valid config option for $class\n";
249 }
250 }
251  
252 sub add_list {
253 2 ▶ my $o = shift;
Subroutine add_list: called CC=4 SCAR=14.0
Pod undocumented
254 2 my ($ref, $key, $value, $default) = @_;
255 2 ▶ $value = [$value] unless ref $value eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" 1 1 2
256 2 for (@$value) {
257 3 ▶ if (defined $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) { } 3 0 3
258 3 push @{$ref->{$key}}, $_;
259 }
260 else {
261 0 $ref->{$key} = $default;
262 }
263 }
264 }
265  
266 sub add_string {
267 6 ▶ my $o = shift;
Subroutine add_string: called CC=5 SCAR=17.2
Pod undocumented
268 6 my ($ref, $key, $value, $default) = @_;
269 6 ▶ $value = [$value] unless ref $value;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value 6 0 6
270 6 ▶ croak usage_validate($key) unless ref($value) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" 0 6 6
271 6 for (@$value) {
272 6 ▶ if (defined $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) { } 6 0 6
273 6 $ref->{$key} .= ' ' . $_;
274 }
275 else {
276 0 $ref->{$key} = $default;
277 }
278 }
279 }
280  
281 sub add_text {
282 0 ▶ my $o = shift;
Subroutine add_text: not called CC=5 SCAR=34.0
Pod undocumented
283 0 my ($ref, $key, $value, $default) = @_;
284 0 ▶ $value = [$value] unless ref $value;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value 0 0 0
285 0 ▶ croak usage_validate($key) unless ref($value) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" 0 0 0
286 0 for (@$value) {
287 0 ▶ if (defined $_) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) { } 0 0 0
288 0 chomp;
289 0 $ref->{$key} .= $_ . "\n";
290 }
291 else {
292 0 $ref->{$key} = $default;
293 }
294 }
295 }
296  
297 #==============================================================================
298 # Return a small report about the C code..
299 #==============================================================================
300 sub info {
301 0 ▶ my $o = shift;
Subroutine info: not called CC=5 SCAR=34.0
Pod documented
302 0 ▶ return <<END if $o->{ILSM}{XSMODE};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"ILSM"}{"XSMODE"} 0 0 0
303 No information is currently generated when using XSMODE.
304  
305 END
306 0 my $text = '';
307 0 $o->preprocess;
308 0 $o->parse;
309 0 ▶ if (defined $o->{ILSM}{parser}{data}{functions}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o->{'ILSM'}{'parser'}{'data'}{'functions'}) { } 0 0 0
310 0 $text .= "The following Inline $o->{API}{language} function(s) have been successfully bound to Perl:\n";
311 0 my $parser = $o->{ILSM}{parser};
312 0 my $data = $parser->{data};
313 0 for my $function (sort @{$data->{functions}}) {
314 0 my $return_type = $data->{function}{$function}{return_type};
315 0 my @arg_names = @{$data->{function}{$function}{arg_names}};
316 0 my @arg_types = @{$data->{function}{$function}{arg_types}};
317 0 my @args = map {$_ . ' ' . shift @arg_names} @arg_types;
318 0 $text .= "\t$return_type $function(" . join(', ', @args) . ")\n";
319 }
320 }
321 else {
322 0 $text .= "No $o->{API}{language} functions have been successfully bound to Perl.\n\n";
323 }
324 0 ▶ $text .= Inline::Struct::info($o) if $o->{STRUCT}{'.any'};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"STRUCT"}{".any"} 0 0 0
325 0 return $text;
326 }
327  
328 sub config {
329 0 ▶ my $o = shift;
Subroutine config: not called CC=1 SCAR=6.9
Pod undocumented
330 }
331  
332 #==============================================================================
333 # Parse and compile C code
334 #==============================================================================
335 30 my $total_build_time;
336 sub build {
337 47 ▶ my $o = shift;
Subroutine build: called CC=8 SCAR=24.9
Pod undocumented
338  
339 47 ▶ if ($o->{CONFIG}{BUILD_TIMERS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"CONFIG"}{"BUILD_TIMERS"}) 0 47 47
340 0 eval {require Time::HiRes};
341 0 ▶ croak "You need Time::HiRes for BUILD_TIMERS option:\n$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
342 0 $total_build_time = Time::HiRes::time();
343 }
344 47 my ($file, $lockfh);
345 47 if (IS_WIN32) {
346 #this can not look like a file path, or new() fails
347 $file = 'Inline__C_' . $o->{API}{directory} . '.lock';
348 $file =~ s/\\/_/g; #per CreateMutex on MSDN
349 $lockfh = Win32::Mutex->new(0, $file) or die "lockmutex $file: $^E";
350 $lockfh->wait(); #acquire, can't use 1 to new(), since if new() opens
351 #existing instead of create new Muxtex, it is not acquired
352 }
353 else {
354 47 $file = File::Spec->catfile($o->{API}{directory}, '.lock');
355 47 ▶ open $lockfh, '>', $file or die "lockfile $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $lockfh, ">", $file or die "lockfile ${file}: $!" 0 47 47
356 47 ▶ flock($lockfh, LOCK_EX) or die "flock: $!\n" if $^O !~ /^VMS|riscos|VOS$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $^O =~ /^VMS|riscos|VOS$/ 47 0 47
Condition40%2/5
$^O =~ /^VMS|riscos|VOS$/ || (flock($lockfh, 2) || die("flock: $!\n"))
l!l&&r!l&&!r
0470
flock $lockfh, 2 or die "flock: $!\n"
l!l
470
MC/DC0%0/2
$^O =~ /^VMS|riscos|VOS$/ || (flock($lockfh, 2) || die("flock: $!\n"))
$^O =~ /^VMS|riscos|VOS$/ flock $lockfh, 2
Truth table33%1/3
A || B
A= $^O =~ /^VMS|riscos|VOS$/B= flock $lockfh, 2
ABresult
1X1
011
000
357 }
358 47 $o->mkpath($o->{API}{build_dir});
359 47 $o->call('preprocess', 'Build Preprocess');
360 47 $o->call('parse', 'Build Parse');
361 47 $o->call('write_XS', 'Build Glue 1');
362 47 $o->call('write_Inline_headers', 'Build Glue 2');
363 47 $o->call('write_Makefile_PL', 'Build Glue 3');
364 47 $o->call('compile', 'Build Compile');
365 46 if (IS_WIN32) {
366 $lockfh->release or die "releasemutex $file: $^E";
367 }
368 else {
369 46 ▶ flock($lockfh, LOCK_UN) if $^O !~ /^VMS|riscos|VOS$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $^O =~ /^VMS|riscos|VOS$/ 46 0 46
370 }
371 46 ▶ if ($o->{CONFIG}{BUILD_TIMERS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"CONFIG"}{"BUILD_TIMERS"}) 0 46 46
372 0 $total_build_time = Time::HiRes::time() - $total_build_time;
373 0 printf STDERR "Total Build Time: %5.4f secs\n", $total_build_time;
374 }
375 }
376  
377 sub call {
378 468 ▶ my ($o, $method, $header, $indent) = (@_, 0);
Subroutine call: called CC=7 SCAR=20.8
Pod undocumented
379 468 my $time;
380 468 my $i = ' ' x $indent;
381 468 ▶ print STDERR "${i}Starting $header Stage\n" if $o->{CONFIG}{BUILD_NOISY};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"CONFIG"}{"BUILD_NOISY"} 0 468 468
382 $time = Time::HiRes::time()
383 468 ▶ if $o->{CONFIG}{BUILD_TIMERS};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"CONFIG"}{"BUILD_TIMERS"} 0 468 468
384  
385 468 $o->$method();
386  
387 $time = Time::HiRes::time() - $time
388 466 ▶ if $o->{CONFIG}{BUILD_TIMERS};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"CONFIG"}{"BUILD_TIMERS"} 0 466 466
389 466 ▶ print STDERR "${i}Finished $header Stage\n" if $o->{CONFIG}{BUILD_NOISY};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"CONFIG"}{"BUILD_NOISY"} 0 466 466
390 printf STDERR "${i}Time for $header Stage: %5.4f secs\n", $time
391 466 ▶ if $o->{CONFIG}{BUILD_TIMERS};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"CONFIG"}{"BUILD_TIMERS"} 0 466 466
392 466 ▶ print STDERR "\n" if $o->{CONFIG}{BUILD_NOISY};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"CONFIG"}{"BUILD_NOISY"} 0 466 466
393 }
394  
395 #==============================================================================
396 # Apply any
397 #==============================================================================
398 sub preprocess {
399 47 ▶ my $o = shift;
Subroutine preprocess: called CC=2 SCAR=7.0
Pod undocumented
400 47 ▶ return if $o->{ILSM}{parser};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"ILSM"}{"parser"} 0 47 47
401 47 $o->get_maps;
402 47 $o->get_types;
403 47 $o->{ILSM}{code} = $o->filter(@{$o->{ILSM}{FILTERS}});
404 }
405  
406 #==============================================================================
407 # Parse the function definition information out of the C code
408 #==============================================================================
409 sub parse {
410 47 ▶ my $o = shift;
Subroutine parse: called CC=5 SCAR=16.7
Pod undocumented
411 47 ▶ return if $o->{ILSM}{parser};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"ILSM"}{"parser"} 0 47 47
412 47 ▶ return if $o->{ILSM}{XSMODE};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"ILSM"}{"XSMODE"} 1 46 47
413 46 my $parser = $o->{ILSM}{parser} = $o->get_parser;
414 46 $parser->{data}{typeconv} = $o->{ILSM}{typeconv};
415 46 $parser->{data}{AUTOWRAP} = $o->{ILSM}{AUTOWRAP};
416 46 ▶ Inline::Struct::parse($o) if $o->{STRUCT}{'.any'};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"STRUCT"}{".any"} 0 46 46
417 $parser->code($o->{ILSM}{code})
418 46 ▶ or croak <<END;
Branch: 1 branch
BranchTrueFalseTotal
$parser->code($o->{"ILSM"}{"code"}) or croak(qq[Bad $o->{"API"}{"language"} code passed to Inline at @{[caller 2];}\n]) 0 46 46
419 0 Bad $o->{API}{language} code passed to Inline at @{[caller(2)]}
420 END
421 }
422  
423 # Create and initialize a parser
424 sub get_parser {
425 28 ▶ my $o = shift;
Subroutine get_parser: called CC=2 SCAR=6.9
Pod undocumented
426 Inline::C::_parser_test($o->{CONFIG}{DIRECTORY}, "Inline::C::get_parser called\n")
427 28 ▶ if $o->{CONFIG}{_TESTING};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"CONFIG"}{"_TESTING"} 1 27 28
428 28 require Inline::C::Parser::RecDescent;
429 28 Inline::C::Parser::RecDescent::get_parser($o);
430 }
431  
432 #==============================================================================
433 # Gather the path names of all applicable typemap files.
434 #==============================================================================
435 sub get_maps {
436 47 ▶ my $o = shift;
Subroutine get_maps: called CC=10 SCAR=24.8
Pod undocumented
437  
438 47 ▶ print STDERR "get_maps Stage\n" if $o->{CONFIG}{BUILD_NOISY};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"CONFIG"}{"BUILD_NOISY"} 0 47 47
439 47 my $typemap = '';
440 47 my $file;
441 $file = File::Spec->catfile(
442 $Config::Config{installprivlib},
443 47 "ExtUtils",
444 "typemap",
445 );
446 47 ▶ $typemap = $file if -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $file 47 0 47
447 $file = File::Spec->catfile(
448 $Config::Config{privlibexp}
449 47 ,"ExtUtils","typemap"
450 );
451 47 ▶ $typemap = $file
Branch: 1 branch
BranchTrueFalseTotal
if not $typemap and -f $file 0 47 47
Condition33%1/3
not $typemap and -f $file
!ll&&!rl&&r
4700
MC/DC0%0/2
not $typemap and -f $file
not $typemap -f $file
Truth table33%1/3
not(A) and B
A= not $typemapB= -f $file
ABresult
0X0
100
111
452 if (not $typemap and -f $file);
453 47 ▶ warn "Can't find the default system typemap file"
Branch: 1 branch
BranchTrueFalseTotal
if not $typemap and $^W 0 47 47
Condition33%1/3
not $typemap and $^W
!ll&&!rl&&r
4700
MC/DC0%0/2
not $typemap and $^W
not $typemap $^W
Truth table33%1/3
not(A) and B
A= not $typemapB= $^W
ABresult
0X0
100
111
454 if (not $typemap and $^W);
455  
456 47 ▶ unshift(@{$o->{ILSM}{MAKEFILE}{TYPEMAPS}}, $typemap) if $typemap;
Branch: 1 branch
BranchTrueFalseTotal
if $typemap 47 0 47
457  
458 47 ▶ if (not $o->UNTAINT) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $o->UNTAINT) 43 4 47
459 43 require FindBin;
460 43 $file = File::Spec->catfile($FindBin::Bin,"typemap");
461 43 ▶ if ( -f $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $file) 43 0 43
462 43 push(@{$o->{ILSM}{MAKEFILE}{TYPEMAPS}}, $file);
463 }
464 }
465 }
466  
467 #==============================================================================
468 # This routine parses XS typemap files to get a list of valid types to create
469 # bindings to. This code is mostly hacked out of Larry Wall's xsubpp program.
470 #==============================================================================
471 sub get_types {
472 47 ▶ my (%type_kind, %proto_letter, %input_expr, %output_expr);
Subroutine get_types: called CC=19 SCAR=29.8
Pod undocumented
473 47 my $o = shift;
474 47 local $_;
475 croak "No typemaps specified for Inline C code"
476 47 ▶ unless @{$o->{ILSM}{MAKEFILE}{TYPEMAPS}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$o->{"ILSM"}{"MAKEFILE"}{"TYPEMAPS"};} 0 47 47
477  
478 47 my $proto_re = "[" . quotemeta('\$%&*@;') . "]";
479 47 foreach my $typemap (@{$o->{ILSM}{MAKEFILE}{TYPEMAPS}}) {
480 93 ▶ next unless -e $typemap;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $typemap 0 93 93
481 # skip directories, binary files etc.
482 93 ▶ warn("Warning: ignoring non-text typemap file '$typemap'\n"), next
Branch: 1 branch
BranchTrueFalseTotal
unless -T $typemap 0 93 93
483 unless -T $typemap;
484 93 ▶ open(TYPEMAP, $typemap)
Branch: 1 branch
BranchTrueFalseTotal
open TYPEMAP, $typemap or warn("Warning: could not open typemap file '${typemap}': $!\n"), next 0 93 93
485 or warn ("Warning: could not open typemap file '$typemap': $!\n"),
486 next;
487 93 my $mode = 'Typemap';
488 93 my $junk = "";
489 93 my $current = \$junk;
490 93 ▶ while (<TYPEMAP>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline TYPEMAP)) 22928 93 23021
491 22928 ▶ next if /^\s*\#/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*\#/ 658 22270 22928
492 22270 my $line_no = $. + 1;
493 22270 ▶ if (/^INPUT\s*$/) {$mode = 'Input'; $current = \$junk; next}
Branch: 1 branch
BranchTrueFalseTotal
if (/^INPUT\s*$/) 93 22177 22270
494 22177 ▶ if (/^OUTPUT\s*$/) {$mode = 'Output'; $current = \$junk; next}
Branch: 1 branch
BranchTrueFalseTotal
if (/^OUTPUT\s*$/) 93 22084 22177
495 22084 ▶ if (/^TYPEMAP\s*$/) {$mode = 'Typemap'; $current = \$junk; next}
Branch: 1 branch
BranchTrueFalseTotal
if (/^TYPEMAP\s*$/) 0 22084 22084
496 22084 ▶ if ($mode eq 'Typemap') {
Branch: 3 branches
BranchTrueFalseTotal
if ($mode eq 'Typemap') { } 2677 19407 22084
elsif (/^\s/) { } 15273 4134 19407
elsif ($mode eq 'Input') { } 2067 2067 4134
497 2677 chomp;
498 2677 my $line = $_;
499 2677 TrimWhitespace($_);
500 # skip blank lines and comment lines
501 2677 ▶ next if /^$/ or /^\#/;
Branch: 1 branch
BranchTrueFalseTotal
if /^$/ or /^\#/ 234 2443 2677
Condition66%2/3
/^$/ or /^\#/
l!l&&r!l&&!r
23402443
MC/DC50%1/2
/^$/ or /^\#/
/^$/ /^\#/
Truth table66%2/3
A or B
A= /^$/B= /^\#/
ABresult
1X1
011
000
502 2443 ▶ my ($type,$kind, $proto) =
Branch: 1 branch
BranchTrueFalseTotal
() = /^\s*(.*?\S)\s+(\S+)\s*($proto_re*)\s*$/ or warn("Warning: File '${typemap}' Line $. '${line}' TYPEMAP entry needs 2 or 3 columns\n"), next 0 2443 2443
503 /^\s*(.*?\S)\s+(\S+)\s*($proto_re*)\s*$/ or
504 warn("Warning: File '$typemap' Line $. '$line' TYPEMAP entry needs 2 or 3 columns\n"), next;
505 2443 $type = TidyType($type);
506 2443 $type_kind{$type} = $kind;
507 # prototype defaults to '$'
508 2443 ▶ $proto = "\$" unless $proto;
Branch: 1 branch
BranchTrueFalseTotal
unless $proto 2443 0 2443
509 2443 ▶ warn("Warning: File '$typemap' Line $. '$line' Invalid prototype '$proto'\n")
Branch: 1 branch
BranchTrueFalseTotal
unless &ValidProtoString($proto) 0 2443 2443
510 unless ValidProtoString($proto);
511 2443 $proto_letter{$type} = C_string($proto);
512 }
513 elsif (/^\s/) {
514 15273 $$current .= $_;
515 }
516 elsif ($mode eq 'Input') {
517 2067 s/\s+$//;
518 2067 $input_expr{$_} = '';
519 2067 $current = \$input_expr{$_};
520 }
521 else {
522 2067 s/\s+$//;
523 2067 $output_expr{$_} = '';
524 2067 $current = \$output_expr{$_};
525 }
526 }
527 93 close(TYPEMAP);
528 }
529  
530 2398 my %valid_types = map {($_, 1)} grep {
531 47 defined $input_expr{$type_kind{$_}}
532 } keys %type_kind;
533  
534 2445 my %valid_rtypes = map {($_, 1)} (
535 grep {
536 47 defined $output_expr{$type_kind{$_}}
537 } keys %type_kind
538 ), 'void';
539  
540 47 $o->{ILSM}{typeconv}{type_kind} = \%type_kind;
541 47 $o->{ILSM}{typeconv}{input_expr} = \%input_expr;
542 47 $o->{ILSM}{typeconv}{output_expr} = \%output_expr;
543 47 $o->{ILSM}{typeconv}{valid_types} = \%valid_types;
544 47 $o->{ILSM}{typeconv}{valid_rtypes} = \%valid_rtypes;
545 }
546  
547 sub ValidProtoString ($) {
548 2443 ▶ my $string = shift;
Subroutine ValidProtoString: called CC=2 SCAR=7.1
Pod undocumented
549 2443 my $proto_re = "[" . quotemeta('\$%&*@;') . "]";
550 2443 ▶ return ($string =~ /^$proto_re+$/) ? $string : 0;
Branch: 1 branch
BranchTrueFalseTotal
$string =~ /^$proto_re+$/ ? : 2443 0 2443
551 }
552  
553 sub TrimWhitespace {
554 5120 ▶ $_[0] =~ s/^\s+|\s+$//go;
Subroutine TrimWhitespace: called CC=1 SCAR=0.0
Pod undocumented
555 }
556  
557 sub TidyType {
558 2443 ▶ local $_ = shift;
Subroutine TidyType: called CC=1 SCAR=0.0
Pod undocumented
559 2443 s|\s*(\*+)\s*|$1|g;
560 2443 s|(\*+)| $1 |g;
561 2443 s|\s+| |g;
562 2443 TrimWhitespace($_);
563 2443 $_;
564 }
565  
566 sub C_string ($) {
567 2443 ▶ (my $string = shift) =~ s|\\|\\\\|g;
Subroutine C_string: called CC=1 SCAR=0.0
Pod undocumented
568 2443 $string;
569 }
570  
571 #==============================================================================
572 # Write the XS code
573 #==============================================================================
574 sub write_XS {
575 47 ▶ my $o = shift;
Subroutine write_XS: called CC=5 SCAR=16.6
Pod undocumented
576 47 my $modfname = $o->{API}{modfname};
577 47 my $module = $o->{API}{module};
578 47 my $file = File::Spec->catfile($o->{API}{build_dir},"$modfname.xs");
579 47 ▶ open XS, ">", $file or croak "$file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open XS, ">", $file or croak("${file}: $!") 0 47 47
580 47 ▶ if ($o->{ILSM}{XSMODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{'ILSM'}{'XSMODE'}) { } 1 46 47
581 1 ▶ warn <<END if $^W and $o->{ILSM}{code} !~ /MODULE\s*=\s*$module\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $^W and not $o->{"ILSM"}{"code"} =~ /MODULE\s*=\s*$module\b/ 0 1 1
Condition33%1/3
$^W and not $o->{"ILSM"}{"code"} =~ /MODULE\s*=\s*$module\b/
!ll&&!rl&&r
010
MC/DC0%0/2
$^W and not $o->{"ILSM"}{"code"} =~ /MODULE\s*=\s*$module\b/
$^W not $o->{"ILSM"}{"code"} =~ /MODULE\s*=\s*$module\b/
Truth table33%1/3
A and not(B)
A= $^WB= not $o->{"ILSM"}{"code"} =~ /MODULE\s*=\s*$module\b/
ABresult
0X0
100
111
582 While using Inline XSMODE, your XS code does not have a line with
583  
584 MODULE = $module
585  
586 You should use the Inline NAME config option, and it should match the
587 XS MODULE name.
588  
589 END
590 1 print XS $o->xs_code;
591 }
592 else {
593 46 print XS $o->xs_generate;
594 }
595 47 close XS;
596 }
597  
598 #==============================================================================
599 # Generate the XS glue code (piece together lots of snippets)
600 #==============================================================================
601 sub xs_generate {
602 46 ▶ my $o = shift;
Subroutine xs_generate: called CC=1 SCAR=0.0
Pod undocumented
603 46 return join '', (
604 $o->xs_includes,
605 $o->xs_struct_macros,
606 $o->xs_code,
607 $o->xs_struct_code,
608 $o->xs_bindings,
609 $o->xs_boot,
610 );
611 }
612  
613 sub xs_includes {
614 46 ▶ my $o = shift;
Subroutine xs_includes: called CC=1 SCAR=0.0
Pod undocumented
615 46 return $o->{ILSM}{AUTO_INCLUDE};
616 }
617  
618 sub xs_struct_macros {
619 46 ▶ my $o = shift;
Subroutine xs_struct_macros: called CC=1 SCAR=0.0
Pod undocumented
620 46 return $o->{STRUCT}{'.macros'};
621 }
622  
623 sub xs_code {
624 47 ▶ my $o = shift;
Subroutine xs_code: called CC=1 SCAR=0.0
Pod undocumented
625 47 return $o->{ILSM}{code};
626 }
627  
628 sub xs_struct_code {
629 46 ▶ my $o = shift;
Subroutine xs_struct_code: called CC=1 SCAR=0.0
Pod undocumented
630 46 return $o->{STRUCT}{'.xs'};
631 }
632  
633 sub xs_boot {
634 46 ▶ my $o = shift;
Subroutine xs_boot: called CC=3 SCAR=13.3
Pod undocumented
635 46 ▶ if (defined $o->{ILSM}{XS}{BOOT} and $o->{ILSM}{XS}{BOOT}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o->{"ILSM"}{"XS"}{"BOOT"} and $o->{"ILSM"}{"XS"}{"BOOT"}) 0 46 46
Condition33%1/3
defined $o->{"ILSM"}{"XS"}{"BOOT"} and $o->{"ILSM"}{"XS"}{"BOOT"}
!ll&&!rl&&r
4600
MC/DC0%0/2
defined $o->{"ILSM"}{"XS"}{"BOOT"} and $o->{"ILSM"}{"XS"}{"BOOT"}
defined $o->{"ILSM"}{"XS"}{"BOOT"} $o->{"ILSM"}{"XS"}{"BOOT"}
Truth table33%1/3
A and B
A= defined $o->{"ILSM"}{"XS"}{"BOOT"}B= $o->{"ILSM"}{"XS"}{"BOOT"}
ABresult
0X0
100
111
636 0 return <<END;
637 BOOT:
638 $o->{ILSM}{XS}{BOOT}
639 END
640 }
641 46 return '';
642 }
643  
644 sub xs_bindings {
645 46 ▶ my $o = shift;
Subroutine xs_bindings: called CC=19 SCAR=29.9
Pod undocumented
646 46 my $dir = $o->{API}{directory};
647  
648 46 ▶ if ($o->{CONFIG}{_TESTING}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"CONFIG"}{"_TESTING"}) 13 33 46
649 13 my $file = "$dir/void_test";
650 13 ▶ if (! -f $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $file) 2 11 13
651 2 ▶ warn "$file: $!" if !open(TEST_FH, '>', $file);
Branch: 1 branch
BranchTrueFalseTotal
unless open TEST_FH, ">", $file 0 2 2
652 2 ▶ warn "$file: $!" if !close(TEST_FH);
Branch: 1 branch
BranchTrueFalseTotal
unless close TEST_FH 0 2 2
653 }
654 }
655  
656 46 my ($pkg, $module) = @{$o->{API}}{qw(pkg module)};
657 my $prefix = (
658 ($o->{ILSM}{XS}{PREFIX})
659 46 ▶ ? "PREFIX = $o->{ILSM}{XS}{PREFIX}"
Branch: 1 branch
BranchTrueFalseTotal
$o->{'ILSM'}{'XS'}{'PREFIX'} ? : 2 44 46
660 : ''
661 );
662  
663 my $prototypes = defined($o->{CONFIG}{PROTOTYPES})
664 ? $o->{CONFIG}{PROTOTYPES}
665 46 ▶ : 'DISABLE';
Branch: 1 branch
BranchTrueFalseTotal
defined $o->{'CONFIG'}{'PROTOTYPES'} ? : 2 44 46
666  
667 46 my $XS = <<END;
668  
669 MODULE = $module PACKAGE = $pkg $prefix
670  
671 PROTOTYPES: $prototypes
672  
673 END
674  
675 46 my $parser = $o->{ILSM}{parser};
676 46 my $data = $parser->{data};
677  
678 warn(
679 "Warning. No Inline C functions bound to Perl in ", $o->{API}{script},
680 "\n" .
681 "Check your C function definition(s) for Inline compatibility\n\n"
682 46 ▶ ) if ((not defined$data->{functions}) and ($^W));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $data->{"functions"} and $^W 0 46 46
Condition33%1/3
not defined $data->{"functions"} and $^W
!ll&&!rl&&r
4600
MC/DC0%0/2
not defined $data->{"functions"} and $^W
not defined $data->{"functions"} $^W
Truth table33%1/3
not(A) and B
A= not defined $data->{"functions"}B= $^W
ABresult
0X0
100
111
683  
684 46 for my $function (@{$data->{functions}}) {
685 77 my $return_type = $data->{function}->{$function}->{return_type};
686 77 my @arg_names = @{$data->{function}->{$function}->{arg_names}};
687 77 my @arg_types = @{$data->{function}->{$function}->{arg_types}};
688  
689 77 $XS .= join '', (
690 "\n$return_type\n$function (",
691 join(', ', @arg_names), ")\n"
692 );
693  
694 77 for my $arg_name (@arg_names) {
695 60 my $arg_type = shift @arg_types;
696 60 ▶ last if $arg_type eq '...';
Branch: 1 branch
BranchTrueFalseTotal
if $arg_type eq "..." 0 60 60
697 60 $XS .= "\t$arg_type\t$arg_name\n";
698 }
699  
700 77 my %h;
701 77 ▶ if (defined($o->{CONFIG}{PROTOTYPE})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o->{"CONFIG"}{"PROTOTYPE"}) 2 75 77
702 2 %h = %{$o->{CONFIG}{PROTOTYPE}};
703 }
704  
705 77 ▶ if (defined($h{$function})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h{$function}) 2 75 77
706 2 $XS .= " PROTOTYPE: $h{$function}\n";
707 }
708  
709 77 my $listargs = '';
710 77 ▶ $listargs = pop @arg_names
Branch: 1 branch
BranchTrueFalseTotal
if @arg_names and $arg_names[-1] eq "..." 0 77 77
Condition66%2/3
@arg_names and $arg_names[-1] eq "..."
!ll&&!rl&&r
35420
MC/DC0%0/2
@arg_names and $arg_names[-1] eq "..."
@arg_names $arg_names[-1] eq "..."
Truth table66%2/3
A and B
A= @arg_namesB= $arg_names[-1] eq "..."
ABresult
0X0
100
111
711 if (@arg_names and $arg_names[-1] eq '...');
712 77 my $arg_name_list = join(', ', @arg_names);
713  
714 77 ▶ if ($return_type eq 'void') {
Branch: 2 branches
BranchTrueFalseTotal
if ($return_type eq 'void') { } 18 59 77
elsif ($listargs) { } 0 59 59
715 18 ▶ if ($o->{CONFIG}{_TESTING}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{'CONFIG'}{'_TESTING'}) { } 10 8 18
716 10 $XS .= <<END;
717 PREINIT:
718 PerlIO* stream;
719 I32* temp;
720 PPCODE:
721 temp = PL_markstack_ptr++;
722 $function($arg_name_list);
723 stream = PerlIO_open(\"$dir/void_test\", \"a\");
724 if (stream == NULL) warn(\"%s\\n\", \"Unable to open $dir/void_test for appending\");
725 if (PL_markstack_ptr != temp) {
726 PerlIO_printf(stream, \"%s\\n\", \"TRULY_VOID\");
727 PerlIO_close(stream);
728 PL_markstack_ptr = temp;
729 XSRETURN_EMPTY; /* return empty stack */
730 }
731 PerlIO_printf(stream, \"%s\\n\", \"LIST_CONTEXT\");
732 PerlIO_close(stream);
733 return; /* assume stack size is correct */
734 END
735 }
736 else {
737 8 $XS .= <<END;
738 PREINIT:
739 I32* temp;
740 PPCODE:
741 temp = PL_markstack_ptr++;
742 $function($arg_name_list);
743 if (PL_markstack_ptr != temp) {
744 /* truly void, because dXSARGS not invoked */
745 PL_markstack_ptr = temp;
746 XSRETURN_EMPTY; /* return empty stack */
747 }
748 /* must have used dXSARGS; list context implied */
749 return; /* assume stack size is correct */
750 END
751 }
752 }
753 elsif ($listargs) {
754 0 $XS .= <<END;
755 PREINIT:
756 I32* temp;
757 CODE:
758 temp = PL_markstack_ptr++;
759 RETVAL = $function($arg_name_list);
760 PL_markstack_ptr = temp;
761 OUTPUT:
762 RETVAL
763 END
764 }
765 }
766 46 $XS .= "\n";
767 46 return $XS;
768 }
769  
770 #==============================================================================
771 # Generate the INLINE.h file.
772 #==============================================================================
773 sub write_Inline_headers {
774 47 ▶ my $o = shift;
Subroutine write_Inline_headers: called CC=2 SCAR=7.0
Pod undocumented
775  
776 47 ▶ open HEADER, "> ".File::Spec->catfile($o->{API}{build_dir},"INLINE.h")
Branch: 1 branch
BranchTrueFalseTotal
open HEADER, '> ' . "File::Spec"->catfile($o->{"API"}{"build_dir"}, "INLINE.h") or croak() 0 47 47
777 or croak;
778  
779 47 print HEADER <<'END';
780 #define Inline_Stack_Vars dXSARGS
781 #define Inline_Stack_Items items
782 #define Inline_Stack_Item(x) ST(x)
783 #define Inline_Stack_Reset sp = mark
784 #define Inline_Stack_Push(x) XPUSHs(x)
785 #define Inline_Stack_Done PUTBACK
786 #define Inline_Stack_Return(x) XSRETURN(x)
787 #define Inline_Stack_Void XSRETURN(0)
788  
789 #define INLINE_STACK_VARS Inline_Stack_Vars
790 #define INLINE_STACK_ITEMS Inline_Stack_Items
791 #define INLINE_STACK_ITEM(x) Inline_Stack_Item(x)
792 #define INLINE_STACK_RESET Inline_Stack_Reset
793 #define INLINE_STACK_PUSH(x) Inline_Stack_Push(x)
794 #define INLINE_STACK_DONE Inline_Stack_Done
795 #define INLINE_STACK_RETURN(x) Inline_Stack_Return(x)
796 #define INLINE_STACK_VOID Inline_Stack_Void
797  
798 #define inline_stack_vars Inline_Stack_Vars
799 #define inline_stack_items Inline_Stack_Items
800 #define inline_stack_item(x) Inline_Stack_Item(x)
801 #define inline_stack_reset Inline_Stack_Reset
802 #define inline_stack_push(x) Inline_Stack_Push(x)
803 #define inline_stack_done Inline_Stack_Done
804 #define inline_stack_return(x) Inline_Stack_Return(x)
805 #define inline_stack_void Inline_Stack_Void
806 END
807  
808 47 close HEADER;
809 }
810  
811 #==============================================================================
812 # Generate the Makefile.PL
813 #==============================================================================
814 sub write_Makefile_PL {
815 47 ▶ my $o = shift;
Subroutine write_Makefile_PL: called CC=4 SCAR=13.9
Pod undocumented
816 47 $o->{ILSM}{xsubppargs} = '';
817 47 my $i = 0;
818 47 for (@{$o->{ILSM}{MAKEFILE}{TYPEMAPS}}) {
819 93 $o->{ILSM}{xsubppargs} .= "-typemap \"$_\" ";
820 }
821  
822 my %options = (
823 VERSION => $o->{API}{version} || '0.00',
824 47 %{$o->{ILSM}{MAKEFILE}},
825 NAME => $o->{API}{module},
826 47 ▶ );
Condition50%1/2
$o->{'API'}{'version'} || '0.00'
l!l
047
MC/DC0%0/1
$o->{'API'}{'version'} || '0.00'
$o->{'API'}{'version'}
Truth table50%1/2
A
A= $o->{'API'}{'version'}
Aresult
11
00
827  
828 47 ▶ open MF, "> ".File::Spec->catfile($o->{API}{build_dir},"Makefile.PL")
Branch: 1 branch
BranchTrueFalseTotal
open MF, '> ' . "File::Spec"->catfile($o->{"API"}{"build_dir"}, "Makefile.PL") or croak() 0 47 47
829 or croak;
830  
831 47 print MF <<END;
832 use ExtUtils::MakeMaker;
833 my %options = %\{
834 END
835  
836 47 local $Data::Dumper::Terse = 1;
837 47 local $Data::Dumper::Indent = 1;
838 47 print MF Data::Dumper::Dumper(\ %options);
839  
840 47 print MF <<END;
841 \};
842 WriteMakefile(\%options);
843  
844 # Remove the Makefile dependency. Causes problems on a few systems.
845 sub MY::makefile { '' }
846 END
847 47 close MF;
848 }
849  
850 #==============================================================================
851 # Run the build process.
852 #==============================================================================
853 sub compile {
854 47 ▶ my $o = shift;
Subroutine compile: called CC=3 SCAR=11.0
Pod undocumented
855  
856 47 my $build_dir = $o->{API}{build_dir};
857 47 my $cwd = &cwd;
858 47 ▶ ($cwd) = $cwd =~ /(.*)/ if $o->UNTAINT;
Branch: 1 branch
BranchTrueFalseTotal
if $o->UNTAINT 4 43 47
859  
860 47 chdir $build_dir;
861 # Run these in an eval block, so that we get to chdir back to
862 # $cwd if there's a failure. (Ticket #81375.)
863 47 eval {
864 47 $o->call('makefile_pl', '"perl Makefile.PL"', 2);
865 47 $o->call('make', '"make"', 2);
866 46 $o->call('make_install', '"make install"', 2);
867 };
868 47 chdir $cwd;
869 47 ▶ die if $@; #Die now that we've done the chdir back to $cwd. (#81375)
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 46 47
870 46 $o->call('cleanup', 'Cleaning Up', 2);
871 }
872  
873 sub makefile_pl {
874 47 ▶ my ($o) = @_;
Subroutine makefile_pl: called CC=4 SCAR=15.0
Pod undocumented
875 47 my $perl;
876 -f ($perl = $Config::Config{perlpath})
877 47 ▶ or ($perl = $^X)
Branch: 1 branch
BranchTrueFalseTotal
-f ($perl = $Config::Config{"perlpath"}) or $perl = $^X or croak("Can't locate your perl binary") 0 47 47
Condition33%1/3
-f ($perl = $Config::Config{"perlpath"}) or $perl = $^X
l!l&&r!l&&!r
4700
MC/DC0%0/2
-f ($perl = $Config::Config{"perlpath"}) or $perl = $^X
-f ($perl = $Config::Config{"perlpath"}) $perl = $^X
Truth table33%1/3
A or B
A= -f ($perl = $Config::Config{"perlpath"})B= $perl = $^X
ABresult
1X1
011
000
878 or croak "Can't locate your perl binary";
879 47 ▶ $perl = qq{"$perl"} if $perl =~ m/\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $perl =~ /\s/ 0 47 47
880 47 $o->system_call("$perl Makefile.PL", 'out.Makefile_PL');
881 47 $o->fix_make;
882 }
883 sub make {
884 47 ▶ my ($o) = @_;
Subroutine make: called CC=4 SCAR=15.6
Pod documented
885 my $make = $o->{ILSM}{MAKE} || $Config::Config{make}
886 47 ▶ or croak "Can't locate your make binary";
Branch: 1 branch
BranchTrueFalseTotal
my $make = $o->{"ILSM"}{"MAKE"} || $Config::Config{"make"} or croak("Can't locate your make binary") 0 47 47
Condition33%1/3
$o->{'ILSM'}{'MAKE'} || $Config::Config{'make'}
l!l&&r!l&&!r
0470
MC/DC0%0/2
$o->{'ILSM'}{'MAKE'} || $Config::Config{'make'}
$o->{'ILSM'}{'MAKE'} $Config::Config{'make'}
Truth table33%1/3
A || B
A= $o->{'ILSM'}{'MAKE'}B= $Config::Config{'make'}
ABresult
1X1
011
000
887 local $ENV{MAKEFLAGS} = $ENV{MAKEFLAGS} =~ s/(--jobserver-fds=[\d,]+)//
888 47 ▶ if $ENV{MAKEFLAGS};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"MAKEFLAGS"} 47 0 47
889 47 $o->system_call("$make", 'out.make');
890 }
891 sub make_install {
892 46 ▶ my ($o) = @_;
Subroutine make_install: called CC=4 SCAR=15.2
Pod undocumented
893 my $make = $o->{ILSM}{MAKE} || $Config::Config{make}
894 46 ▶ or croak "Can't locate your make binary";
Branch: 1 branch
BranchTrueFalseTotal
my $make = $o->{"ILSM"}{"MAKE"} || $Config::Config{"make"} or croak("Can't locate your make binary") 0 46 46
Condition33%1/3
$o->{'ILSM'}{'MAKE'} || $Config::Config{'make'}
l!l&&r!l&&!r
0460
MC/DC0%0/2
$o->{'ILSM'}{'MAKE'} || $Config::Config{'make'}
$o->{'ILSM'}{'MAKE'} $Config::Config{'make'}
Truth table33%1/3
A || B
A= $o->{'ILSM'}{'MAKE'}B= $Config::Config{'make'}
ABresult
1X1
011
000
895 46 ▶ if ($ENV{MAKEFLAGS}) { # Avoid uninitialized warnings
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"MAKEFLAGS"}) 46 0 46
896 local $ENV{MAKEFLAGS} = $ENV{MAKEFLAGS} =~
897 46 s/(--jobserver-fds=[\d,]+)//;
898 }
899 46 $o->system_call("$make pure_install", 'out.make_install');
900 }
901 sub cleanup {
902 46 ▶ my ($o) = @_;
Subroutine cleanup: called CC=4 SCAR=14.0
Pod undocumented
903 my ($modpname, $modfname, $install_lib) =
904 46 @{$o->{API}}{qw(modpname modfname install_lib)};
905 46 ▶ if ($o->{API}{cleanup}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->{"API"}{"cleanup"}) 46 0 46
906 $o->rmpath(
907 46 File::Spec->catdir($o->{API}{directory},'build'),
908 $modpname
909 );
910 46 my $autodir = File::Spec->catdir($install_lib,'auto',$modpname);
911 46 my @files = ( ".packlist", map "$modfname.$_", qw( bs exp lib ) );
912 46 my @paths = grep { -e } map { File::Spec->catfile($autodir,$_) } @files;
913 46 ▶ unlink($_) || die "Can't delete file $_: $!" for @paths;
Branch: 1 branch
BranchTrueFalseTotal
unlink $_ or die "Can't delete file ${_}: $!" 0 46 46
914 }
915 }
916  
917 sub system_call {
918 140 ▶ my ($o, $cmd, $output_file) = @_;
Subroutine system_call: called CC=5 SCAR=16.2
Pod undocumented
919 my $build_noisy = defined $ENV{PERL_INLINE_BUILD_NOISY}
920 ? $ENV{PERL_INLINE_BUILD_NOISY}
921 140 ▶ : $o->{CONFIG}{BUILD_NOISY};
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'PERL_INLINE_BUILD_NOISY'} ? : 0 140 140
922 # test this functionality with:
923 #perl -MInline=C,Config,BUILD_NOISY,1,FORCE_BUILD,1 -e "use Inline C => q[void inline_warner() { int *x = 2; }]"
924 140 ▶ if (not $build_noisy) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($build_noisy) 140 0 140
925 140 $cmd = "$cmd > $output_file 2>&1";
926 }
927 140 ▶ ($cmd) = $cmd =~ /(.*)/ if $o->UNTAINT;
Branch: 1 branch
BranchTrueFalseTotal
if $o->UNTAINT 12 128 140
928 140 ▶ system($cmd) == 0
Branch: 1 branch
BranchTrueFalseTotal
system($cmd) == 0 or croak($o->build_error_message($cmd, $output_file, $build_noisy)) 1 139 140
929 or croak($o->build_error_message($cmd, $output_file, $build_noisy));
930 }
931  
932 sub build_error_message {
933 1 ▶ my ($o, $cmd, $output_file, $build_noisy) = @_;
Subroutine build_error_message: called CC=6 SCAR=18.3
Pod undocumented
934 1 my $build_dir = $o->{API}{build_dir};
935 1 my $output = '';
936 1 ▶ if (not $build_noisy and
Branch: 1 branch
BranchTrueFalseTotal
if (not $build_noisy and open OUTPUT, $output_file) 1 0 1
Condition33%1/3
not $build_noisy and open OUTPUT, $output_file
!ll&&!rl&&r
001
MC/DC0%0/2
not $build_noisy and open OUTPUT, $output_file
not $build_noisy open OUTPUT, $output_file
Truth table33%1/3
not(A) and B
A= not $build_noisyB= open OUTPUT, $output_file
ABresult
0X0
100
111
937 open(OUTPUT, $output_file)
938 ) {
939 1 local $/;
940 1 $output = <OUTPUT>;
941 1 close OUTPUT;
942 }
943  
944 1 my $errcode = $? >> 8;
945 1 $output .= <<END;
946  
947 A problem was encountered while attempting to compile and install your Inline
948 $o->{API}{language} code. The command that failed was:
949 \"$cmd\" with error code $errcode
950  
951 The build directory was:
952 $build_dir
953  
954 To debug the problem, cd to the build directory, and inspect the output files.
955  
956 END
957 1 ▶ if ($cmd =~ /^make >/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /^make >/) 1 0 1
958 1 for (sort keys %ENV) {
959 29 ▶ $output .= "Environment $_ = '$ENV{$_}'\n" if /^(?:MAKE|PATH)/;
Branch: 1 branch
BranchTrueFalseTotal
if /^(?:MAKE|PATH)/ 4 25 29
960 }
961 }
962 1 return $output;
963 }
964  
965 #==============================================================================
966 # This routine fixes problems with the MakeMaker Makefile.
967 #==============================================================================
968 30 my %fixes = (
969 INSTALLSITEARCH => 'install_lib',
970 INSTALLDIRS => 'installdirs',
971 XSUBPPARGS => 'xsubppargs',
972 INSTALLSITELIB => 'install_lib',
973 );
974  
975 sub fix_make {
976 30 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
977 47 ▶ my (@lines, $fix);
Subroutine fix_make: called CC=6 SCAR=18.0
Pod undocumented
978 47 my $o = shift;
979  
980 47 $o->{ILSM}{install_lib} = $o->{API}{install_lib};
981 47 $o->{ILSM}{installdirs} = 'site';
982  
983 47 ▶ open(MAKEFILE, '< Makefile')
Branch: 1 branch
BranchTrueFalseTotal
open MAKEFILE, "< Makefile" or croak("Can't open Makefile for input: $!\n") 0 47 47
984 or croak "Can't open Makefile for input: $!\n";
985 47 @lines = <MAKEFILE>;
986 47 close MAKEFILE;
987  
988 47 ▶ open(MAKEFILE, '> Makefile')
Branch: 1 branch
BranchTrueFalseTotal
open MAKEFILE, "> Makefile" or croak("Can't open Makefile for output: $!\n") 0 47 47
989 or croak "Can't open Makefile for output: $!\n";
990 47 for (@lines) {
991 49675 ▶ if (/^(\w+)\s*=\s*\S+.*$/ and
Branch: 1 branch
BranchTrueFalseTotal
if (/^(\w+)\s*=\s*\S+.*$/ and $fix = $fixes{$1}) { } 188 49487 49675
Condition100%3/3
/^(\w+)\s*=\s*\S+.*$/ and $fix = $fixes{$1}
!ll&&!rl&&r
407498738188
MC/DC100%2/2
/^(\w+)\s*=\s*\S+.*$/ and $fix = $fixes{$1}
/^(\w+)\s*=\s*\S+.*$/ $fix = $fixes{$1}
Truth table100%3/3
A and B
A= /^(\w+)\s*=\s*\S+.*$/B= $fix = $fixes{$1}
ABresult
0X0
100
111
992 $fix = $fixes{$1}
993 ) {
994 188 my $fixed = $o->{ILSM}{$fix};
995 188 print MAKEFILE "$1 = $fixed\n";
996 }
997 else {
998 49487 print MAKEFILE;
999 }
1000 }
1001 47 close MAKEFILE;
1002 }
1003  
1004 sub quote_space {
1005 # Do nothing if $ENV{NO_INSANE_DIRNAMES} is set
1006 18 ▶ return $_[0] if $ENV{NO_INSANE_DIRNAMES};
Subroutine quote_space: called CC=15 SCAR=27.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"NO_INSANE_DIRNAMES"} 1 17 18
1007  
1008 # If $_[0] contains one or more doublequote characters, assume
1009 # that whitespace has already been quoted as required. Hence,
1010 # do nothing other than immediately return $_[0] as is.
1011 # We currently don't properly handle tabs either, so we'll
1012 # do the same if $_[0] =~ /\t/.
1013 17 ▶ return $_[0] if ($_[0] =~ /"/ || $_[0] =~ /\t/);
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /"/ or $_[0] =~ /\t/ 2 15 17
Condition66%2/3
$_[0] =~ /"/ or $_[0] =~ /\t/
l!l&&r!l&&!r
2015
MC/DC50%1/2
$_[0] =~ /"/ or $_[0] =~ /\t/
$_[0] =~ /"/ $_[0] =~ /\t/
Truth table66%2/3
A or B
A= $_[0] =~ /"/B= $_[0] =~ /\t/
ABresult
1X1
011
000
1014  
1015 # We want to split on /\s\-I/ not /\-I/
1016 15 my @in = split /\s\-I/, $_[0];
1017 15 my $s = @in - 1;
1018 15 my %s;
1019 my %q;
1020  
1021 # First up, let's reinstate the ' ' characters that split
1022 # removed
1023 15 ▶ for (my $i = 0; $i < $s; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $s) 41 15 56
1024 41 $in[$i] .= ' ';
1025 }
1026  
1027 # This for{} block dies if it finds that any of the ' -I'
1028 # occurrences in $_[0] are part of a directory name.
1029 15 ▶ for (my $i = 1; $i < $s; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $s) 26 14 40
1030 26 my $t = $in[$i + 1];
1031 26 ▶ while ($t =~ /\s$/) {chop $t}
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /\s$/) 51 26 77
1032 26 ▶ die "Found a '", $in[$i], "-I", $t, "' directory.",
Branch: 1 branch
BranchTrueFalseTotal
if -d $in[$i] . '-I' . $t 1 25 26
1033 " INC Config argument is ambiguous.",
1034 " Please use doublequotes to signify your intentions"
1035 if -d ($in[$i] . "-I" . $t);
1036 }
1037  
1038 14 $s++; # Now the same as scalar(@in)
1039  
1040 # Remove (but also Keep track of the amount of) whitespace
1041 # at the end of each element of @in.
1042 14 ▶ for (my $i = 0; $i < $s; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $s) 50 14 64
1043 50 my $count = 0;
1044 50 ▶ while ($in[$i] =~ /\s$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in[$i] =~ /\s$/) 83 50 133
1045 83 chop $in[$i];
1046 83 $count++;
1047 }
1048 50 $s{$i} = $count;
1049 }
1050  
1051 # Note which elements of @in still contain whitespace. These
1052 # (and only these) elements will be quoted
1053 14 ▶ for (my $i = 0; $i < $s; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $s) 50 14 64
1054 50 ▶ $q{$i} = 1 if $in[$i] =~ /\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $in[$i] =~ /\s/ 9 41 50
1055 }
1056  
1057 # Reinstate the occurrences of '-I' that were removed by split(),
1058 # insert any quotes that are needed, reinstate the whitespace
1059 # that was removed earlier, then join() the array back together
1060 # again.
1061 14 ▶ for (my $i = 0; $i < $s; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $s) 50 14 64
1062 50 ▶ $in[$i] = '-I' . $in[$i] if $i;
Branch: 1 branch
BranchTrueFalseTotal
if $i 36 14 50
1063 50 ▶ $in[$i] = '"' . $in[$i] . '"' if $q{$i};
Branch: 1 branch
BranchTrueFalseTotal
if $q{$i} 9 41 50
1064 50 $in[$i] .= ' ' x $s{$i};
1065 }
1066  
1067 # Note: If there was no whitespace that needed quoting, the
1068 # original argument should not have changed in any way.
1069  
1070 14 my $out = join '', @in;
1071 14 $out =~ s/"\-I\s+\//"\-I\//g;
1072 14 $_[0] = $out;
1073 }
1074  
1075 #==============================================================================
1076 # This routine used by C/t/09parser to test that the expected parser is in use
1077 #==============================================================================
1078  
1079 sub _parser_test {
1080 14 ▶ my $dir = shift;
Subroutine _parser_test: called CC=3 SCAR=11.3
1081 14 my $file = "$dir/parser_id";
1082 14 ▶ warn "$file: $!" if !open(TEST_FH, '>>', $file);
Branch: 1 branch
BranchTrueFalseTotal
unless open TEST_FH, ">>", $file 0 14 14
1083 14 print TEST_FH $_[0];
1084 14 ▶ warn "$file: $!" if !close(TEST_FH);
Branch: 1 branch
BranchTrueFalseTotal
if not close TEST_FH 0 14 14
1085 }
1086  
1087 30 1;
↑ Summary blib/lib/Inline/C/Parser/RegExp.pm »