C2XS.pm

filter: Statementstmt 91.4% 311 / 340 Branchbran 77.0% 148 / 192 Conditioncond 88.8% 16 / 18 MC/DCmcdc 75.0% 9 / 12 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 1 totaltotal 86.2% 496 / 575 CC 112 SCAR 41.4
CC
112
Cov
86%
c2xs
92.7
_write_pm
25.9
_write_manifest
7.7
CRAP 62.6
« C2XS/Context.pm ↑ Summary
1 package InlineX::C2XS;
2 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 15 require Exporter;
8 15 our @ISA = qw(Exporter);
9  
10 15 our @EXPORT_OK = qw(c2xs context);
11  
12 15 our $VERSION = '0.26';
13 #$VERSION = eval $VERSION;
14  
15 15 ▶use InlineX::C2XS::Context;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 15 my $config_options;
18  
19 15 our @allowable_config_keys = ('AUTOWRAP', 'AUTO_INCLUDE', 'CODE', 'DIST', 'TYPEMAPS', 'LIBS', 'INC',
20 'WRITE_MAKEFILE_PL', 'BUILD_NOISY', 'BOOT', 'BOOT_F', 'EXPORT_ALL', 'EXPORT_OK_ALL', 'MANIF',
21 'EXPORT_TAGS_ALL', 'MAKE', 'PREFIX', 'PREREQ_PM', 'CCFLAGS', 'CCFLAGSEX', 'LD', 'LDDLFLAGS',
22 'MYEXTLIB', 'OPTIMIZE', 'PRE_HEAD', 'PROTOTYPE', 'PROTOTYPES', 'CC', 'SRC_LOCATION', 'T',
23 '_TESTING', 'USE', 'USING', 'WRITE_PM', 'VERSION');
24  
25 ##=========================##
26  
27 sub c2xs {
28 30 ▶ eval {require "Inline/C.pm"};
Subroutine c2xs: called CC=75 SCAR=45.3
Pod undocumented
29 30 ▶ if($@) {die "Need a functioning Inline::C (version 0.46_01 or later). $@"}
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 30 30
30 30 my $module = shift;
31 30 my $pkg = shift;
32  
33 # Set the default for $build_dir.
34 # (This will be overwritten by a supplied build_dir argument.)
35 30 my $build_dir = '.';
36  
37 30 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 30 0 30
38 30 ▶ if(ref($_[0]) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'HASH') { } 12 18 30
39 12 $config_options = shift;
40 # Check for invalid config options - and die if one is found
41 12 ▶ for(keys(%$config_options)) { die "$_ is an invalid config option" if !_check_config_keys($_)}
Branch: 1 branch
BranchTrueFalseTotal
unless _check_config_keys($_) 2 15 17
42 10 ▶ if(@_) {die "Incorrect usage - there should be no arguments to c2xs() after the hash reference"}
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 8 10
43 }
44 18 else {$build_dir = shift}
45 }
46  
47 26 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 16 10 26
48 16 ▶ if(ref($_[0]) ne "HASH") {die "Fourth arg to c2xs() needs to be a hash containing config options ... but it's not !!\n"}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] ne "HASH") 4 12 16
49 12 $config_options = shift;
50 # Check for invalid config options - and die if one is found
51 12 ▶ for(keys(%$config_options)) { die "$_ is an invalid config option" if !_check_config_keys($_)}
Branch: 1 branch
BranchTrueFalseTotal
unless _check_config_keys($_) 0 87 87
52 }
53  
54 22 ▶ unless(-d $build_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $build_dir) 2 20 22
55 2 die "$build_dir is not a valid directory";
56 }
57 20 my $modfname = (split /::/, $module)[-1];
58 20 ▶ my $need_inline_h = $config_options->{AUTOWRAP} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$config_options->{'AUTOWRAP'} ? : 10 10 20
59 20 my $code = '';
60 20 my $o;
61  
62 20 ▶ if(exists($config_options->{CODE}) && exists($config_options->{SRC_LOCATION})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config_options->{"CODE"} and exists $config_options->{"SRC_LOCATION"}) 2 18 20
Condition100%3/3
exists $config_options->{"CODE"} and exists $config_options->{"SRC_LOCATION"}
!ll&&!rl&&r
1442
MC/DC100%2/2
exists $config_options->{"CODE"} and exists $config_options->{"SRC_LOCATION"}
exists $config_options->{"CODE"} exists $config_options->{"SRC_LOCATION"}
Truth table100%3/3
A and B
A= exists $config_options->{"CODE"}B= exists $config_options->{"SRC_LOCATION"}
ABresult
0X0
100
111
63 2 die "You can provide either CODE *or* SRC_LOCATION arguments ... but not *both*";
64 }
65  
66 18 ▶ if(exists($config_options->{BOOT}) && exists($config_options->{BOOT_F})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config_options->{"BOOT"} and exists $config_options->{"BOOT_F"}) 0 18 18
Condition66%2/3
exists $config_options->{"BOOT"} and exists $config_options->{"BOOT_F"}
!ll&&!rl&&r
1620
MC/DC0%0/2
exists $config_options->{"BOOT"} and exists $config_options->{"BOOT_F"}
exists $config_options->{"BOOT"} exists $config_options->{"BOOT_F"}
Truth table66%2/3
A and B
A= exists $config_options->{"BOOT"}B= exists $config_options->{"BOOT_F"}
ABresult
0X0
100
111
67 0 die "You can provide either BOOT *or* BOOT_F arguments ... but not *both*";
68 }
69  
70 18 ▶ if(exists($config_options->{CODE})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $config_options->{'CODE'}) { } 4 14 18
elsif (exists $config_options->{'SRC_LOCATION'}) { } 4 10 14
71 4 $code = $config_options->{CODE};
72 4 ▶ if($code =~ /inline_stack_vars/i) {$need_inline_h = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ /inline_stack_vars/i) 0 4 4
73 }
74 elsif(exists($config_options->{SRC_LOCATION})) {
75 4 ▶ open(RD, "<", $config_options->{SRC_LOCATION}) or die "Can't open ", $config_options->{SRC_LOCATION}, " for reading: $!";
Branch: 1 branch
BranchTrueFalseTotal
open RD, "<", $config_options->{"SRC_LOCATION"} or die "Can't open ", $config_options->{"SRC_LOCATION"}, " for reading: $!" 2 2 4
76 2 ▶ while(<RD>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline RD)) 4 2 6
77 4 $code .= $_;
78 4 ▶ if($_ =~ /inline_stack_vars/i) {$need_inline_h = 1}
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /inline_stack_vars/i) 0 4 4
79 }
80 2 ▶ close(RD) or die "Can't close ", $config_options->{SRC_LOCATION}, " after reading: $!";
Branch: 1 branch
BranchTrueFalseTotal
close RD or die "Can't close ", $config_options->{"SRC_LOCATION"}, " after reading: $!" 0 2 2
81 }
82 else {
83 10 ▶ open(RD, "<", "src/$modfname.c") or die "Can't open src/${modfname}.c for reading: $!";
Branch: 1 branch
BranchTrueFalseTotal
open RD, "<", "src/$modfname.c" or die "Can't open src/$modfname.c for reading: $!" 0 10 10
84 10 ▶ while(<RD>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline RD)) 916 10 926
85 916 $code .= $_;
86 916 ▶ if($_ =~ /inline_stack_vars/i) {$need_inline_h = 1}
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /inline_stack_vars/i) 4 912 916
87 }
88 10 ▶ close(RD) or die "Can't close src/$modfname.c after reading: $!";
Branch: 1 branch
BranchTrueFalseTotal
close RD or die "Can't close src/$modfname.c after reading: $!" 0 10 10
89 }
90  
91 ## Initialise $o.
92 ## Many of these keys may not be needed for the purpose of this
93 ## specific exercise - but they shouldn't do any harm, so I'll
94 ## leave them in, just in case they're ever needed.
95 16 $o->{CONFIG}{BUILD_TIMERS} = 0;
96 16 $o->{CONFIG}{PRINT_INFO} = 0;
97 16 $o->{CONFIG}{USING} = [];
98 16 $o->{CONFIG}{WARNINGS} = 1;
99 16 $o->{CONFIG}{PRINT_VERSION} = 0;
100 16 $o->{CONFIG}{CLEAN_BUILD_AREA} = 0;
101 16 $o->{CONFIG}{GLOBAL_LOAD} = 0;
102 16 $o->{CONFIG}{DIRECTORY} = '';
103 16 $o->{CONFIG}{SAFEMODE} = -1;
104 16 $o->{CONFIG}{CLEAN_AFTER_BUILD} = 1;
105 16 $o->{CONFIG}{FORCE_BUILD} = 0;
106 16 $o->{CONFIG}{NAME} = '';
107 16 $o->{CONFIG}{_INSTALL_} = 0;
108 16 $o->{CONFIG}{WITH} = [];
109 16 $o->{CONFIG}{AUTONAME} = 1;
110 16 $o->{CONFIG}{REPORTBUG} = 0;
111 16 $o->{CONFIG}{UNTAINT} = 0;
112 16 $o->{CONFIG}{VERSION} = '';
113 16 $o->{CONFIG}{BUILD_NOISY} = 1;
114 16 $o->{INLINE}{ILSM_suffix} = $Config::Config{dlext};
115 16 $o->{INLINE}{ILSM_module} = 'Inline::C';
116 16 $o->{INLINE}{version} = $Inline::VERSION;
117 16 $o->{INLINE}{ILSM_type} = 'compiled';
118 16 $o->{INLINE}{DIRECTORY} = 'irrelevant_0';
119 16 $o->{INLINE}{object_ready} = 0;
120 16 $o->{INLINE}{md5} = 'irrelevant_1';
121 16 $o->{API}{modfname} = $modfname;
122 16 $o->{API}{script} = 'irrelevant_2';
123 16 $o->{API}{location} = 'irrelevant_3';
124 16 $o->{API}{language} = 'C';
125 16 $o->{API}{modpname} = 'irrelevant_4';
126 16 $o->{API}{directory} = 'irrelevant_5';
127 16 $o->{API}{install_lib} = 'irrelevant_6';
128 16 $o->{API}{build_dir} = $build_dir;
129 16 $o->{API}{language_id} = 'C';
130 16 $o->{API}{pkg} = $pkg;
131 16 $o->{API}{suffix} = $Config::Config{dlext};
132 16 $o->{API}{cleanup} = 1;
133 16 $o->{API}{module} = $module;
134 16 $o->{API}{code} = $code;
135  
136 16 ▶ if(exists($config_options->{PROTOTYPE})) {$o->{CONFIG}{PROTOTYPE} = $config_options->{PROTOTYPE}}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config_options->{"PROTOTYPE"}) 0 16 16
137  
138 16 ▶ if(exists($config_options->{PROTOTYPES})) {$o->{CONFIG}{PROTOTYPES} = $config_options->{PROTOTYPES}}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config_options->{"PROTOTYPES"}) 0 16 16
139  
140 16 ▶ if(exists($config_options->{BUILD_NOISY})) {$o->{CONFIG}{BUILD_NOISY} = $config_options->{BUILD_NOISY}}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config_options->{"BUILD_NOISY"}) 2 14 16
141  
142 16 ▶ if(exists($config_options->{_TESTING})) {$o->{CONFIG}{_TESTING} = $config_options->{_TESTING}} # Internal testing flag
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config_options->{"_TESTING"}) 0 16 16
143  
144 16 ▶ if($config_options->{AUTOWRAP}) {$o->{ILSM}{AUTOWRAP} = 1}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"AUTOWRAP"}) 10 6 16
145  
146 16 ▶ if($config_options->{BOOT}) {$o->{ILSM}{XS}{BOOT} = $config_options->{BOOT}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"BOOT"}) 2 14 16
147  
148 16 ▶ if($config_options->{DIST}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"DIST"}) 1 15 16
149 1 $config_options->{WRITE_MAKEFILE_PL} = 1;
150 1 $config_options->{WRITE_PM} = 1;
151 1 $config_options->{MANIF} = 1;
152 1 $config_options->{T} = 1;
153 }
154  
155 16 ▶ if($config_options->{BOOT_F}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"BOOT_F"}) 0 16 16
156 0 my $code;
157 0 ▶ open(RD, "<", $config_options->{BOOT_F}) or die "Can't open ", $config_options->{BOOT_F}, " for reading: $!";
Branch: 1 branch
BranchTrueFalseTotal
open RD, "<", $config_options->{"BOOT_F"} or die "Can't open ", $config_options->{"BOOT_F"}, " for reading: $!" 0 0 0
158 0 ▶ while(<RD>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline RD)) 0 0 0
159 0 $code .= $_;
160 0 ▶ if($_ =~ /inline_stack_vars/i) {$need_inline_h = 1}
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /inline_stack_vars/i) 0 0 0
161 }
162 0 ▶ close(RD) or die "Can't close ", $config_options->{BOOT_F}, " after reading: $!";
Branch: 1 branch
BranchTrueFalseTotal
close RD or die "Can't close ", $config_options->{"BOOT_F"}, " after reading: $!" 0 0 0
163 0 $o->{ILSM}{XS}{BOOT} = $code;
164 }
165  
166 # This is what Inline::C does with the MAKE parameter ... so we'll do the same.
167 # Not sure that this achieves anything in the context of InlineX::C2XS.
168 16 ▶ if($config_options->{MAKE}) {$o->{ILSM}{MAKE} = $config_options->{MAKE}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"MAKE"}) 2 14 16
169  
170 16 ▶ if(exists($config_options->{TYPEMAPS})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config_options->{'TYPEMAPS'}) { } 12 4 16
171 12 my $val =$config_options->{TYPEMAPS};
172 12 ▶ if(ref($val) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq 'ARRAY') { } 9 3 12
173 9 for(@{$val}) {
174 9 ▶ die "Couldn't locate the typemap $_" unless -f $_;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_ 2 7 9
175 }
176 7 $o->{ILSM}{MAKEFILE}{TYPEMAPS} = $val;
177 }
178 else {
179 3 my @vals = split /\s+/, $val;
180 3 for(@vals) {
181 3 ▶ die "Couldn't locate the typemap $_" unless -f $_;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_ 0 3 3
182 }
183 3 $o->{ILSM}{MAKEFILE}{TYPEMAPS} = \@vals;
184 }
185 }
186 else {
187 4 $o->{ILSM}{MAKEFILE}{TYPEMAPS} = [];
188 }
189  
190 14 my @uncorrupted_typemaps = @{$o->{ILSM}{MAKEFILE}{TYPEMAPS}};
191  
192 14 ▶ if($config_options->{LIBS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"LIBS"}) 2 12 14
193 2 $o->{ILSM}{MAKEFILE}{LIBS} = $config_options->{LIBS};
194 }
195  
196 14 ▶ if($config_options->{PREFIX}) {$o->{ILSM}{XS}{PREFIX} = $config_options->{PREFIX}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"PREFIX"}) 2 12 14
197  
198 14 bless($o, 'Inline::C');
199  
200 14 Inline::C::validate($o);
201  
202 14 ▶ if($config_options->{PRE_HEAD}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"PRE_HEAD"}) 2 12 14
203 2 my $v = $config_options->{PRE_HEAD};
204 #{ # open scope
205 # no warnings 'newline';
206 2 ▶ unless( -f $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $v) { } 1 1 2
207 1 $o->{ILSM}{AUTO_INCLUDE} = $v . "\n" . $o->{ILSM}{AUTO_INCLUDE};
208 }
209 else {
210 1 my $insert;
211 1 ▶ open RD, '<', $v or die "Couldn't open $v for reading: $!";
Branch: 1 branch
BranchTrueFalseTotal
open RD, "<", $v or die "Couldn't open $v for reading: $!" 0 1 1
212 1 ▶ while(<RD>) {$insert .= $_}
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline RD)) 5 1 6
213 1 ▶ close RD or die "Couldn't close $v after reading: $!";
Branch: 1 branch
BranchTrueFalseTotal
close RD or die "Couldn't close $v after reading: $!" 0 1 1
214 1 $o->{ILSM}{AUTO_INCLUDE} = $insert . "\n" . $o->{ILSM}{AUTO_INCLUDE};
215 }
216 #} # close scope
217 }
218  
219 14 ▶ if($config_options->{AUTO_INCLUDE}) {$o->{ILSM}{AUTO_INCLUDE} .= $config_options->{AUTO_INCLUDE} . "\n"}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"AUTO_INCLUDE"}) 10 4 14
220  
221 14 ▶ if($config_options->{CC}) {$o->{ILSM}{MAKEFILE}{CC} = $config_options->{CC}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"CC"}) 2 12 14
222  
223 14 ▶ if($config_options->{CCFLAGS}) {$o->{ILSM}{MAKEFILE}{CCFLAGS} = " " . $config_options->{CCFLAGS}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"CCFLAGS"}) 2 12 14
224  
225 14 ▶ if($config_options->{CCFLAGSEX}) {$o->{ILSM}{MAKEFILE}{CCFLAGS} = $Config{ccflags} . " "
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"CCFLAGSEX"}) 0 14 14
226 0 . $config_options->{CCFLAGSEX}}
227  
228 14 ▶ if(exists($config_options->{INC})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config_options->{'INC'}) { } 10 4 14
229 10 ▶ if(ref($config_options->{INC}) eq 'ARRAY') {$o->{ILSM}{MAKEFILE}{INC} = join ' ', @{$config_options->{INC}};}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $config_options->{'INC'} eq 'ARRAY') { } 0 10 10
230 10 else {$o->{ILSM}{MAKEFILE}{INC} = $config_options->{INC};}
231 }
232 4 else {$o->{ILSM}{MAKEFILE}{INC} = ''}
233  
234 14 my $uncorrupted_inc = $o->{ILSM}{MAKEFILE}{INC};
235  
236 14 ▶ if($config_options->{LD}) {$o->{ILSM}{MAKEFILE}{LD} = " " . $config_options->{LD}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"LD"}) 2 12 14
237  
238 14 ▶ if($config_options->{PREREQ_PM}) {$o->{ILSM}{MAKEFILE}{PREREQ_PM} = $config_options->{PREREQ_PM}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"PREREQ_PM"}) 1 13 14
239  
240 14 ▶ if($config_options->{LDDLFLAGS}) {$o->{ILSM}{MAKEFILE}{LDDLFLAGS} = " " . $config_options->{LDDLFLAGS}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"LDDLFLAGS"}) 2 12 14
241  
242 # Here, we'll add the MAKE parameter to $o->{ILSM}{MAKEFILE}{MAKE} ... which
243 # could be useful (given that recent versions of Extutils::MakeMaker now recognise it):
244 14 ▶ if($config_options->{MAKE}) {$o->{ILSM}{MAKEFILE}{MAKE} = $config_options->{MAKE}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"MAKE"}) 2 12 14
245  
246 14 ▶ if($config_options->{MYEXTLIB}) {$o->{ILSM}{MAKEFILE}{MYEXTLIB} = " " . $config_options->{MYEXTLIB}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"MYEXTLIB"}) 2 12 14
247  
248 14 ▶ if($config_options->{OPTIMIZE}) {$o->{ILSM}{MAKEFILE}{OPTIMIZE} = " " . $config_options->{OPTIMIZE}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"OPTIMIZE"}) 2 12 14
249  
250 14 ▶ if($config_options->{USING}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"USING"}) 5 9 14
251 5 my $val = $config_options->{USING};
252 5 ▶ if(ref($val) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq 'ARRAY') { } 4 1 5
253 4 $o->{CONFIG}{USING} = $val;
254 }
255 else {
256 1 $o->{CONFIG}{USING} = [$val];
257 }
258 5 Inline::push_overrides($o);
259 }
260  
261 14 ▶ if(!$need_inline_h) {$o->{ILSM}{AUTO_INCLUDE} =~ s/#include "INLINE\.h"//i}
Branch: 1 branch
BranchTrueFalseTotal
unless ($need_inline_h) 2 12 14
262  
263 14 _build($o, $need_inline_h);
264  
265 14 ▶ if($config_options->{WRITE_MAKEFILE_PL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"WRITE_MAKEFILE_PL"}) 3 11 14
266 3 $o->{ILSM}{MAKEFILE}{INC} = $uncorrupted_inc; # Make sure cwd is included only if it was specified.
267 3 $o->{ILSM}{MAKEFILE}{TYPEMAPS} = \@uncorrupted_typemaps; # Otherwise the standard perl typemap gets included ... annoying.
268 3 ▶ if($config_options->{VERSION}) {$o->{API}{version} = $config_options->{VERSION}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{'VERSION'}) { } 3 0 3
269 0 else {warn "'VERSION' being set to '0.00' in the Makefile.PL. Did you supply a correct version number to c2xs() ?"}
270 3 print "Writing Makefile.PL in the ", $o->{API}{build_dir}, " directory\n";
271 3 $o->call('write_Makefile_PL', 'Build Glue 3');
272 }
273  
274 14 ▶ if($config_options->{WRITE_PM}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"WRITE_PM"}) 4 10 14
275 4 ▶ if($config_options->{VERSION}) {$o->{API}{version} = $config_options->{VERSION}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{'VERSION'}) { } 4 0 4
276 else {
277 0 warn "'\$VERSION' being set to '0.00' in ", $o->{API}{modfname}, ".pm. Did you supply a correct version number to c2xs() ?";
278 0 $o->{API}{version} = '0.00';
279 }
280 4 _write_pm($o);
281 }
282  
283 14 ▶ if($config_options->{MANIF}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"MANIF"}) 1 13 14
284 1 _write_manifest($modfname, $build_dir, $config_options, $need_inline_h);
285 }
286  
287 14 ▶ if($config_options->{T}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"T"}) 1 13 14
288 1 _write_test_script($module, $build_dir);
289 }
290 }
291  
292 ##=========================##
293  
294 sub _build {
295 14 ▶ my $o = shift;
Subroutine _build: called CC=2 SCAR=6.9
296 14 my $need_inline_headers = shift;
297  
298 14 $o->call('preprocess', 'Build Preprocess');
299 14 $o->call('parse', 'Build Parse');
300  
301 14 print "Writing ", $o->{API}{modfname}, ".xs in the ", $o->{API}{build_dir}, " directory\n";
302 14 $o->call('write_XS', 'Build Glue 1');
303  
304 14 ▶ if($need_inline_headers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_inline_headers) 12 2 14
305 12 print "Writing INLINE.h in the ", $o->{API}{build_dir}, " directory\n";
306 12 $o->call('write_Inline_headers', 'Build Glue 2');
307 }
308 }
309  
310 ##=========================##
311  
312 sub _check_config_keys {
313 104 ▶ for(@allowable_config_keys) {
Subroutine _check_config_keys: called CC=3 SCAR=11.0
314 1453 ▶ return 1 if $_ eq $_[0]; # it's a valid config option
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $_[0] 102 1351 1453
315 }
316 2 return 0; # it's an invalid config option
317 }
318  
319 ##=========================##
320  
321 sub _write_pm {
322 4 ▶ my $o = shift;
Subroutine _write_pm: called CC=25 SCAR=32.5
323 4 my $offset = 4;
324 4 my $max = 100;
325 4 my $length = $offset;
326 4 my @use;
327  
328 4 ▶ if($config_options->{USE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"USE"}) 3 1 4
329 die "Value supplied to config option USE must be an array reference"
330 3 ▶ if ref($config_options->{USE}) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $config_options->{"USE"} ne "ARRAY" 0 3 3
331 3 @use = @{$config_options->{USE}};
332 }
333  
334 4 ▶ open(WR, '>', $o->{API}{build_dir} . '/' . $o->{API}{modfname} . ".pm")
Branch: 1 branch
BranchTrueFalseTotal
open WR, ">", $o->{"API"}{"build_dir"} . '/' . $o->{"API"}{"modfname"} . '.pm' or die "Couldn't create the .pm file: $!" 0 4 4
335 or die "Couldn't create the .pm file: $!";
336 4 print "Writing ", $o->{API}{modfname}, ".pm in the ", $o->{API}{build_dir}, " directory\n";
337 4 print WR "## This file generated by InlineX::C2XS (version ",
338 $InlineX::C2XS::VERSION, ") using Inline::C (version ", $Inline::C::VERSION, ")\n";
339 4 print WR "package ", $o->{API}{module}, ";\n";
340 4 for(@use) {
341 3 print WR "use ${_};\n";
342 }
343 4 print WR "\n";
344 4 print WR "require Exporter;\n*import = \\&Exporter::import;\nrequire DynaLoader;\n\n";
345 # Switch to xdg's recommendation for assigning version number
346 #print WR "\$", $o->{API}{module}, "::VERSION = '", $o->{API}{version}, "';\n\n";
347 4 print WR "our \$VERSION = '", $o->{API}{version}, "';\n\$VERSION = eval \$VERSION;\n";
348 4 print WR "DynaLoader::bootstrap ", $o->{API}{module}, " \$VERSION;\n\n";
349  
350 4 ▶ unless($config_options->{EXPORT_ALL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{'EXPORT_ALL'}) { } 1 3 4
351 3 print WR "\@", $o->{API}{module}, "::EXPORT = ();\n";
352 }
353 else {
354 1 print WR "\@", $o->{API}{module}, "::EXPORT = qw(\n";
355 1 for(@{$o->{ILSM}{parser}{data}{functions}}) {
356 8 ▶ if ($_ =~ /^_/ && $_ !~ /^__/) {next}
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^_/ and not $_ =~ /^__/) 4 4 8
Condition100%3/3
$_ =~ /^_/ and not $_ =~ /^__/
!ll&&!rl&&r
314
MC/DC100%2/2
$_ =~ /^_/ and not $_ =~ /^__/
$_ =~ /^_/ not $_ =~ /^__/
Truth table100%3/3
A and not(B)
A= $_ =~ /^_/B= not $_ =~ /^__/
ABresult
0X0
100
111
357 4 my $l = length($_);
358 4 ▶ if($length + $l > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length + $l > $max) 0 4 4
359 0 print WR "\n", " " x $offset, "$_ ";
360 0 $length = $offset + $l + 1;
361 }
362 4 ▶ if($length == $offset) {print WR " " x $offset, "$_ "}
Branch: 1 branch
BranchTrueFalseTotal
if ($length == $offset) { } 1 3 4
363 3 else {print WR "$_ " }
364 4 $length += $l + 1;
365 }
366 1 print WR "\n", " " x $offset, ");\n\n";
367 1 $length = $offset;
368 }
369  
370 4 ▶ unless($config_options->{EXPORT_OK_ALL} || $config_options->{EXPORT_TAGS_ALL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{'EXPORT_OK_ALL'} or $config_options->{'EXPORT_TAGS_ALL'}) { } 1 3 4
Condition66%2/3
$config_options->{"EXPORT_OK_ALL"} or $config_options->{"EXPORT_TAGS_ALL"}
l!l&&r!l&&!r
103
MC/DC50%1/2
$config_options->{"EXPORT_OK_ALL"} or $config_options->{"EXPORT_TAGS_ALL"}
$config_options->{"EXPORT_OK_ALL"} $config_options->{"EXPORT_TAGS_ALL"}
Truth table66%2/3
A or B
A= $config_options->{"EXPORT_OK_ALL"}B= $config_options->{"EXPORT_TAGS_ALL"}
ABresult
1X1
011
000
371 3 print WR "\@", $o->{API}{module}, "::EXPORT_OK = ();\n\n";
372 }
373 else {
374 1 print WR "\@", $o->{API}{module}, "::EXPORT_OK = qw(\n";
375 1 for(@{$o->{ILSM}{parser}{data}{functions}}) {
376 8 ▶ if ($_ =~ /^_/ && $_ !~ /^__/) {next}
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^_/ and not $_ =~ /^__/) 4 4 8
Condition100%3/3
$_ =~ /^_/ and not $_ =~ /^__/
!ll&&!rl&&r
314
MC/DC100%2/2
$_ =~ /^_/ and not $_ =~ /^__/
$_ =~ /^_/ not $_ =~ /^__/
Truth table100%3/3
A and not(B)
A= $_ =~ /^_/B= not $_ =~ /^__/
ABresult
0X0
100
111
377 4 my $l = length($_);
378 4 ▶ if($length + $l > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length + $l > $max) 0 4 4
379 0 print WR "\n", " " x $offset, "$_ ";
380 0 $length = $offset + $l + 1;
381 }
382 4 ▶ if($length == $offset) {print WR " " x $offset, "$_ "}
Branch: 1 branch
BranchTrueFalseTotal
if ($length == $offset) { } 1 3 4
383 3 else {print WR "$_ " }
384 4 $length += $l + 1;
385 }
386 1 print WR "\n", " " x $offset, ");\n\n";
387 1 $length = $offset;
388 }
389  
390 4 ▶ if($config_options->{EXPORT_TAGS_ALL}){
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"EXPORT_TAGS_ALL"}) 1 3 4
391 1 print WR "\%", $o->{API}{module}, "::EXPORT_TAGS = (", $config_options->{EXPORT_TAGS_ALL}, " => [qw(\n";
392 1 for(@{$o->{ILSM}{parser}{data}{functions}}) {
393 8 ▶ if ($_ =~ /^_/ && $_ !~ /^__/) {next}
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^_/ and not $_ =~ /^__/) 4 4 8
Condition100%3/3
$_ =~ /^_/ and not $_ =~ /^__/
!ll&&!rl&&r
314
MC/DC100%2/2
$_ =~ /^_/ and not $_ =~ /^__/
$_ =~ /^_/ not $_ =~ /^__/
Truth table100%3/3
A and not(B)
A= $_ =~ /^_/B= not $_ =~ /^__/
ABresult
0X0
100
111
394 4 my $l = length($_);
395 4 ▶ if($length + $l > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length + $l > $max) 0 4 4
396 0 print WR "\n", " " x $offset, "$_ ";
397 0 $length = $offset + $l + 1;
398 }
399 4 ▶ if($length == $offset) {print WR " " x $offset, "$_ "}
Branch: 1 branch
BranchTrueFalseTotal
if ($length == $offset) { } 1 3 4
400 3 else {print WR "$_ " }
401 4 $length += $l + 1;
402 }
403 1 print WR "\n", " " x $offset, ")]);\n\n";
404 1 $length = $offset;
405 }
406  
407 4 print WR "sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking\n\n";
408 4 print WR "1;\n";
409 4 ▶ close(WR) or die "Couldn't close the .pm file after writing to it: $!";
Branch: 1 branch
BranchTrueFalseTotal
close WR or die "Couldn't close the .pm file after writing to it: $!" 0 4 4
410 }
411  
412 ##=========================##
413  
414 sub _write_manifest {
415 1 ▶ my $m = shift; # name of pm and xs files
Subroutine _write_manifest: called CC=7 SCAR=20.4
416 1 my $bd = shift; # build directory
417 1 my $c = shift; # config options
418 1 my $ih = shift; # INLINE.h is present ?
419  
420 1 print "Writing the MANIFEST file in the $bd directory\n";
421  
422 1 ▶ open WRM, '>', "$bd/MANIFEST" or die "Can't open MANIFEST for writing: $!";
Branch: 1 branch
BranchTrueFalseTotal
open WRM, ">", "$bd/MANIFEST" or die "Can't open MANIFEST for writing: $!" 0 1 1
423 1 print WRM "MANIFEST\n";
424 1 ▶ if($c->{WRITE_PM}) {print WRM "$m.pm\n"}
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"WRITE_PM"}) 1 0 1
425 1 ▶ if($ih) {print WRM "INLINE.h\n"}
Branch: 1 branch
BranchTrueFalseTotal
if ($ih) 0 1 1
426 1 print WRM "$m.xs\n";
427 1 ▶ if($c->{WRITE_MAKEFILE_PL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"WRITE_MAKEFILE_PL"}) 1 0 1
428 1 print WRM "Makefile.PL\n";
429 }
430 1 ▶ if($c->{T}){
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"T"}) 1 0 1
431 1 print WRM "t/00load.t\n";
432 }
433 1 ▶ close WRM or die "Can't close $bd/MANIFEST after writing: $!";
Branch: 1 branch
BranchTrueFalseTotal
close WRM or die "Can't close $bd/MANIFEST after writing: $!" 0 1 1
434 }
435  
436 ##=========================##
437  
438 sub _write_test_script {
439 15 ▶ use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
440 1 ▶ my $mod = $_[0];
Subroutine _write_test_script: called CC=5 SCAR=16.7
441 1 my $path = "$_[1]/t";
442 1 ▶ unless(-d $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $path) 1 0 1
443 1 ▶ if(!File::Path::make_path($path, {verbose => 1})) {die "Failed to create $path directory"};
Branch: 1 branch
BranchTrueFalseTotal
unless (File::Path::make_path($path, {"verbose", 1})) 0 1 1
444 }
445  
446 1 print "Writing 00load.t in the $path directory\n";
447 1 ▶ open WRT, '>', "$path/00load.t" or die "Couldn't open $path/00load.t for writing: $!";
Branch: 1 branch
BranchTrueFalseTotal
open WRT, ">", "$path/00load.t" or die "Couldn't open $path/00load.t for writing: $!" 0 1 1
448 1 print WRT "## This file auto-generated by InlineX-C2XS-" . $InlineX::C2XS::VERSION . "\n\n";
449 1 print WRT "use strict;\nuse warnings;\n\n";
450 1 print WRT "print \"1..1\\n\";\n\n";
451 1 print WRT "eval{require $mod;};\n";
452 1 print WRT "if(\$\@) {\n warn \"\\\$\\\@: \$\@\";\n print \"not ok 1\\n\";\n}\n";
453 1 print WRT "else {print \"ok 1\\n\"}\n";
454 1 ▶ close WRT or die "Couldn't close $path/00load.t after writing: $!";
Branch: 1 branch
BranchTrueFalseTotal
close WRT or die "Couldn't close $path/00load.t after writing: $!" 0 1 1
455 }
456  
457 ##=========================##
458  
459 15 *context = \&InlineX::C2XS::Context::apply_context_args;
460  
461 ##=========================##
462  
463 ##=========================##
464  
465 15 1;
466  
467 __END__
« C2XS/Context.pm ↑ Summary