C2XS.pm

filter: Statementstmt 91.5% 313 / 342 Branchbran 77.3% 150 / 194 Conditioncond 88.8% 16 / 18 MC/DCmcdc 75.0% 9 / 12 Subroutinesub 100% 12 / 12 Podpod 0.0% 0 / 1 totaltotal 86.3% 500 / 579 CC 113 SCAR 41.5
CC
113
Cov
86%
c2xs
93.6
_write_pm
25.9
_write_manifest
7.7
CRAP 63.4
« 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.27';
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', 'OBJECT', 'OPTIMIZE', 'PRE_HEAD', 'PROTOTYPE', 'PROTOTYPES', 'CC', 'SRC_LOCATION', 'T',
23 '_TESTING', 'USE', 'USING', 'WRITE_PM', 'VERSION');
24  
25 ##=========================##
26  
27 30 ▶sub c2xs {
Subroutine c2xs: called CC=76 SCAR=45.4
Pod undocumented
28 30 eval {require "Inline/C.pm"};
29 0 ▶ 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 89 89
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 0 ▶ 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 0 ▶ 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: $!" 2 0 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: $!" 10 0 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: $!" 10 0 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 0 ▶ 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 0 ▶ 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 0 ▶ 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: $!" 1 0 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: $!" 1 0 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->{OBJECT}) {$o->{ILSM}{MAKEFILE}{OBJECT} = $config_options->{OBJECT}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"OBJECT"}) 2 12 14
224  
225 14 ▶ if($config_options->{CCFLAGS}) {$o->{ILSM}{MAKEFILE}{CCFLAGS} = " " . $config_options->{CCFLAGS}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"CCFLAGS"}) 2 12 14
226  
227 14 ▶ if($config_options->{CCFLAGSEX}) {$o->{ILSM}{MAKEFILE}{CCFLAGS} = $Config{ccflags} . " "
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"CCFLAGSEX"}) 0 14 14
228 0 . $config_options->{CCFLAGSEX}}
229  
230 14 ▶ if(exists($config_options->{INC})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config_options->{'INC'}) { } 10 4 14
231 0 ▶ 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
232 10 else {$o->{ILSM}{MAKEFILE}{INC} = $config_options->{INC};}
233 }
234 4 else {$o->{ILSM}{MAKEFILE}{INC} = ''}
235  
236 14 my $uncorrupted_inc = $o->{ILSM}{MAKEFILE}{INC};
237  
238 14 ▶ if($config_options->{LD}) {$o->{ILSM}{MAKEFILE}{LD} = " " . $config_options->{LD}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"LD"}) 2 12 14
239  
240 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
241  
242 14 ▶ if($config_options->{LDDLFLAGS}) {$o->{ILSM}{MAKEFILE}{LDDLFLAGS} = " " . $config_options->{LDDLFLAGS}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"LDDLFLAGS"}) 2 12 14
243  
244 # Here, we'll add the MAKE parameter to $o->{ILSM}{MAKEFILE}{MAKE} ... which
245 # could be useful (given that recent versions of Extutils::MakeMaker now recognise it):
246 14 ▶ if($config_options->{MAKE}) {$o->{ILSM}{MAKEFILE}{MAKE} = $config_options->{MAKE}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"MAKE"}) 2 12 14
247  
248 14 ▶ if($config_options->{MYEXTLIB}) {$o->{ILSM}{MAKEFILE}{MYEXTLIB} = " " . $config_options->{MYEXTLIB}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"MYEXTLIB"}) 2 12 14
249  
250 14 ▶ if($config_options->{OPTIMIZE}) {$o->{ILSM}{MAKEFILE}{OPTIMIZE} = " " . $config_options->{OPTIMIZE}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"OPTIMIZE"}) 2 12 14
251  
252 14 ▶ if($config_options->{USING}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"USING"}) 5 9 14
253 5 my $val = $config_options->{USING};
254 5 ▶ if(ref($val) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $val eq 'ARRAY') { } 4 1 5
255 4 $o->{CONFIG}{USING} = $val;
256 }
257 else {
258 1 $o->{CONFIG}{USING} = [$val];
259 }
260 5 Inline::push_overrides($o);
261 }
262  
263 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
264  
265 14 _build($o, $need_inline_h);
266  
267 14 ▶ if($config_options->{WRITE_MAKEFILE_PL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"WRITE_MAKEFILE_PL"}) 3 11 14
268 3 $o->{ILSM}{MAKEFILE}{INC} = $uncorrupted_inc; # Make sure cwd is included only if it was specified.
269 3 $o->{ILSM}{MAKEFILE}{TYPEMAPS} = \@uncorrupted_typemaps; # Otherwise the standard perl typemap gets included ... annoying.
270 3 ▶ if($config_options->{VERSION}) {$o->{API}{version} = $config_options->{VERSION}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{'VERSION'}) { } 3 0 3
271 0 else {warn "'VERSION' being set to '0.00' in the Makefile.PL. Did you supply a correct version number to c2xs() ?"}
272 3 print "Writing Makefile.PL in the ", $o->{API}{build_dir}, " directory\n";
273 3 $o->call('write_Makefile_PL', 'Build Glue 3');
274 }
275  
276 14 ▶ if($config_options->{WRITE_PM}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"WRITE_PM"}) 4 10 14
277 4 ▶ if($config_options->{VERSION}) {$o->{API}{version} = $config_options->{VERSION}}
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{'VERSION'}) { } 4 0 4
278 else {
279 0 warn "'\$VERSION' being set to '0.00' in ", $o->{API}{modfname}, ".pm. Did you supply a correct version number to c2xs() ?";
280 0 $o->{API}{version} = '0.00';
281 }
282 4 _write_pm($o);
283 }
284  
285 14 ▶ if($config_options->{MANIF}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"MANIF"}) 1 13 14
286 1 _write_manifest($modfname, $build_dir, $config_options, $need_inline_h);
287 }
288  
289 14 ▶ if($config_options->{T}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"T"}) 1 13 14
290 1 _write_test_script($module, $build_dir);
291 }
292 }
293  
294 ##=========================##
295  
296 14 ▶sub _build {
Subroutine _build: called CC=2 SCAR=6.9
297 14 my $o = shift;
298 14 my $need_inline_headers = shift;
299  
300 14 $o->call('preprocess', 'Build Preprocess');
301 14 $o->call('parse', 'Build Parse');
302  
303 14 print "Writing ", $o->{API}{modfname}, ".xs in the ", $o->{API}{build_dir}, " directory\n";
304 14 $o->call('write_XS', 'Build Glue 1');
305  
306 14 ▶ if($need_inline_headers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($need_inline_headers) 12 2 14
307 12 print "Writing INLINE.h in the ", $o->{API}{build_dir}, " directory\n";
308 12 $o->call('write_Inline_headers', 'Build Glue 2');
309 }
310 }
311  
312 ##=========================##
313  
314 106 ▶sub _check_config_keys {
Subroutine _check_config_keys: called CC=3 SCAR=11.0
315 106 for(@allowable_config_keys) {
316 1530 ▶ return 1 if $_ eq $_[0]; # it's a valid config option
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $_[0] 104 1426 1530
317 }
318 2 return 0; # it's an invalid config option
319 }
320  
321 ##=========================##
322  
323 4 ▶sub _write_pm {
Subroutine _write_pm: called CC=25 SCAR=32.5
324 4 my $o = shift;
325 4 my $offset = 4;
326 4 my $max = 100;
327 4 my $length = $offset;
328 4 my @use;
329  
330 4 ▶ if($config_options->{USE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"USE"}) 3 1 4
331 die "Value supplied to config option USE must be an array reference"
332 3 ▶ if ref($config_options->{USE}) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $config_options->{"USE"} ne "ARRAY" 0 3 3
333 3 @use = @{$config_options->{USE}};
334 }
335  
336 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: $!" 4 0 4
337 or die "Couldn't create the .pm file: $!";
338 4 print "Writing ", $o->{API}{modfname}, ".pm in the ", $o->{API}{build_dir}, " directory\n";
339 4 print WR "## This file generated by InlineX::C2XS (version ",
340 $InlineX::C2XS::VERSION, ") using Inline::C (version ", $Inline::C::VERSION, ")\n";
341 4 print WR "package ", $o->{API}{module}, ";\n";
342 4 for(@use) {
343 3 print WR "use ${_};\n";
344 }
345 4 print WR "\n";
346 4 print WR "require Exporter;\n*import = \\&Exporter::import;\nrequire DynaLoader;\n\n";
347 # Switch to xdg's recommendation for assigning version number
348 #print WR "\$", $o->{API}{module}, "::VERSION = '", $o->{API}{version}, "';\n\n";
349 4 print WR "our \$VERSION = '", $o->{API}{version}, "';\n\$VERSION = eval \$VERSION;\n";
350 4 print WR "DynaLoader::bootstrap ", $o->{API}{module}, " \$VERSION;\n\n";
351  
352 4 ▶ unless($config_options->{EXPORT_ALL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{'EXPORT_ALL'}) { } 1 3 4
353 3 print WR "\@", $o->{API}{module}, "::EXPORT = ();\n";
354 }
355 else {
356 1 print WR "\@", $o->{API}{module}, "::EXPORT = qw(\n";
357 1 for(@{$o->{ILSM}{parser}{data}{functions}}) {
358 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
359 4 my $l = length($_);
360 4 ▶ if($length + $l > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length + $l > $max) 0 4 4
361 0 print WR "\n", " " x $offset, "$_ ";
362 0 $length = $offset + $l + 1;
363 }
364 4 ▶ if($length == $offset) {print WR " " x $offset, "$_ "}
Branch: 1 branch
BranchTrueFalseTotal
if ($length == $offset) { } 1 3 4
365 3 else {print WR "$_ " }
366 4 $length += $l + 1;
367 }
368 1 print WR "\n", " " x $offset, ");\n\n";
369 1 $length = $offset;
370 }
371  
372 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
373 3 print WR "\@", $o->{API}{module}, "::EXPORT_OK = ();\n\n";
374 }
375 else {
376 1 print WR "\@", $o->{API}{module}, "::EXPORT_OK = qw(\n";
377 1 for(@{$o->{ILSM}{parser}{data}{functions}}) {
378 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
379 4 my $l = length($_);
380 4 ▶ if($length + $l > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length + $l > $max) 0 4 4
381 0 print WR "\n", " " x $offset, "$_ ";
382 0 $length = $offset + $l + 1;
383 }
384 4 ▶ if($length == $offset) {print WR " " x $offset, "$_ "}
Branch: 1 branch
BranchTrueFalseTotal
if ($length == $offset) { } 1 3 4
385 3 else {print WR "$_ " }
386 4 $length += $l + 1;
387 }
388 1 print WR "\n", " " x $offset, ");\n\n";
389 1 $length = $offset;
390 }
391  
392 4 ▶ if($config_options->{EXPORT_TAGS_ALL}){
Branch: 1 branch
BranchTrueFalseTotal
if ($config_options->{"EXPORT_TAGS_ALL"}) 1 3 4
393 1 print WR "\%", $o->{API}{module}, "::EXPORT_TAGS = (", $config_options->{EXPORT_TAGS_ALL}, " => [qw(\n";
394 1 for(@{$o->{ILSM}{parser}{data}{functions}}) {
395 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
396 4 my $l = length($_);
397 4 ▶ if($length + $l > $max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length + $l > $max) 0 4 4
398 0 print WR "\n", " " x $offset, "$_ ";
399 0 $length = $offset + $l + 1;
400 }
401 4 ▶ if($length == $offset) {print WR " " x $offset, "$_ "}
Branch: 1 branch
BranchTrueFalseTotal
if ($length == $offset) { } 1 3 4
402 3 else {print WR "$_ " }
403 4 $length += $l + 1;
404 }
405 1 print WR "\n", " " x $offset, ")]);\n\n";
406 1 $length = $offset;
407 }
408  
409 4 print WR "sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking\n\n";
410 4 print WR "1;\n";
411 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: $!" 4 0 4
412 }
413  
414 ##=========================##
415  
416 1 ▶sub _write_manifest {
Subroutine _write_manifest: called CC=7 SCAR=20.4
417 1 my $m = shift; # name of pm and xs files
418 1 my $bd = shift; # build directory
419 1 my $c = shift; # config options
420 1 my $ih = shift; # INLINE.h is present ?
421  
422 1 print "Writing the MANIFEST file in the $bd directory\n";
423  
424 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: $!" 1 0 1
425 1 print WRM "MANIFEST\n";
426 1 ▶ if($c->{WRITE_PM}) {print WRM "$m.pm\n"}
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"WRITE_PM"}) 1 0 1
427 0 ▶ if($ih) {print WRM "INLINE.h\n"}
Branch: 1 branch
BranchTrueFalseTotal
if ($ih) 0 1 1
428 1 print WRM "$m.xs\n";
429 1 ▶ if($c->{WRITE_MAKEFILE_PL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"WRITE_MAKEFILE_PL"}) 1 0 1
430 1 print WRM "Makefile.PL\n";
431 }
432 1 ▶ if($c->{T}){
Branch: 1 branch
BranchTrueFalseTotal
if ($c->{"T"}) 1 0 1
433 1 print WRM "t/00load.t\n";
434 }
435 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: $!" 1 0 1
436 }
437  
438 ##=========================##
439  
440 1 ▶sub _write_test_script {
Subroutine _write_test_script: called CC=5 SCAR=16.5
441 15 ▶ use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
442 1 my $mod = $_[0];
443 1 my $path = "$_[1]/t";
444 1 ▶ unless(-d $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $path) 1 0 1
445 0 ▶ 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
446 }
447  
448 1 print "Writing 00load.t in the $path directory\n";
449 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: $!" 1 0 1
450 1 print WRT "## This file auto-generated by InlineX-C2XS-" . $InlineX::C2XS::VERSION . "\n\n";
451 1 print WRT "use strict;\nuse warnings;\n\n";
452 1 print WRT "print \"1..1\\n\";\n\n";
453 1 print WRT "eval{require $mod;};\n";
454 1 print WRT "if(\$\@) {\n warn \"\\\$\\\@: \$\@\";\n print \"not ok 1\\n\";\n}\n";
455 1 print WRT "else {print \"ok 1\\n\"}\n";
456 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: $!" 1 0 1
457 }
458  
459 ##=========================##
460  
461 15 *context = \&InlineX::C2XS::Context::apply_context_args;
462  
463 ##=========================##
464  
465 ##=========================##
466  
467 15 1;
468  
469 __END__
« C2XS/Context.pm ↑ Summary