blib/lib/ExtUtils/Constant.pm

filter: Statementstmt 78.3% 112 / 143 Branchbran 66.6% 44 / 66 Conditioncond 36.0% 9 / 25 MC/DCmcdc 14.2% 2 / 14 Subroutinesub 75.0% 12 / 16 Podpod 55.5% 5 / 9 totaltotal 67.4% 184 / 273 CC 43 SCAR 30.4
CC
43
Cov
71%
WriteConstants
42.2
XS_constant
20.2
WriteMakefileSnippet
20.0
CRAP 21.0
« blib/lib/ExtUtils/Constant/ProxySubs.pm ↑ Summary blib/lib/ExtUtils/Constant/Base.pm »
1 package ExtUtils::Constant;
2 1 ▶use vars qw (@ISA $VERSION @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $VERSION = '0.24_50';
4  
5 =head1 NAME
6  
7 ExtUtils::Constant - generate XS code to import C header constants
8  
9 =head1 SYNOPSIS
10  
11 use ExtUtils::Constant qw (WriteConstants);
12 WriteConstants(
13 NAME => 'Foo',
14 NAMES => [qw(FOO BAR BAZ)],
15 );
16 # Generates wrapper code to make the values of the constants FOO BAR BAZ
17 # available to perl
18  
19 =head1 DESCRIPTION
20  
21 ExtUtils::Constant facilitates generating C and XS wrapper code to allow
22 perl modules to AUTOLOAD constants defined in C library header files.
23 It is principally used by the C<h2xs> utility, on which this code is based.
24 It doesn't contain the routines to scan header files to extract these
25 constants.
26  
27 =head1 USAGE
28  
29 Generally one only needs to call the C<WriteConstants> function, and then
30  
31 #include "const-c.inc"
32  
33 in the C section of C<Foo.xs>
34  
35 INCLUDE: const-xs.inc
36  
37 in the XS section of C<Foo.xs>.
38  
39 For greater flexibility use C<constant_types()>, C<C_constant> and
40 C<XS_constant>, with which C<WriteConstants> is implemented.
41  
42 Currently this module understands the following types. h2xs may only know
43 a subset. The sizes of the numeric types are chosen by the C<Configure>
44 script at compile time.
45  
46 =over 4
47  
48 =item IV
49  
50 signed integer, at least 32 bits.
51  
52 =item UV
53  
54 unsigned integer, the same size as I<IV>
55  
56 =item NV
57  
58 floating point type, probably C<double>, possibly C<long double>
59  
60 =item PV
61  
62 NUL terminated string, length will be determined with C<strlen>
63  
64 =item PVN
65  
66 A fixed length thing, given as a [pointer, length] pair. If you know the
67 length of a string at compile time you may use this instead of I<PV>
68  
69 =item SV
70  
71 A B<mortal> SV.
72  
73 =item YES
74  
75 Truth. (C<PL_sv_yes>) The value is not needed (and ignored).
76  
77 =item NO
78  
79 Defined Falsehood. (C<PL_sv_no>) The value is not needed (and ignored).
80  
81 =item UNDEF
82  
83 C<undef>. The value of the macro is not needed.
84  
85 =back
86  
87 =head1 FUNCTIONS
88  
89 =over 4
90  
91 =cut
92  
93 1 ▶if ($] >= 5.006) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= "5.006") 1 0 1
94 1 ▶ eval "use warnings; 1" or die $@;
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval "use warnings; 1" or die $@ 0 1 1
95 }
96 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
97 1 ▶use Carp qw(croak cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
98  
99 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
100 1 ▶use ExtUtils::Constant::Utils qw(C_stringify);
Subroutine BEGIN: called CC=1 SCAR=0.0
101 1 ▶use ExtUtils::Constant::XS qw(%XS_Constant %XS_TypeSet);
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 1 @ISA = 'Exporter';
104  
105 1 %EXPORT_TAGS = ( 'all' => [ qw(
106 XS_constant constant_types return_clause memEQ_clause C_stringify
107 C_constant autoload WriteConstants WriteMakefileSnippet
108 ) ] );
109  
110 1 @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
111  
112 =item constant_types
113  
114 A function returning a single scalar with C<#define> definitions for the
115 constants used internally between the generated C and XS functions.
116  
117 =cut
118  
119 sub constant_types {
120 6 ▶ ExtUtils::Constant::XS->header();
Subroutine constant_types: called CC=1 SCAR=0.0
Pod documented
121 }
122  
123 sub memEQ_clause {
124 0 ▶ cluck "ExtUtils::Constant::memEQ_clause is deprecated";
Subroutine memEQ_clause: not called CC=1 SCAR=6.9
Pod undocumented
125 0 ExtUtils::Constant::XS->memEQ_clause({name=>$_[0], checked_at=>$_[1],
126 indent=>$_[2]});
127 }
128  
129 sub return_clause ($$) {
130 0 ▶ cluck "ExtUtils::Constant::return_clause is deprecated";
Subroutine return_clause: not called CC=1 SCAR=6.9
Pod undocumented
131 0 my $indent = shift;
132 0 ExtUtils::Constant::XS->return_clause({indent=>$indent}, @_);
133 }
134  
135 sub switch_clause {
136 0 ▶ cluck "ExtUtils::Constant::switch_clause is deprecated";
Subroutine switch_clause: not called CC=1 SCAR=6.9
Pod undocumented
137 0 my $indent = shift;
138 0 my $comment = shift;
139 0 ExtUtils::Constant::XS->switch_clause({indent=>$indent, comment=>$comment},
140 @_);
141 }
142  
143 sub C_constant {
144 1 ▶ my ($package, $subname, $default_type, $what, $indent, $breakout, @items)
Subroutine C_constant: called CC=1 SCAR=0.0
Pod undocumented
145 = @_;
146 1 ExtUtils::Constant::XS->C_constant({package => $package, subname => $subname,
147 default_type => $default_type,
148 types => $what, indent => $indent,
149 breakout => $breakout}, @items);
150 }
151  
152 =item XS_constant PACKAGE, TYPES, XS_SUBNAME, C_SUBNAME
153  
154 A function to generate the XS code to implement the perl subroutine
155 I<PACKAGE>::constant used by I<PACKAGE>::AUTOLOAD to load constants.
156 This XS code is a wrapper around a C subroutine usually generated by
157 C<C_constant>, and usually named C<constant>.
158  
159 I<TYPES> should be given either as a comma separated list of types that the
160 C subroutine C<constant> will generate or as a reference to a hash. It should
161 be the same list of types as C<C_constant> was given.
162 [Otherwise C<XS_constant> and C<C_constant> may have different ideas about
163 the number of parameters passed to the C function C<constant>]
164  
165 You can call the perl visible subroutine something other than C<constant> if
166 you give the parameter I<XS_SUBNAME>. The C subroutine it calls defaults to
167 the name of the perl visible subroutine, unless you give the parameter
168 I<C_SUBNAME>.
169  
170 =cut
171  
172 sub XS_constant {
173 6 ▶ my $package = shift;
Subroutine XS_constant: called CC=20 SCAR=30.1
Pod documented
174 6 my $what = shift;
175 6 my $XS_subname = shift;
176 6 my $C_subname = shift;
177 6 ▶ $XS_subname ||= 'constant';
Condition50%1/2
$XS_subname ||= "constant"
l!l
60
MC/DC0%0/1
$XS_subname ||= "constant"
$XS_subname
Truth table50%1/2
A
A= $XS_subname
Aresult
11
00
178 6 ▶ $C_subname ||= $XS_subname;
Condition33%1/3
$C_subname ||= $XS_subname
l!l&&r!l&&!r
600
MC/DC0%0/2
$C_subname ||= $XS_subname
$C_subname $XS_subname
Truth table33%1/3
A ||= B
A= $C_subnameB= $XS_subname
ABresult
1X1
011
000
179  
180 6 ▶ if (!ref $what) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $what) 0 6 6
181 # Convert line of the form IV,UV,NV to hash
182 0 $what = {map {$_ => 1} split /,\s*/, ($what)};
183 }
184 6 my $params = ExtUtils::Constant::XS->params ($what);
185 6 my $type;
186  
187 6 my $xs = <<"EOT";
188 void
189 $XS_subname(sv)
190 PREINIT:
191 #ifdef dXSTARG
192 dXSTARG; /* Faster if we have it. */
193 #else
194 dTARGET;
195 #endif
196 STRLEN len;
197 int type;
198 EOT
199  
200 6 ▶ if ($params->{IV}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'IV'}) { } 5 1 6
201 5 $xs .= " IV iv = 0; /* avoid uninit var warning */\n";
202 } else {
203 1 $xs .= " /* IV\t\tiv;\tUncomment this if you need to return IVs */\n";
204 }
205 6 ▶ if ($params->{NV}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'NV'}) { } 1 5 6
206 1 $xs .= " NV nv = 0.0; /* avoid uninit var warning */\n";
207 } else {
208 5 $xs .= " /* NV\t\tnv;\tUncomment this if you need to return NVs */\n";
209 }
210 6 ▶ if ($params->{PV}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'PV'}) { } 2 4 6
211 2 $xs .= " const char *pv = NULL; /* avoid uninit var warning */\n";
212 } else {
213 4 $xs .=
214 " /* const char\t*pv;\tUncomment this if you need to return PVs */\n";
215 }
216  
217 6 $xs .= << 'EOT';
218 INPUT:
219 SV * sv;
220 const char * s = SvPV(sv, len);
221 EOT
222 6 ▶ if ($params->{''}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{""}) 2 4 6
223 2 $xs .= << 'EOT';
224 INPUT:
225 int utf8 = SvUTF8(sv);
226 EOT
227 }
228 6 $xs .= << 'EOT';
229 PPCODE:
230 EOT
231  
232 6 ▶ if ($params->{IV} xor $params->{NV}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"IV"} xor $params->{"NV"}) 4 2 6
Condition75%3/4
$params->{"IV"} xor $params->{"NV"}
l&&rl&&!r!l&&r!l&&!r
1401
MC/DC100%2/2
$params->{"IV"} xor $params->{"NV"}
$params->{"IV"} $params->{"NV"}
Truth table75%3/4
A xor B
A= $params->{"IV"}B= $params->{"NV"}
ABresult
110
101
011
000
233 4 $xs .= << "EOT";
234 /* Change this to $C_subname(aTHX_ s, len, &iv, &nv);
235 if you need to return both NVs and IVs */
236 EOT
237 }
238 6 $xs .= " type = $C_subname(aTHX_ s, len";
239 6 ▶ $xs .= ', utf8' if $params->{''};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{""} 2 4 6
240 6 ▶ $xs .= ', &iv' if $params->{IV};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"IV"} 5 1 6
241 6 ▶ $xs .= ', &nv' if $params->{NV};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"NV"} 1 5 6
242 6 ▶ $xs .= ', &pv' if $params->{PV};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"PV"} 2 4 6
243 6 ▶ $xs .= ', &sv' if $params->{SV};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"SV"} 1 5 6
244 6 $xs .= ");\n";
245  
246 # If anyone is insane enough to suggest a package name containing %
247 6 my $package_sprintf_safe = $package;
248 6 $package_sprintf_safe =~ s/%/%%/g;
249  
250 6 $xs .= << "EOT";
251 /* Return 1 or 2 items. First is error message, or undef if no error.
252 Second, if present, is found value */
253 switch (type) {
254 case PERL_constant_NOTFOUND:
255 sv =
256 sv_2mortal(newSVpvf("%s is not a valid $package_sprintf_safe macro", s));
257 PUSHs(sv);
258 break;
259 case PERL_constant_NOTDEF:
260 sv = sv_2mortal(newSVpvf(
261 "Your vendor has not defined $package_sprintf_safe macro %s, used",
262 s));
263 PUSHs(sv);
264 break;
265 EOT
266  
267 6 foreach $type (sort keys %XS_Constant) {
268 # '' marks utf8 flag needed.
269 60 ▶ next if $type eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "" 6 54 60
270 $xs .= "\t/* Uncomment this if you need to return ${type}s\n"
271 54 ▶ unless $what->{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless $what->{$type} 40 14 54
272 54 $xs .= " case PERL_constant_IS$type:\n";
273 54 ▶ if (length $XS_Constant{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $ExtUtils::Constant::XS_Constant{$type}) { } 48 6 54
274 48 $xs .= << "EOT";
275 EXTEND(SP, 2);
276 PUSHs(&PL_sv_undef);
277 $XS_Constant{$type};
278 EOT
279 } else {
280 # Do nothing. return (), which will be correctly interpreted as
281 # (undef, undef)
282 }
283 54 $xs .= " break;\n";
284 54 ▶ unless ($what->{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($what->{$type}) 40 14 54
285 40 chop $xs; # Yes, another need for chop not chomp.
286 40 $xs .= " */\n";
287 }
288 }
289 6 $xs .= << "EOT";
290 default:
291 sv = sv_2mortal(newSVpvf(
292 "Unexpected return type %d while processing $package_sprintf_safe macro %s, used",
293 type, s));
294 PUSHs(sv);
295 }
296 EOT
297  
298 6 return $xs;
299 }
300  
301  
302 =item autoload PACKAGE, VERSION, AUTOLOADER
303  
304 A function to generate the AUTOLOAD subroutine for the module I<PACKAGE>
305 I<VERSION> is the perl version the code should be backwards compatible with.
306 It defaults to the version of perl running the subroutine. If I<AUTOLOADER>
307 is true, the AUTOLOAD subroutine falls back on AutoLoader::AUTOLOAD for all
308 names that the constant() routine doesn't recognise.
309  
310 =cut
311  
312 # ' # Grr. syntax highlighters that don't grok pod.
313  
314 sub autoload {
315 7 ▶ my ($module, $compat_version, $autoloader) = @_;
Subroutine autoload: called CC=6 SCAR=19.3
Pod documented
316 7 ▶ $compat_version ||= $];
Condition33%1/3
$compat_version ||= $]
l!l&&r!l&&!r
700
MC/DC0%0/2
$compat_version ||= $]
$compat_version $]
Truth table33%1/3
A ||= B
A= $compat_versionB= $]
ABresult
1X1
011
000
317 7 ▶ croak "Can't maintain compatibility back as far as version $compat_version"
Branch: 1 branch
BranchTrueFalseTotal
if $compat_version < 5 0 7 7
318 if $compat_version < 5;
319 7 my $func = "sub AUTOLOAD {\n"
320 . " # This AUTOLOAD is used to 'autoload' constants from the constant()\n"
321 . " # XS function.";
322 7 ▶ $func .= " If a constant is not found then control is passed\n"
Branch: 1 branch
BranchTrueFalseTotal
if $autoloader 0 7 7
323 . " # to the AUTOLOAD in AutoLoader." if $autoloader;
324  
325  
326 7 $func .= "\n\n"
327 . " my \$constname;\n";
328 7 ▶ $func .=
Branch: 1 branch
BranchTrueFalseTotal
if $compat_version >= "5.006" 7 0 7
329 " our \$AUTOLOAD;\n" if ($compat_version >= 5.006);
330  
331 7 $func .= <<"EOT";
332 (\$constname = \$AUTOLOAD) =~ s/.*:://;
333 croak "&${module}::constant not defined" if \$constname eq 'constant';
334 my (\$error, \$val) = constant(\$constname);
335 EOT
336  
337 7 ▶ if ($autoloader) {
Branch: 1 branch
BranchTrueFalseTotal
if ($autoloader) { } 0 7 7
338 0 $func .= <<'EOT';
339 if ($error) {
340 if ($error =~ /is not a valid/) {
341 $AutoLoader::AUTOLOAD = $AUTOLOAD;
342 goto &AutoLoader::AUTOLOAD;
343 } else {
344 croak $error;
345 }
346 }
347 EOT
348 } else {
349 7 $func .=
350 " if (\$error) { croak \$error; }\n";
351 }
352  
353 7 $func .= <<'END';
354 {
355 no strict 'refs';
356 # Fixed between 5.005_53 and 5.005_61
357 #XXX if ($] >= 5.00561) {
358 #XXX *$AUTOLOAD = sub () { $val };
359 #XXX }
360 #XXX else {
361 *$AUTOLOAD = sub { $val };
362 #XXX }
363 }
364 goto &$AUTOLOAD;
365 }
366  
367 END
368  
369 7 return $func;
370 }
371  
372  
373 =item WriteMakefileSnippet
374  
375 WriteMakefileSnippet ATTRIBUTE =E<gt> VALUE [, ...]
376  
377 A function to generate perl code for Makefile.PL that will regenerate
378 the constant subroutines. Parameters are named as passed to C<WriteConstants>,
379 with the addition of C<INDENT> to specify the number of leading spaces
380 (default 2).
381  
382 Currently only C<INDENT>, C<NAME>, C<DEFAULT_TYPE>, C<NAMES>, C<C_FILE> and
383 C<XS_FILE> are recognised.
384  
385 =cut
386  
387 sub WriteMakefileSnippet {
388 0 ▶ my %args = @_;
Subroutine WriteMakefileSnippet: not called CC=4 SCAR=30.0
Pod documented
389 0 ▶ my $indent = $args{INDENT} || 2;
Condition0%0/2
$args{'INDENT'} || 2
l!l
00
MC/DC0%0/1
$args{'INDENT'} || 2
$args{'INDENT'}
Truth table0%0/2
A
A= $args{'INDENT'}
Aresult
11
00
390  
391 0 my $result = <<"EOT";
392 ExtUtils::Constant::WriteConstants(
393 NAME => '$args{NAME}',
394 NAMES => \\\@names,
395 DEFAULT_TYPE => '$args{DEFAULT_TYPE}',
396 EOT
397 0 foreach (qw (C_FILE XS_FILE)) {
398 0 ▶ next unless exists $args{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{$_} 0 0 0
399 $result .= sprintf " %-12s => '%s',\n",
400 0 $_, $args{$_};
401 }
402 0 $result .= <<'EOT';
403 );
404 EOT
405  
406 0 $result =~ s/^/' 'x$indent/gem;
407 return ExtUtils::Constant::XS->dump_names({default_type=>$args{DEFAULT_TYPE},
408 indent=>$indent,},
409 0 @{$args{NAMES}})
410 . $result;
411 }
412  
413 =item WriteConstants ATTRIBUTE =E<gt> VALUE [, ...]
414  
415 Writes a file of C code and a file of XS code which you should C<#include>
416 and C<INCLUDE> in the C and XS sections respectively of your module's XS
417 code. You probably want to do this in your C<Makefile.PL>, so that you can
418 easily edit the list of constants without touching the rest of your module.
419 The attributes supported are
420  
421 =over 4
422  
423 =item NAME
424  
425 Name of the module. This must be specified
426  
427 =item DEFAULT_TYPE
428  
429 The default type for the constants. If not specified C<IV> is assumed.
430  
431 =item BREAKOUT_AT
432  
433 The names of the constants are grouped by length. Generate child subroutines
434 for each group with this number or more names in.
435  
436 =item NAMES
437  
438 An array of constants' names, either scalars containing names, or hashrefs
439 as detailed in L<"C_constant">.
440  
441 =item PROXYSUBS
442  
443 If true, uses proxy subs. See L<ExtUtils::Constant::ProxySubs>.
444  
445 =item C_FH
446  
447 A filehandle to write the C code to. If not given, then I<C_FILE> is opened
448 for writing.
449  
450 =item C_FILE
451  
452 The name of the file to write containing the C code. The default is
453 C<const-c.inc>. The C<-> in the name ensures that the file can't be
454 mistaken for anything related to a legitimate perl package name, and
455 not naming the file C<.c> avoids having to override Makefile.PL's
456 C<.xs> to C<.c> rules.
457  
458 =item XS_FH
459  
460 A filehandle to write the XS code to. If not given, then I<XS_FILE> is opened
461 for writing.
462  
463 =item XS_FILE
464  
465 The name of the file to write containing the XS code. The default is
466 C<const-xs.inc>.
467  
468 =item XS_SUBNAME
469  
470 The perl visible name of the XS subroutine generated which will return the
471 constants. The default is C<constant>.
472  
473 =item C_SUBNAME
474  
475 The name of the C subroutine generated which will return the constants.
476 The default is I<XS_SUBNAME>. Child subroutines have C<_> and the name
477 length appended, so constants with 10 character names would be in
478 C<constant_10> with the default I<XS_SUBNAME>.
479  
480 =back
481  
482 =cut
483  
484 sub WriteConstants {
485 7 ▶ my %ARGS =
Subroutine WriteConstants: called CC=16 SCAR=37.4
Pod documented
486 ( # defaults
487 C_FILE => 'const-c.inc',
488 XS_FILE => 'const-xs.inc',
489 XS_SUBNAME => 'constant',
490 DEFAULT_TYPE => 'IV',
491 @_);
492  
493 7 ▶ $ARGS{C_SUBNAME} ||= $ARGS{XS_SUBNAME}; # No-one sane will have C_SUBNAME eq '0'
Condition33%1/3
$ARGS{"C_SUBNAME"} ||= $ARGS{"XS_SUBNAME"}
l!l&&r!l&&!r
070
MC/DC0%0/2
$ARGS{"C_SUBNAME"} ||= $ARGS{"XS_SUBNAME"}
$ARGS{"C_SUBNAME"} $ARGS{"XS_SUBNAME"}
Truth table33%1/3
A ||= B
A= $ARGS{"C_SUBNAME"}B= $ARGS{"XS_SUBNAME"}
ABresult
1X1
011
000
494  
495 7 ▶ croak "Module name not specified" unless length $ARGS{NAME};
Branch: 1 branch
BranchTrueFalseTotal
unless length $ARGS{"NAME"} 0 7 7
496  
497 # Do this before creating (empty) files, in case it fails:
498 7 ▶ require ExtUtils::Constant::ProxySubs if $ARGS{PROXYSUBS};
Branch: 1 branch
BranchTrueFalseTotal
if $ARGS{"PROXYSUBS"} 1 6 7
499  
500 7 my $c_fh = $ARGS{C_FH};
501 7 ▶ if (!$c_fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c_fh) 0 7 7
502 0 ▶ if ($] <= 5.008) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] <= "5.008") 0 0 0
503 # We need these little games, rather than doing things
504 # unconditionally, because we're used in core Makefile.PLs before
505 # IO is available (needed by filehandle), but also we want to work on
506 # older perls where undefined scalars do not automatically turn into
507 # anonymous file handles.
508 0 require FileHandle;
509 0 $c_fh = FileHandle->new();
510 }
511 0 ▶ open $c_fh, ">$ARGS{C_FILE}" or die "Can't open $ARGS{C_FILE}: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $c_fh, qq[>$ARGS{"C_FILE"}] or die qq[Can't open $ARGS{"C_FILE"}: $!] 0 0 0
512 }
513  
514 7 my $xs_fh = $ARGS{XS_FH};
515 7 ▶ if (!$xs_fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($xs_fh) 0 7 7
516 0 ▶ if ($] <= 5.008) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] <= "5.008") 0 0 0
517 0 require FileHandle;
518 0 $xs_fh = FileHandle->new();
519 }
520 0 ▶ open $xs_fh, ">$ARGS{XS_FILE}" or die "Can't open $ARGS{XS_FILE}: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $xs_fh, qq[>$ARGS{"XS_FILE"}] or die qq[Can't open $ARGS{"XS_FILE"}: $!] 0 0 0
521 }
522  
523 # As this subroutine is intended to make code that isn't edited, there's no
524 # need for the user to specify any types that aren't found in the list of
525 # names.
526
527 7 ▶ if ($ARGS{PROXYSUBS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ARGS{'PROXYSUBS'}) { } 1 6 7
528 1 $ARGS{C_FH} = $c_fh;
529 1 $ARGS{XS_FH} = $xs_fh;
530 1 ExtUtils::Constant::ProxySubs->WriteConstants(%ARGS);
531 } else {
532 6 my $types = {};
533  
534 6 print $c_fh constant_types(); # macro defs
535 6 print $c_fh "\n";
536  
537 # indent is still undef. Until anyone implements indent style rules with
538 # it.
539 6 foreach (ExtUtils::Constant::XS->C_constant({package => $ARGS{NAME},
540 subname => $ARGS{C_SUBNAME},
541 default_type =>
542 $ARGS{DEFAULT_TYPE},
543 types => $types,
544 breakout =>
545 $ARGS{BREAKOUT_AT}},
546 6 @{$ARGS{NAMES}})) {
547 16 print $c_fh $_, "\n"; # C constant subs
548 }
549 print $xs_fh XS_constant ($ARGS{NAME}, $types, $ARGS{XS_SUBNAME},
550 6 $ARGS{C_SUBNAME});
551 }
552  
553 7 ▶ close $c_fh or warn "Error closing $ARGS{C_FILE}: $!" unless $ARGS{C_FH};
Branch: 1 branch
BranchTrueFalseTotal
unless $ARGS{"C_FH"} 0 7 7
Condition25%1/4
$ARGS{'C_FH'} || (close $c_fh || warn("Error closing $ARGS{'C_FILE'}: $!"))
l!l
70
close $c_fh or warn qq[Error closing $ARGS{"C_FILE"}: $!]
l!l
00
MC/DC0%0/2
$ARGS{'C_FH'} || (close $c_fh || warn("Error closing $ARGS{'C_FILE'}: $!"))
$ARGS{'C_FH'} close $c_fh
Truth table33%1/3
A || B
A= $ARGS{'C_FH'}B= close $c_fh
ABresult
1X1
011
000
554 7 ▶ close $xs_fh or warn "Error closing $ARGS{XS_FILE}: $!" unless $ARGS{XS_FH};
Branch: 1 branch
BranchTrueFalseTotal
unless $ARGS{"XS_FH"} 0 7 7
Condition25%1/4
$ARGS{'XS_FH'} || (close $xs_fh || warn("Error closing $ARGS{'XS_FILE'}: $!"))
l!l
70
close $xs_fh or warn qq[Error closing $ARGS{"XS_FILE"}: $!]
l!l
00
MC/DC0%0/2
$ARGS{'XS_FH'} || (close $xs_fh || warn("Error closing $ARGS{'XS_FILE'}: $!"))
$ARGS{'XS_FH'} close $xs_fh
Truth table33%1/3
A || B
A= $ARGS{'XS_FH'}B= close $xs_fh
ABresult
1X1
011
000
555 }
556  
557 1 1;
558 __END__
« blib/lib/ExtUtils/Constant/ProxySubs.pm ↑ Summary blib/lib/ExtUtils/Constant/Base.pm »