Install/ParseXS.pm

filter: Statementstmt 24.8% 81 / 326 Branchbran 0.6% 1 / 144 Conditioncond 1.3% 1 / 73 MC/DCmcdc 0.0% 0 / 42 Subroutinesub 45.1% 14 / 31 Podpod 0.0% 0 / 11 totaltotal 15.4% 97 / 627 SCAR 87.7
CC
102
Cov
15%
__ANON__
4290.0
__ANON__
650.0
code_start_idx
12.0
CRAP 6427.2
« Install.pm ↑ Summary Loader.pm »
1 package # hide from CPAN indexer
2 XS::Install::ParseXS;
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use ExtUtils::ParseXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use ExtUtils::ParseXS::Eval;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use ExtUtils::ParseXS::Utilities;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use ExtUtils::Typemaps;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use ExtUtils::Typemaps::InputMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use ExtUtils::Typemaps::OutputMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 my (@pre_callbacks, @no_typemap_callbacks);
15 1 our ($top_typemaps, $cur_typemaps);
16 1 our $cplus = grep { /-C\+\+/ } @ARGV;
17 1 my $re_quot1 = qr/"(?:[^"\\]+|\\.)*"/;
18 1 my $re_quot2 = qr/'(?:[^'\\]+|\\.)*'/;
19 1 my $re_quot = qr/(?:$re_quot1|$re_quot2)/;
20 1 my $re_comment_single = qr#//[^\n]*\n#;
21 1 my $re_comment_multi = qr#/\*.*?\*/#ms;
22 1 my $re_ignored = qr/(?:$re_quot|$re_comment_single|$re_comment_multi)/ms;
23 1 my $re_braces = qr#(?<braces>\{(?>[^/"'{}]+|$re_ignored|(?&braces)|/)*\})#ms;
24 1 our $re_xsub = qr/(XS_EUPXS\(XS_[a-zA-Z0-9_]+\))[^{]+($re_braces)/ms;
25 1 our $re_boot = qr/(XS_EXTERNAL\(boot_[a-zA-Z0-9_]+\))[^{]+($re_braces)/ms;
26  
27 0 ▶sub add_pre_callback { push @pre_callbacks, shift; }
Subroutine add_pre_callback: not called CC=1 SCAR=6.9
Pod undocumented
28 0 ▶sub add_post_callback { push @CatchEnd::post_callbacks, shift; }
Subroutine add_post_callback: not called CC=1 SCAR=6.9
Pod undocumented
29 0 ▶sub add_no_typemap_callback { push @no_typemap_callbacks, shift; }
Subroutine add_no_typemap_callback: not called CC=1 SCAR=6.9
Pod undocumented
30  
31 sub call {
32 1 ▶ my ($cbs, @args) = @_;
Subroutine call: called CC=2 SCAR=6.9
Pod undocumented
33 1 $_->(@args) for @$cbs;
34 }
35  
36 sub code_start_idx {
37 0 ▶ my $lines = shift;
Subroutine code_start_idx: not called CC=3 SCAR=24.8
Pod undocumented
38 0 my $idx;
39 0 ▶ for (my $i = 2; $i < @$lines; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$lines) 0 0 0
40 0 ▶ return $i+1 if $lines->[$i] =~ /^(PP)?CODE\s*:/;
Branch: 1 branch
BranchTrueFalseTotal
if $lines->[$i] =~ /^(PP)?CODE\s*:/ 0 0 0
41 }
42 0 die "code start not found";
43 }
44  
45 sub code_end_idx {
46 0 ▶ my $lines = shift;
Subroutine code_end_idx: not called CC=3 SCAR=24.8
Pod undocumented
47 0 my $idx = code_start_idx($lines);
48 0 ▶ for (; $idx < @$lines; ++$idx) {
Branch: 1 branch
BranchTrueFalseTotal
if ($idx < @$lines) 0 0 0
49 0 ▶ return $idx if $lines->[$idx] =~ /^[a-zA-Z0-9]+\s*:/;
Branch: 1 branch
BranchTrueFalseTotal
if $lines->[$idx] =~ /^[a-zA-Z0-9]+\s*:/ 0 0 0
50 }
51 0 return $idx;
52 }
53  
54 sub is_empty {
55 0 ▶ my $lines = shift;
Subroutine is_empty: not called CC=1 SCAR=6.9
Pod undocumented
56 0 return code_start_idx($lines) == code_end_idx($lines);
57 }
58  
59 sub insert_code_top {
60 0 ▶ my ($parser, $code) = @_;
Subroutine insert_code_top: not called CC=2 SCAR=17.9
Pod undocumented
61 0 my $lines = $parser->{line};
62 0 my $linno = $parser->{line_no};
63 0 my $idx = code_start_idx($lines);
64 0 splice(@$lines, $idx, 0, $code);
65 0 ▶ splice(@$linno, $idx, 0, $linno->[$idx] // $linno->[-1]);
Condition0%0/3
$linno->[$idx] // $linno->[-1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$linno->[$idx] // $linno->[-1]
$linno->[$idx] $linno->[-1]
Truth table0%0/3
A // B
A= $linno->[$idx]B= $linno->[-1]
ABresult
1X1
011
000
66 }
67  
68 sub insert_code_bottom {
69 0 ▶ my ($parser, $code) = @_;
Subroutine insert_code_bottom: not called CC=2 SCAR=17.9
Pod undocumented
70 0 my $lines = $parser->{line};
71 0 my $linno = $parser->{line_no};
72 0 my $idx = code_end_idx($lines);
73 0 splice(@$lines, $idx, 0, $code);
74 0 ▶ splice(@$linno, $idx, 0, $linno->[$idx] // $linno->[-1]);
Condition0%0/3
$linno->[$idx] // $linno->[-1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$linno->[$idx] // $linno->[-1]
$linno->[$idx] $linno->[-1]
Truth table0%0/3
A // B
A= $linno->[$idx]B= $linno->[-1]
ABresult
1X1
011
000
75 }
76  
77 1 my $orig_pmxl = \&ExtUtils::ParseXS::_process_module_xs_line;
78 *ExtUtils::ParseXS::_process_module_xs_line = sub {
79 0 ▶ my ($self, $module, $pkg, $prefix) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
80 0 $orig_pmxl->(@_);
81 0 $self->{xsi}{module} = $module;
82 0 $self->{xsi}{inline_mode} = 0;
83 1 };
84  
85 sub get_mode {
86 0 ▶ return '' unless $_[0] =~ /^MODE\s*:\s*(\w+)\s*$/;
Subroutine get_mode: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^MODE\s*:\s*(\w+)\s*$/ 0 0 0
87 0 return uc($1);
88 }
89  
90 # pre process XS function
91 1 my $orig_fetch_para = \&ExtUtils::ParseXS::fetch_para;
92 *ExtUtils::ParseXS::fetch_para = sub {
93 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=65 SCAR=83.6
94 0 my $ret = $orig_fetch_para->($self, @_);
95 0 my $lines = $self->{line};
96 0 my $linno = $self->{line_no};
97 0 ▶ return $ret unless @$lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @$lines 0 0 0
98
99 0 ▶ if (get_mode($lines->[0]) eq 'INLINE') {
Branch: 1 branch
BranchTrueFalseTotal
if (get_mode($lines->[0]) eq "INLINE") 0 0 0
100 0 $self->{xsi}{inline_mode} = 1;
101 0 shift @$lines;
102 0 shift @$linno;
103 }
104
105 0 ▶ if ($self->{xsi}{inline_mode}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"xsi"}{"inline_mode"}) 0 0 0
106 0 ▶ while (@$lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$lines) 0 0 0
107 0 my $line = shift @$lines;
108 0 shift @$linno;
109 0 ▶ if (get_mode($line) eq 'XS') {
Branch: 1 branch
BranchTrueFalseTotal
if (get_mode($line) eq "XS") 0 0 0
110 0 $self->{xsi}{inline_mode} = 0;
111 0 last;
112 }
113 0 print "$line\n";
114 }
115 0 ▶ return $ret unless @$lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @$lines 0 0 0
116 }
117
118 # concat 2 lines codes (functions with default behaviour) to make it preprocessed like C-like synopsis
119 0 ▶ if (@$lines == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$lines == 2) 0 0 0
120 0 $lines->[0] .= ' '.$lines->[1];
121 0 splice(@$lines, 1, 1);
122 0 splice(@$linno, 1, 1);
123 }
124
125 0 ▶ if ($lines->[0] and $lines->[0] =~ /^([A-Z]+)\s*\{/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines->[0] and $lines->[0] =~ /^([A-Z]+)\s*\{/) 0 0 0
Condition0%0/3
$lines->[0] and $lines->[0] =~ /^([A-Z]+)\s*\{/
!ll&&!rl&&r
000
MC/DC0%0/2
$lines->[0] and $lines->[0] =~ /^([A-Z]+)\s*\{/
$lines->[0] $lines->[0] =~ /^([A-Z]+)\s*\{/
Truth table0%0/3
A and B
A= $lines->[0]B= $lines->[0] =~ /^([A-Z]+)\s*\{/
ABresult
0X0
100
111
126 0 $lines->[0] = "$1:";
127 0 ▶ if ($lines->[-1] =~ /^\}/) { pop @$lines; pop @$linno; }
Branch: 1 branch
BranchTrueFalseTotal
if ($lines->[-1] =~ /^\}/) 0 0 0
128 }
129
130 0 my %attrs;
131
132 0 ▶ if ($lines->[0] and $lines->[0] =~ /^(.+?)\s+([^\s()]+\s*(\((?:[^()]|(?3))*\)))\s*(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines->[0] and $lines->[0] =~ /^(.+?)\s+([^\s()]+\s*(\((?:[^()]|(?3))*\)))\s*(.*)/) 0 0 0
Condition0%0/3
$lines->[0] and $lines->[0] =~ /^(.+?)\s+([^\s()]+\s*(\((?:[^()]|(?3))*\)))\s*(.*)/
!ll&&!rl&&r
000
MC/DC0%0/2
$lines->[0] and $lines->[0] =~ /^(.+?)\s+([^\s()]+\s*(\((?:[^()]|(?3))*\)))\s*(.*)/
$lines->[0] $lines->[0] =~ /^(.+?)\s+([^\s()]+\s*(\((?:[^()]|(?3))*\)))\s*(.*)/
Truth table0%0/3
A and B
A= $lines->[0]B= $lines->[0] =~ /^(.+?)\s+([^\s()]+\s*(\((?:[^()]|(?3))*\)))\s*(.*)/
ABresult
0X0
100
111
133 0 my ($type, $sig, $rest) = ($1, $2, $4);
134 0 shift @$lines;
135 0 my $deflinno = shift @$linno;
136
137 0 my $remove_closing;
138 0 ▶ if ((my $idx = index($rest, '{')) >= 0) { # move following text on next line
Branch: 2 branches
BranchTrueFalseTotal
if ((my $idx = index($rest, '{')) >= 0) { } 0 0 0
elsif ($lines->[0] and $lines->[0] =~ s/^\s*\{//) { } 0 0 0
139 0 $remove_closing = 1;
140 0 my $content = substr($rest, $idx+1);
141 0 substr($rest, $idx) = '';
142 0 ▶ if ($content =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /\S/) 0 0 0
143 0 unshift @$lines, $content;
144 0 unshift @$linno, $deflinno;
145 }
146 ▶ } elsif ($lines->[0] and $lines->[0] =~ s/^\s*\{//) { # '{' on next line
Condition0%0/3
$lines->[0] and $lines->[0] =~ s/^\s*\{//
!ll&&!rl&&r
000
MC/DC0%0/2
$lines->[0] and $lines->[0] =~ s/^\s*\{//
$lines->[0] $lines->[0] =~ s/^\s*\{//
Truth table0%0/3
A and B
A= $lines->[0]B= $lines->[0] =~ s/^\s*\{//
ABresult
0X0
100
111
147 0 $remove_closing = 1;
148 0 ▶ if ($lines->[0] !~ /\S/) { # nothing remains, delete entire line
Branch: 1 branch
BranchTrueFalseTotal
unless ($lines->[0] =~ /\S/) 0 0 0
149 0 shift @$lines;
150 0 shift @$linno;
151 }
152 }
153  
154 0 ▶ if ($remove_closing) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remove_closing) 0 0 0
155 0 $lines->[-1] =~ s/}\s*;?\s*$//;
156 0 ▶ if ($lines->[-1] !~ /\S/) { pop @$lines; pop @$linno; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($lines->[-1] =~ /\S/) 0 0 0
157
158 0 ▶ if (!$lines->[0] or $lines->[0] !~ /\S/) { # no code remains, but body was present ({}), add empty code to prevent default behaviour
Branch: 1 branch
BranchTrueFalseTotal
unless ($lines->[0] and $lines->[0] =~ /\S/) 0 0 0
Condition0%0/3
$lines->[0] and $lines->[0] =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
$lines->[0] and $lines->[0] =~ /\S/
$lines->[0] $lines->[0] =~ /\S/
Truth table0%0/3
A and B
A= $lines->[0]B= $lines->[0] =~ /\S/
ABresult
0X0
100
111
159 0 $lines->[0] = ' ';
160 0 ▶ $linno->[0] ||= $deflinno;
Condition0%0/3
$linno->[0] ||= $deflinno
l!l&&r!l&&!r
000
MC/DC0%0/2
$linno->[0] ||= $deflinno
$linno->[0] $deflinno
Truth table0%0/3
A ||= B
A= $linno->[0]B= $deflinno
ABresult
1X1
011
000
161 }
162 }
163
164 0 ▶ if (length $lines->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $lines->[0]) 0 0 0
165 0 ▶ unshift @$lines, $type =~ /^void(\s|$)/ ? 'PPCODE:' : 'CODE:';
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /^void(\s|$)/ ? : 0 0 0
166 0 unshift @$linno, $deflinno;
167 }
168
169 0 ▶ if ($rest =~ /:(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /:(.+)/) 0 0 0
170 0 my $attrs_str = $1;
171 0 %attrs = ($attrs_str =~ /\s*([A-Za-z]+)\s*(?:\(([^()]*)\)|)\s*/g);
172 }
173
174 0 ▶ while (my ($attr, $val) = each %attrs) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %attrs) 0 0 0
175 0 $attr = uc($attr);
176 0 ▶ if ($attr eq 'ALIAS' && (my @alias = split /\s*,\s*/, $val)) {
Branch: 3 branches
BranchTrueFalseTotal
if ($attr eq 'ALIAS' and my @alias = split(/\s*,\s*/, $val, 0)) { } 0 0 0
elsif ($attr eq 'CONST') { } 0 0 0
elsif (defined $val) { } 0 0 0
Condition0%0/3
$attr eq "ALIAS" and my @alias = split(/\s*,\s*/, $val, 0)
!ll&&!rl&&r
000
MC/DC0%0/2
$attr eq "ALIAS" and my @alias = split(/\s*,\s*/, $val, 0)
$attr eq "ALIAS" my @alias = split(/\s*,\s*/, $val, 0)
Truth table0%0/3
A and B
A= $attr eq "ALIAS"B= my @alias = split(/\s*,\s*/, $val, 0)
ABresult
0X0
100
111
177 0 foreach my $alias_entry (reverse @alias) {
178 0 unshift @$lines, " $alias_entry";
179 0 unshift @$linno, $deflinno;
180 }
181 0 unshift @$lines, 'ALIAS:';
182 0 unshift @$linno, $deflinno;
183 }
184 0 elsif ($attr eq 'CONST') { next }
185 elsif (defined $val) {
186 0 unshift @$lines, "$attr: $val";
187 0 unshift @$linno, $deflinno;
188 }
189 }
190  
191 0 unshift @$lines, $sig;
192 0 unshift @$lines, $type;
193 0 unshift @$linno, $deflinno for 1..2;
194 }
195
196 # make BOOT's code in personal scope
197 0 ▶ if ($lines->[0] =~ /^BOOT\s*:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines->[0] =~ /^BOOT\s*:/) 0 0 0
198 0 splice(@$lines, 1, 0, " {");
199 0 splice(@$linno, 1, 0, $linno->[0]);
200 0 push @$lines, " }";
201 0 push @$linno, $linno->[-1];
202 }
203
204 map {
205 0 s/\b__PACKAGE__\b/"$self->{Package}"/g;
206 0 s/\b__MODULE__\b/"$self->{xsi}{module}"/g;
207 } @$lines;
208
209 0 ▶ my $out_type = $lines->[0] or return $ret;
Branch: 1 branch
BranchTrueFalseTotal
my $out_type = $lines->[0] or return $ret 0 0 0
210 # filter out junk, because first line might be "BOOT:", "PROTOTYPES: ...", "INCLUDE: ...", "#ifdef", etc
211 0 ▶ return $ret if !$out_type or $out_type =~ /^#/ or $out_type =~ /^[_A-Z]+\s*:([^:]|$)/;
Branch: 1 branch
BranchTrueFalseTotal
if not $out_type or $out_type =~ /^#/ or $out_type =~ /^[_A-Z]+\s*:([^:]|$)/ 0 0 0
Condition0%0/6
not $out_type or $out_type =~ /^#/ or $out_type =~ /^[_A-Z]+\s*:([^:]|$)/
l!l&&r!l&&!r
000
not $out_type or $out_type =~ /^#/
l!l&&r!l&&!r
000
MC/DC0%0/3
not $out_type or $out_type =~ /^#/ or $out_type =~ /^[_A-Z]+\s*:([^:]|$)/
not $out_type $out_type =~ /^#/ $out_type =~ /^[_A-Z]+\s*:([^:]|$)/
Truth table0%0/4
not(A) or B or C
A= not $out_typeB= $out_type =~ /^#/C= $out_type =~ /^[_A-Z]+\s*:([^:]|$)/
ABCresult
1XX1
01X1
0011
0000
212  
213 # parse signature -> $func and @args
214 0 my $sig = $lines->[1];
215 0 ▶ $sig =~ /^([^(]+)\((.*)\)\s*$/ or die "bad signature: '$sig', at $self->{filepathname}, function $self->{pname}";
Branch: 1 branch
BranchTrueFalseTotal
$sig =~ /^([^(]+)\((.*)\)\s*$/ or die qq[bad signature: '${sig}', at $self->{"filepathname"}, function $self->{"pname"}] 0 0 0
216 0 my $func = $1;
217 0 my $args_str = $2;
218 0 $func =~ s/^\s+//; $func =~ s/\s+$//;
219 0 my @args;
220 my $variadic;
221 0 for my $str (split /\s*,\s*/, $args_str) {
222 0 my %info;
223 0 ▶ $info{default} = $1 if $str =~ s/\s*=\s*(.+)$//;
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ s/\s*=\s*(.+)$// 0 0 0
224 0 $info{name} = '';
225 0 ▶ $info{name} = $1 if $str =~ s/([a-zA-Z0-9_\$]+)\s*$//;
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ s/([a-zA-Z0-9_\$]+)\s*$// 0 0 0
226 0 $info{type} = $str;
227 0 ▶ if ($str eq '...') {
Branch: 1 branch
BranchTrueFalseTotal
if ($str eq "...") 0 0 0
228 0 $variadic = 1;
229 0 next;
230 }
231 0 ▶ if (!$info{type}) { # arg with no name
Branch: 1 branch
BranchTrueFalseTotal
unless ($info{"type"}) 0 0 0
232 0 $info{type} = $info{name};
233 0 $info{name} = '';
234 }
235
236 0 map { s/^\s+//; s/\s+$// } values %info;
237 0 push @args, \%info;
238 }
239
240 0 ▶ if ($func =~ s/^(.+):://) { # replace 'Class::meth' with 'meth(Class* THIS)'
Branch: 1 branch
BranchTrueFalseTotal
if ($func =~ s/^(.+):://) 0 0 0
241 0 ▶ unshift @args, $func eq 'new' ? {name => 'CLASS', type => 'SV*', orig_type => $1} :
Branch: 1 branch
BranchTrueFalseTotal
$func eq 'new' ? : 0 0 0
242 {name => 'THIS', type => "$1*"};
243 }
244
245 0 my $first_arg = $args[0];
246 0 ▶ $first_arg->{type} = 'const '.$first_arg->{type} if exists($attrs{const}) or exists($attrs{CONST});
Branch: 1 branch
BranchTrueFalseTotal
if exists $attrs{"const"} or exists $attrs{"CONST"} 0 0 0
Condition0%0/3
exists $attrs{"const"} or exists $attrs{"CONST"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $attrs{"const"} or exists $attrs{"CONST"}
exists $attrs{"const"} exists $attrs{"CONST"}
Truth table0%0/3
A or B
A= exists $attrs{"const"}B= exists $attrs{"CONST"}
ABresult
1X1
011
000
247 0 ▶ my $is_method = $first_arg && $first_arg->{name} eq 'THIS';
Condition0%0/3
$first_arg && $first_arg->{'name'} eq 'THIS'
!ll&&!rl&&r
000
MC/DC0%0/2
$first_arg && $first_arg->{'name'} eq 'THIS'
$first_arg $first_arg->{'name'} eq 'THIS'
Truth table0%0/3
A && B
A= $first_argB= $first_arg->{'name'} eq 'THIS'
ABresult
0X0
100
111
248
249 0 my $para = join("\n", @$lines);
250
251 0 ▶ if ($para !~ /^(PP)?CODE\s*:/m) { # empty function, replace with $func(@args) or $first_arg->$func(@rest_args)
Branch: 1 branch
BranchTrueFalseTotal
unless ($para =~ /^(PP)?CODE\s*:/m) 0 0 0
252 0 my $void = $out_type =~ /^void(?:\s|$)/;
253 0 ▶ push @$lines, $void ? 'PPCODE:' : 'CODE:';
Branch: 1 branch
BranchTrueFalseTotal
$void ? : 0 0 0
254 0 push @$linno, $linno->[-1];
255 0 ▶ if ($func ne 'new' and ($func ne 'DESTROY' or !$is_method)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($func ne "new" and $func ne "DESTROY" || !$is_method) 0 0 0
Condition0%0/6
$func ne "new" and $func ne "DESTROY" || !$is_method
!ll&&!rl&&r
000
$func ne "DESTROY" or not $is_method
l!l&&r!l&&!r
000
MC/DC0%0/3
$func ne "new" and $func ne "DESTROY" || !$is_method
$func ne "new" $func ne "DESTROY" not $is_method
Truth table0%0/4
A and B or not(C)
A= $func ne "new"B= $func ne "DESTROY"C= not $is_method
ABCresult
0XX0
1000
11X1
1011
256 0 my $code = '';
257 0 my @real_args = @args;
258 0 ▶ if ($is_method) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_method) 0 0 0
259 0 shift @real_args;
260 0 $code = $first_arg->{name}.'->';
261 }
262 0 $code .= $func.'('.join(', ', map { $_->{name} } @real_args).')';
263 0 ▶ $code = "RETVAL = $code" unless $void;
Branch: 1 branch
BranchTrueFalseTotal
unless $void 0 0 0
264 0 push @$lines, " $code;";
265 0 push @$linno, $linno->[-1];
266 }
267 0 $para = join("\n", @$lines);
268 }
269
270 0 ▶ if ($para =~ /^CODE\s*:/m and $para !~ /^OUTPUT\s*:/m) { # add OUTPUT:RETVAL unless any
Branch: 1 branch
BranchTrueFalseTotal
if ($para =~ /^CODE\s*:/m and not $para =~ /^OUTPUT\s*:/m) 0 0 0
Condition0%0/3
$para =~ /^CODE\s*:/m and not $para =~ /^OUTPUT\s*:/m
!ll&&!rl&&r
000
MC/DC0%0/2
$para =~ /^CODE\s*:/m and not $para =~ /^OUTPUT\s*:/m
$para =~ /^CODE\s*:/m not $para =~ /^OUTPUT\s*:/m
Truth table0%0/3
A and not(B)
A= $para =~ /^CODE\s*:/mB= not $para =~ /^OUTPUT\s*:/m
ABresult
0X0
100
111
271 0 push @$lines, 'OUTPUT:', ' RETVAL';
272 0 push @$linno, $linno->[-1] for 1..2;
273 0 $para = join("\n", @$lines);
274 }
275
276 0 my $cb_args = {
277 ret => $out_type,
278 func => $func,
279 args => \@args,
280 variadic => $variadic,
281 };
282 0 call(\@pre_callbacks, $self, $cb_args);
283
284 # form final signature for ParseXS
285 0 ▶ my @args_lines = map { "$_->{type} $_->{name}".(defined($_->{default}) ? " = $_->{default}" : '') } @args;
Branch: 1 branch
BranchTrueFalseTotal
defined $_->{'default'} ? : 0 0 0
286 0 ▶ push @args_lines, '...' if $variadic;
Branch: 1 branch
BranchTrueFalseTotal
if $variadic 0 0 0
287 0 $sig = $func.' ('.join(', ', @args_lines).')';
288
289 0 $lines->[0] = $out_type;
290 0 $lines->[1] = $sig;
291
292 0 ▶ if (is_empty($lines)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_empty($lines)) 0 0 0
293 0 ▶ if ($func eq 'DESTROY' and $is_method) {
Branch: 2 branches
BranchTrueFalseTotal
if ($func eq 'DESTROY' and $is_method) { } 0 0 0
elsif ($func eq 'new') { } 0 0 0
Condition0%0/3
$func eq "DESTROY" and $is_method
!ll&&!rl&&r
000
MC/DC0%0/2
$func eq "DESTROY" and $is_method
$func eq "DESTROY" $is_method
Truth table0%0/3
A and B
A= $func eq "DESTROY"B= $is_method
ABresult
0X0
100
111
294 0 insert_code_top($self, " delete THIS;");
295 }
296 elsif ($func eq 'new') {
297 0 insert_code_top($self, " RETVAL = ".default_constructor($out_type, \@args).';');
298 }
299 }
300
301 0 return $ret;
302 1 };
303  
304 sub default_constructor {
305 0 ▶ my ($ret_type, $args) = @_;
Subroutine default_constructor: not called CC=3 SCAR=24.8
Pod undocumented
306 0 my @pass_args = @$args;
307 0 my $fa = shift @pass_args;
308 0 my $args_str = join(', ', map { $_->{name} } @pass_args);
309 0 my $new_type = $fa->{orig_type};
310 0 ▶ unless ($new_type) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($new_type) 0 0 0
311 0 $new_type = $ret_type;
312 0 $new_type =~ s/\s*\*$//;
313 }
314 0 my $ret = "new $new_type($args_str)";
315
316 0 ▶ $ret = "$ret_type($ret)" unless $ret_type =~ /\*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $ret_type =~ /\*$/ 0 0 0
317
318 0 return $ret;
319 }
320  
321 {
322 1 my $orig_merge = \&ExtUtils::Typemaps::merge;
323 1 my $orig_parse = \&ExtUtils::Typemaps::_parse;
324 1 my $orig_get = \&ExtUtils::Typemaps::get_typemap;
325
326 *ExtUtils::Typemaps::get_typemap = sub {
327 0 ▶ my $ret = $orig_get->(@_);
Subroutine __ANON__: not called CC=2 SCAR=17.9
328 0 ▶ return $ret if $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 0 0
329 0 call(\@no_typemap_callbacks, @_);
330 0 return $orig_get->(@_);
331 1 };
332
333 *ExtUtils::Typemaps::merge = sub {
334 0 ▶ $top_typemaps = $_[0];
Subroutine __ANON__: not called CC=1 SCAR=6.9
335 0 return $orig_merge->(@_);
336 1 };
337
338 *ExtUtils::Typemaps::_parse = sub {
339 0 ▶ local $cur_typemaps = $_[0];
Subroutine __ANON__: not called CC=1 SCAR=6.9
340 0 return $orig_parse->(@_);
341 1 };
342 }
343  
344 {
345 # remove ugly default behaviour, it always overrides typemaps in xsubpp's command line
346 1 *ExtUtils::ParseXS::Utilities::standard_typemap_locations = sub {
347 0 ▶ my $inc = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
348 0 my @ret;
349 0 ▶ push @ret, 'typemap' if -e 'typemap';
Branch: 1 branch
BranchTrueFalseTotal
if -e "typemap" 0 0 0
350 0 return @ret;
351 1 };
352 }
353  
354 {
355 1 package # hide from CPAN
356 CatchEnd;
357 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
358 1 ▶ use feature 'say';
Subroutine BEGIN: called CC=1 SCAR=0.0
359
360 1 our @post_callbacks;
361  
362 1 my ($out, $orig_stdout);
363 1 open $orig_stdout, '>&', STDOUT;
364 1 close STDOUT;
365 1 ▶ open STDOUT, '>', \$out or die $!; # This shouldn't fail
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">", \$out or die $! 0 1 1
366
367 #post-process XS out
368 sub END {
369 1 ▶ $out //= '';
Subroutine END: called CC=2 SCAR=7.0
Condition50%1/2
$out //= ""
l!l
01
MC/DC0%0/1
$out //= ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
370 1 select $orig_stdout;
371  
372 1 $out =~ s/^MODE\s*:.+//mg;
373
374 # remove XS function C-prototype (it causes warnings on many compilers)
375 1 $out =~ s/XS_EUPXS\(XS_[a-zA-Z0-9_]+\);.*\n/\n/mg;
376
377 # remove XS BOOT function C-prototype
378 1 $out =~ s/XS_EXTERNAL\(boot_[a-zA-Z0-9_]+\);.*\n/\n/mg;
379  
380 1 XS::Install::ParseXS::call(\@post_callbacks, \$out);
381 1 print $out;
382 }
383 }
384  
385 {
386 1 package #hide from CPAN
387 ExtUtils::ParseXS;
388 1 my $END = "!End!\n\n";
389 1 my $BLOCK_regexp = '\s*(' . $ExtUtils::ParseXS::Constants::XSKeywordsAlternation . "|$END)\\s*:";
390 # copy-paste from ExtUtils::ParseXS to fix Typemaps with references (&). ParseXS was simply removing it from type
391 # only one line changed with regexp
392 # my ($var_type, $var_addr, $var_name) = /^(.*?[^&\s])\s*(\&?)\s*\b(\w+)$/s
393 *INPUT_handler = sub {
394 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=25 SCAR=64.8
395 0 $_ = shift;
396 0 ▶ for (; !/^$BLOCK_regexp/o; $_ = shift(@{ $self->{line} })) {
Branch: 1 branch
BranchTrueFalseTotal
if (not /^$BLOCK_regexp/o) 0 0 0
397 0 ▶ last if /^\s*NOT_IMPLEMENTED_YET/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*NOT_IMPLEMENTED_YET/ 0 0 0
398 0 ▶ next unless /\S/; # skip blank lines
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ 0 0 0
399
400 0 trim_whitespace($_);
401 0 my $ln = $_;
402
403 # remove trailing semicolon if no initialisation
404 0 ▶ s/\s*;$//g unless /[=;+].*\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless /[=;+].*\S/ 0 0 0
405
406 # Process the length(foo) declarations
407 0 ▶ if (s/^([^=]*)\blength\(\s*(\w+)\s*\)\s*$/$1 XSauto_length_of_$2=NO_INIT/x) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/^([^=]*)\blength\(\s*(\w+)\s*\)\s*$/$1 XSauto_length_of_$2=NO_INIT/x) 0 0 0
408 0 print "\tSTRLEN\tSTRLEN_length_of_$2;\n";
409 0 $self->{lengthof}->{$2} = undef;
410 0 $self->{deferred} .= "\n\tXSauto_length_of_$2 = STRLEN_length_of_$2;\n";
411 }
412
413 # check for optional initialisation code
414 0 my $var_init = '';
415 0 ▶ $var_init = $1 if s/\s*([=;+].*)$//s;
Branch: 1 branch
BranchTrueFalseTotal
if s/\s*([=;+].*)$//s 0 0 0
416 0 $var_init =~ s/"/\\"/g;
417 # *sigh* It's valid to supply explicit input typemaps in the argument list...
418 0 my $is_overridden_typemap = $var_init =~ /ST\s*\(|\$arg\b/;
419
420 0 s/\s+/ /g;
421 0 my $var_addr = '';
422 0 ▶ my ($var_type, $var_name) = /^(.*?[^\s])\s*\b(\w+)$/s
Branch: 1 branch
BranchTrueFalseTotal
() = /^(.*?[^\s])\s*\b(\w+)$/s or $self->blurt("Error: invalid argument declaration '${ln}'"), next 0 0 0
423 or $self->blurt("Error: invalid argument declaration '$ln'"), next;
424
425 # Check for duplicate definitions
426 $self->blurt("Error: duplicate definition of argument '$var_name' ignored"), next
427 if $self->{arg_list}->{$var_name}++
428 0 ▶ or defined $self->{argtype_seen}->{$var_name} and not $self->{processing_arg_with_types};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"arg_list"}{$var_name}++ or defined $self->{"argtype_seen"}{$var_name} and not $self->{"processing_arg_with_types"} 0 0 0
Condition0%0/6
$self->{"arg_list"}{$var_name}++ or defined $self->{"argtype_seen"}{$var_name} and not $self->{"processing_arg_with_types"}
l!l&&r!l&&!r
000
defined $self->{"argtype_seen"}{$var_name} and not $self->{"processing_arg_with_types"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"arg_list"}{$var_name}++ or defined $self->{"argtype_seen"}{$var_name} and not $self->{"processing_arg_with_types"}
$self->{"arg_list"}{$var_name}++ defined $self->{"argtype_seen"}{$var_name} not $self->{"processing_arg_with_types"}
Truth table0%0/4
A or B and not(C)
A= $self->{"arg_list"}{$var_name}++B= defined $self->{"argtype_seen"}{$var_name}C= not $self->{"processing_arg_with_types"}
ABCresult
1XX1
0111
00X0
0100
429
430 0 $self->{thisdone} |= $var_name eq "THIS";
431 0 $self->{retvaldone} |= $var_name eq "RETVAL";
432 0 $self->{var_types}->{$var_name} = $var_type;
433 # XXXX This check is a safeguard against the unfinished conversion of
434 # generate_init(). When generate_init() is fixed,
435 # one can use 2-args map_type() unconditionally.
436 0 my $printed_name;
437 0 ▶ if ($var_type =~ / \( \s* \* \s* \) /x) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var_type =~ / \( \s* \* \s* \) /x) { } 0 0 0
438 # Function pointers are not yet supported with output_init()!
439 0 print "\t" . map_type($self, $var_type, $var_name);
440 0 $printed_name = 1;
441 }
442 else {
443 0 print "\t" . map_type($self, $var_type, undef);
444 0 $printed_name = 0;
445 }
446 0 $self->{var_num} = $self->{args_match}->{$var_name};
447
448 0 ▶ if ($self->{var_num}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"var_num"}) 0 0 0
449 0 my $typemap = $self->{typemap}->get_typemap(ctype => $var_type);
450 0 ▶ $self->report_typemap_failure($self->{typemap}, $var_type, "death")
Branch: 1 branch
BranchTrueFalseTotal
unless $typemap or $is_overridden_typemap 0 0 0
Condition0%0/3
$typemap or $is_overridden_typemap
l!l&&r!l&&!r
000
MC/DC0%0/2
$typemap or $is_overridden_typemap
$typemap $is_overridden_typemap
Truth table0%0/3
A or B
A= $typemapB= $is_overridden_typemap
ABresult
1X1
011
000
451 if not $typemap and not $is_overridden_typemap;
452 0 ▶ $self->{proto_arg}->[$self->{var_num}] = ($typemap && $typemap->proto) || "\$";
Condition0%0/5
$typemap && $typemap->proto || '$'
l!l
00
$typemap and $typemap->proto
!ll&&!rl&&r
000
MC/DC0%0/2
$typemap && $typemap->proto || '$'
$typemap $typemap->proto
Truth table0%0/3
A and B
A= $typemapB= $typemap->proto
ABresult
111
0X0
100
453 }
454 0 ▶ $self->{func_args} =~ s/\b($var_name)\b/&$1/ if $var_addr;
Branch: 1 branch
BranchTrueFalseTotal
if $var_addr 0 0 0
455 0 ▶ if ($var_init =~ /^[=;]\s*NO_INIT\s*;?\s*$/
Branch: 3 branches
BranchTrueFalseTotal
if ($var_init =~ /^[=;]\s*NO_INIT\s*;?\s*$/ or $self->{'in_out'}{$var_name} and $self->{'in_out'}{$var_name} =~ /^OUT/ and not $var_init =~ /\S/) { } 0 0 0
elsif ($var_init =~ /\S/) { } 0 0 0
elsif ($self->{'var_num'}) { } 0 0 0
Condition0%0/9
$var_init =~ /^[=;]\s*NO_INIT\s*;?\s*$/ or $self->{"in_out"}{$var_name} and $self->{"in_out"}{$var_name} =~ /^OUT/ and not $var_init =~ /\S/
l!l&&r!l&&!r
000
$self->{"in_out"}{$var_name} and $self->{"in_out"}{$var_name} =~ /^OUT/ and not $var_init =~ /\S/
!ll&&!rl&&r
000
$self->{"in_out"}{$var_name} and $self->{"in_out"}{$var_name} =~ /^OUT/
!ll&&!rl&&r
000
MC/DC0%0/4
$var_init =~ /^[=;]\s*NO_INIT\s*;?\s*$/ or $self->{"in_out"}{$var_name} and $self->{"in_out"}{$var_name} =~ /^OUT/ and not $var_init =~ /\S/
$var_init =~ /^[=;]\s*NO_INIT\s*;?\s*$/ $self->{"in_out"}{$var_name} $self->{"in_out"}{$var_name} =~ /^OUT/ not $var_init =~ /\S/
Truth table0%0/5
A or B and C and not(D)
A= $var_init =~ /^[=;]\s*NO_INIT\s*;?\s*$/B= $self->{"in_out"}{$var_name}C= $self->{"in_out"}{$var_name} =~ /^OUT/D= not $var_init =~ /\S/
ABCDresult
1XXX1
01111
00XX0
010X0
01100
456 or $self->{in_out}->{$var_name} and $self->{in_out}->{$var_name} =~ /^OUT/
457 and $var_init !~ /\S/) {
458 0 ▶ if ($printed_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($printed_name) { } 0 0 0
459 0 print ";\n";
460 }
461 else {
462 0 print "\t$var_name;\n";
463 }
464 }
465 elsif ($var_init =~ /\S/) {
466 $self->output_init( {
467 type => $var_type,
468 num => $self->{var_num},
469 0 var => $var_name,
470 init => $var_init,
471 printed_name => $printed_name,
472 } );
473 }
474 elsif ($self->{var_num}) {
475 $self->generate_init( {
476 type => $var_type,
477 num => $self->{var_num},
478 0 var => $var_name,
479 printed_name => $printed_name,
480 } );
481 }
482 else {
483 0 print ";\n";
484 }
485 }
486 1 };
487 }
488  
489 1 1;
« Install.pm ↑ Summary Loader.pm »