blib/lib/Inline/Pdlpp.pm

filter: Statementstmt 83.0% 88 / 106 Branchbran 41.6% 10 / 24 Conditioncond 36.8% 7 / 19 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 77.7% 21 / 27 Podpod 5.2% 1 / 19 totaltotal 61.6% 127 / 206 CC 21 SCAR 21.7
CC
21
Cov
70%
validate
29.7
write_Makefile_PL
5.1
pd_boot
3.8
CRAP 8.7
« blib/lib/PDL/Options.pm ↑ Summary blib/lib/PDL/CallExt.pm »
1 package Inline::Pdlpp;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Cwd qw(cwd abs_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use PDL::Core::Dev;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 $Inline::Pdlpp::VERSION = '0.4';
13 2 ▶use base qw(Inline::C);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 #==============================================================================
16 # Register this module as an Inline language support module
17 #==============================================================================
18 sub register {
19 return {
20 language => 'Pdlpp',
21 aliases => ['pdlpp','PDLPP'],
22 type => 'compiled',
23 suffix => $Config{dlext},
24 0 ▶ };
Subroutine register: not called CC=1 SCAR=6.9
Pod undocumented
25 }
26  
27 # handle BLESS, INTERNAL, NOISY - pass everything else up to Inline::C
28 sub validate {
29 2 ▶ my $o = shift;
Subroutine validate: called CC=11 SCAR=33.9
Pod undocumented
30 2 ▶ $o->{ILSM} ||= {};
Condition50%1/2
$o->{"ILSM"} ||= {}
l!l
02
MC/DC0%0/1
$o->{"ILSM"} ||= {}
$o->{"ILSM"}
Truth table50%1/2
A
A= $o->{"ILSM"}
Aresult
11
00
31 2 ▶ $o->{ILSM}{XS} ||= {};
Condition50%1/2
$o->{"ILSM"}{"XS"} ||= {}
l!l
02
MC/DC0%0/1
$o->{"ILSM"}{"XS"} ||= {}
$o->{"ILSM"}{"XS"}
Truth table50%1/2
A
A= $o->{"ILSM"}{"XS"}
Aresult
11
00
32 # Shouldn't use internal linking for Inline stuff, normally
33 2 ▶ $o->{ILSM}{INTERNAL} = 0 unless defined $o->{ILSM}{INTERNAL};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o->{"ILSM"}{"INTERNAL"} 2 0 2
34 2 ▶ $o->{ILSM}{MAKEFILE} ||= {};
Condition50%1/2
$o->{"ILSM"}{"MAKEFILE"} ||= {}
l!l
02
MC/DC0%0/1
$o->{"ILSM"}{"MAKEFILE"} ||= {}
$o->{"ILSM"}{"MAKEFILE"}
Truth table50%1/2
A
A= $o->{"ILSM"}{"MAKEFILE"}
Aresult
11
00
35 2 ▶ if (not $o->UNTAINT) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($o->UNTAINT) 2 0 2
36 2 my $w = abs_path(PDL::Core::Dev::whereami_any());
37 2 $o->{ILSM}{MAKEFILE}{INC} = qq{"-I$w/Core"};
38 }
39 2 ▶ $o->{ILSM}{AUTO_INCLUDE} ||= ' '; # not '' as Inline::C does ||=
Condition50%1/2
$o->{"ILSM"}{"AUTO_INCLUDE"} ||= " "
l!l
02
MC/DC0%0/1
$o->{"ILSM"}{"AUTO_INCLUDE"} ||= " "
$o->{"ILSM"}{"AUTO_INCLUDE"}
Truth table50%1/2
A
A= $o->{"ILSM"}{"AUTO_INCLUDE"}
Aresult
11
00
40 2 my @pass_along;
41 2 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
42 0 my ($key, $value) = (shift, shift);
43 0 ▶ if ($key eq 'INTERNAL' or
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "INTERNAL" or $key eq "BLESS") 0 0 0
Condition0%0/3
$key eq "INTERNAL" or $key eq "BLESS"
l!l&&r!l&&!r
000
MC/DC0%0/2
$key eq "INTERNAL" or $key eq "BLESS"
$key eq "INTERNAL" $key eq "BLESS"
Truth table0%0/3
A or B
A= $key eq "INTERNAL"B= $key eq "BLESS"
ABresult
1X1
011
000
44 $key eq 'BLESS'
45 ) {
46 0 $o->{ILSM}{$key} = $value;
47 0 next;
48 }
49 0 ▶ if ($key eq 'NOISY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "NOISY") 0 0 0
50 0 $o->{CONFIG}{BUILD_NOISY} = $value;
51 0 next;
52 }
53 0 push @pass_along, $key, $value;
54 }
55 2 $o->SUPER::validate(@pass_along);
56 }
57  
58 0 ▶sub add_list { goto &Inline::C::add_list }
Subroutine add_list: not called CC=1 SCAR=6.9
Pod undocumented
59 0 ▶sub add_string { goto &Inline::C::add_string }
Subroutine add_string: not called CC=1 SCAR=6.9
Pod undocumented
60 0 ▶sub add_text { goto &Inline::C::add_text }
Subroutine add_text: not called CC=1 SCAR=6.9
Pod undocumented
61  
62 #==============================================================================
63 # Parse and compile C code
64 #==============================================================================
65 sub build {
66 2 ▶ my $o = shift;
Subroutine build: called CC=1 SCAR=0.0
Pod undocumented
67 # $o->parse; # no parsing in pdlpp
68 2 $o->get_maps; # get the typemaps
69 2 $o->write_PD;
70 # $o->write_Inline_headers; # shouldn't need this one either
71 2 $o->write_Makefile_PL;
72 2 $o->compile;
73 }
74  
75 #==============================================================================
76 # Return a small report about the C code..
77 #==============================================================================
78 sub info {
79 0 ▶ my $o = shift;
Subroutine info: not called CC=1 SCAR=6.9
Pod documented
80 0 my $txt = <<END;
81 The following PP code was generated (caution, can be long)...
82  
83 *** start PP file ****
84  
85 END
86 0 return $txt . $o->pd_generate . "\n*** end PP file ****\n";
87 }
88  
89 sub config {
90 0 ▶ my $o = shift;
Subroutine config: not called CC=1 SCAR=6.9
Pod undocumented
91 }
92  
93 #==============================================================================
94 # Write the PDL::PP code into a PD file
95 #==============================================================================
96 sub write_PD {
97 2 ▶ my $o = shift;
Subroutine write_PD: called CC=2 SCAR=7.0
Pod undocumented
98 2 my $modfname = $o->{API}{modfname};
99 2 my $module = $o->{API}{module};
100 2 $o->mkpath($o->{API}{build_dir});
101 2 ▶ open my $fh, ">", "$o->{API}{build_dir}/$modfname.pd" or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", qq[$o->{"API"}{"build_dir"}/$modfname.pd] or croak($!) 0 2 2
102 2 print $fh $o->pd_generate;
103 2 close $fh;
104 }
105  
106 #==============================================================================
107 # Generate the PDL::PP code (piece together a few snippets)
108 #==============================================================================
109 sub pd_generate {
110 2 ▶ my $o = shift;
Subroutine pd_generate: called CC=1 SCAR=0.0
Pod undocumented
111 2 return join "\n", ($o->pd_includes,
112 $o->pd_code,
113 $o->pd_boot,
114 $o->pd_bless,
115 $o->pd_done,
116 );
117 }
118  
119 sub pd_includes {
120 2 ▶ my $o = shift;
Subroutine pd_includes: called CC=1 SCAR=0.0
Pod undocumented
121 2 return << "END";
122 pp_addhdr << 'EOH';
123 $o->{ILSM}{AUTO_INCLUDE}
124 EOH
125  
126 END
127 }
128  
129 sub pd_code {
130 2 ▶ my $o = shift;
Subroutine pd_code: called CC=1 SCAR=0.0
Pod undocumented
131 2 return $o->{API}{code};
132 }
133  
134 sub pd_boot {
135 2 ▶ my $o = shift;
Subroutine pd_boot: called CC=3 SCAR=13.3
Pod undocumented
136 2 ▶ if (defined $o->{ILSM}{XS}{BOOT} and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o->{"ILSM"}{"XS"}{"BOOT"} and $o->{"ILSM"}{"XS"}{"BOOT"}) 0 2 2
Condition33%1/3
defined $o->{"ILSM"}{"XS"}{"BOOT"} and $o->{"ILSM"}{"XS"}{"BOOT"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $o->{"ILSM"}{"XS"}{"BOOT"} and $o->{"ILSM"}{"XS"}{"BOOT"}
defined $o->{"ILSM"}{"XS"}{"BOOT"} $o->{"ILSM"}{"XS"}{"BOOT"}
Truth table33%1/3
A and B
A= defined $o->{"ILSM"}{"XS"}{"BOOT"}B= $o->{"ILSM"}{"XS"}{"BOOT"}
ABresult
0X0
100
111
137 $o->{ILSM}{XS}{BOOT}) {
138 0 return <<END;
139 pp_add_boot << 'EOB';
140 $o->{ILSM}{XS}{BOOT}
141 EOB
142  
143 END
144 }
145 2 return '';
146 }
147  
148  
149 sub pd_bless {
150 2 ▶ my $o = shift;
Subroutine pd_bless: called CC=3 SCAR=13.3
Pod undocumented
151 2 ▶ if (defined $o->{ILSM}{BLESS} and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $o->{"ILSM"}{"BLESS"} and $o->{"ILSM"}{"BLESS"}) 0 2 2
Condition33%1/3
defined $o->{"ILSM"}{"BLESS"} and $o->{"ILSM"}{"BLESS"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $o->{"ILSM"}{"BLESS"} and $o->{"ILSM"}{"BLESS"}
defined $o->{"ILSM"}{"BLESS"} $o->{"ILSM"}{"BLESS"}
Truth table33%1/3
A and B
A= defined $o->{"ILSM"}{"BLESS"}B= $o->{"ILSM"}{"BLESS"}
ABresult
0X0
100
111
152 $o->{ILSM}{BLESS}) {
153 0 return <<END;
154 pp_bless $o->{ILSM}{BLESS};
155 END
156 }
157 2 return '';
158 }
159  
160  
161 sub pd_done {
162 2 ▶ return <<END;
Subroutine pd_done: called CC=1 SCAR=0.0
Pod undocumented
163 pp_done();
164 END
165 }
166  
167 sub get_maps {
168 2 ▶ my $o = shift;
Subroutine get_maps: called CC=1 SCAR=0.0
Pod undocumented
169 2 $o->SUPER::get_maps;
170 2 my $w = abs_path(PDL::Core::Dev::whereami_any());
171 2 push @{$o->{ILSM}{MAKEFILE}{TYPEMAPS}}, "$w/Core/typemap.pdl";
172 }
173  
174 #==============================================================================
175 # Generate the Makefile.PL
176 #==============================================================================
177 sub write_Makefile_PL {
178 2 ▶ my $o = shift;
Subroutine write_Makefile_PL: called CC=5 SCAR=16.3
Pod undocumented
179 2 my ($modfname,$module,$pkg) = @{$o->{API}}{qw(modfname module pkg)};
180 2 ▶ my $coredev_suffix = $o->{ILSM}{INTERNAL} ? '_int' : '';
Branch: 1 branch
BranchTrueFalseTotal
$o->{'ILSM'}{'INTERNAL'} ? : 0 2 2
181 2 my @pack = [ "$modfname.pd", $modfname, $module ];
182 my $stdargs_func = $o->{ILSM}{INTERNAL}
183 2 ▶ ? \&pdlpp_stdargs_int : \&pdlpp_stdargs;
Branch: 1 branch
BranchTrueFalseTotal
$o->{'ILSM'}{'INTERNAL'} ? : 0 2 2
184 2 my %hash = $stdargs_func->(@pack);
185 2 delete $hash{VERSION_FROM};
186 my %options = (
187 %hash,
188 VERSION => $o->{API}{version} || "0.00",
189 2 %{$o->{ILSM}{MAKEFILE}},
190 NAME => $o->{API}{module},
191 INSTALLSITEARCH => $o->{API}{install_lib},
192 INSTALLDIRS => 'site',
193 INSTALLSITELIB => $o->{API}{install_lib},
194 2 ▶ MAN3PODS => {},
Condition50%1/2
$o->{'API'}{'version'} || '0.00'
l!l
02
MC/DC0%0/1
$o->{'API'}{'version'} || '0.00'
$o->{'API'}{'version'}
Truth table50%1/2
A
A= $o->{'API'}{'version'}
Aresult
11
00
195 PM => {},
196 );
197 2 ▶ open my $fh, ">", "$o->{API}{build_dir}/Makefile.PL" or croak;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", qq[$o->{"API"}{"build_dir"}/Makefile.PL] or croak() 0 2 2
198 2 print $fh <<END;
199 use strict;
200 use warnings;
201 use ExtUtils::MakeMaker;
202 use PDL::Core::Dev;
203 my \@pack = [ "$modfname.pd", "$modfname", "$module" ];
204 my %options = %\{
205 END
206 2 local $Data::Dumper::Terse = 1;
207 2 local $Data::Dumper::Indent = 1;
208 2 print $fh Data::Dumper::Dumper(\ %options);
209 2 print $fh <<END;
210 \};
211 WriteMakefile(%options);
212 sub MY::postamble { pdlpp_postamble$coredev_suffix(\@pack); }
213 END
214 2 close $fh;
215 }
216  
217 #==============================================================================
218 # Run the build process.
219 #==============================================================================
220 sub compile {
221 2 ▶ my $o = shift;
Subroutine compile: called CC=2 SCAR=7.1
Pod undocumented
222 # grep is because on Windows, Cwd::abs_path blows up on non-exist dir
223 local $ENV{PERL5LIB} = join $Config{path_sep}, map abs_path($_), grep -e, @INC
224 2 ▶ unless defined $ENV{PERL5LIB};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ENV{"PERL5LIB"} 0 2 2
225 2 $o->SUPER::compile;
226 }
227 ▶sub fix_make { } # our Makefile.PL doesn't need this
Subroutine fix_make: called CC=1 SCAR=0.0
Pod undocumented
228  
229 2 1;
230  
231 __END__
« blib/lib/PDL/Options.pm ↑ Summary blib/lib/PDL/CallExt.pm »