File Coverage

blib/lib/Inline/Pdlpp.pm
Criterion Covered Total %
statement 91 98 92.8
branch 10 22 45.4
condition 9 22 40.9
subroutine 21 23 91.3
pod 1 15 6.6
total 132 180 73.3


line stmt bran cond sub pod time code
1             package Inline::Pdlpp;
2              
3 1     1   270057 use strict;
  1         12  
  1         107  
4 1     1   34 use warnings;
  1         8  
  1         151  
5              
6 1     1   21 use Config;
  1         9  
  1         263  
7 1     1   15 use Data::Dumper;
  1         8  
  1         213  
8 1     1   8 use Carp;
  1         8  
  1         129  
9 1     1   8 use Cwd qw(cwd abs_path);
  1         5  
  1         119  
10 1     1   811 use PDL::Core::Dev;
  1         6  
  1         218  
11              
12             $Inline::Pdlpp::VERSION = '0.4';
13 1     1   22 use base qw(Inline::C);
  1         4  
  1         1760  
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     0 0 0 };
25             }
26              
27             # handle BLESS, INTERNAL - pass everything else up to Inline::C
28             sub validate {
29 2     2 0 3993 my $o = shift;
30 2   50     28 $o->{ILSM} ||= {};
31 2   50     37 $o->{ILSM}{XS} ||= {};
32             # Shouldn't use internal linking for Inline stuff, normally
33 2 50       10 $o->{ILSM}{INTERNAL} = 0 unless defined $o->{ILSM}{INTERNAL};
34 2   50     24 $o->{ILSM}{MAKEFILE} ||= {};
35 2 50       25 if (not $o->UNTAINT) {
36 2         32 $o->{ILSM}{MAKEFILE}{INC} = PDL::Core::Dev::PDL_INCLUDE();
37             }
38 2   50     12 $o->{ILSM}{AUTO_INCLUDE} ||= ' '; # not '' as Inline::C does ||=
39 2         12 my @pass_along;
40 2         11 while (@_) {
41 1         5 my ($key, $value) = (shift, shift);
42 1 50 33     13 if ($key eq 'INTERNAL' or
      33        
43             $key eq 'PACKAGE' or
44             $key eq 'BLESS'
45             ) {
46 1         8 $o->{ILSM}{$key} = $value;
47 1         15 next;
48             }
49 0         0 push @pass_along, $key, $value;
50             }
51 2         49 $o->SUPER::validate(@pass_along);
52             }
53              
54             #==============================================================================
55             # Parse and compile C code
56             #==============================================================================
57             sub build {
58 2     2 0 1968 my $o = shift;
59             # $o->parse; # no parsing in pdlpp
60 2         15 $o->get_maps; # get the typemaps
61 2         26 $o->write_PD;
62             # $o->write_Inline_headers; # shouldn't need this one either
63 2         11 $o->write_Makefile_PL;
64 2         12 $o->compile;
65             }
66              
67             #==============================================================================
68             # Return a small report about the C code..
69             #==============================================================================
70             sub info {
71 0     0 1 0 my $o = shift;
72 0         0 my $txt = <
73             The following PP code was generated (caution, can be long)...
74              
75             *** start PP file ****
76              
77             END
78 0         0 return $txt . $o->pd_generate . "\n*** end PP file ****\n";
79             }
80              
81             #==============================================================================
82             # Write the PDL::PP code into a PD file
83             #==============================================================================
84             sub write_PD {
85 2     2 0 4 my $o = shift;
86 2         10 my $modfname = $o->{API}{modfname};
87 2         22 my $module = $o->{API}{module};
88 2         47 $o->mkpath($o->{API}{build_dir});
89 2 50       1588 open my $fh, ">", "$o->{API}{build_dir}/$modfname.pd" or croak $!;
90 2         20 print $fh $o->pd_generate;
91 2         145 close $fh;
92             }
93              
94             #==============================================================================
95             # Generate the PDL::PP code (piece together a few snippets)
96             #==============================================================================
97             sub pd_generate {
98 2     2 0 6 my $o = shift;
99 2         8 return join "\n", ($o->pd_includes,
100             $o->pd_code,
101             $o->pd_boot,
102             $o->pd_bless,
103             $o->pd_done,
104             );
105             }
106              
107             sub pd_includes {
108 2     2 0 3 my $o = shift;
109 2         14 return << "END";
110             pp_addhdr << 'EOH';
111             $o->{ILSM}{AUTO_INCLUDE}
112             EOH
113              
114             END
115             }
116              
117             sub pd_code {
118 2     2 0 4 my $o = shift;
119 2         19 return $o->{API}{code};
120             }
121              
122             sub pd_boot {
123 2     2 0 4 my $o = shift;
124 2 0 33     7 if (defined $o->{ILSM}{XS}{BOOT} and
125             $o->{ILSM}{XS}{BOOT}) {
126 0         0 return <
127             pp_add_boot << 'EOB';
128             $o->{ILSM}{XS}{BOOT}
129             EOB
130              
131             END
132             }
133 2         10 return '';
134             }
135              
136              
137             sub pd_bless {
138 2     2 0 4 my $o = shift;
139 2 0 33     7 if (defined $o->{ILSM}{BLESS} and
140             $o->{ILSM}{BLESS}) {
141 0         0 return <
142             pp_bless $o->{ILSM}{BLESS};
143             END
144             }
145 2         10 return '';
146             }
147              
148              
149             sub pd_done {
150 2     2 0 42 return <
151             pp_done();
152             END
153             }
154              
155             sub get_maps {
156 2     2 0 4 my $o = shift;
157 2         48 $o->SUPER::get_maps;
158 2         314 push @{$o->{ILSM}{MAKEFILE}{TYPEMAPS}}, PDL::Core::Dev::PDL_TYPEMAP();
  2         12  
159             }
160              
161             #==============================================================================
162             # Generate the Makefile.PL
163             #==============================================================================
164             sub write_Makefile_PL {
165 2     2 0 4 my $o = shift;
166 2         4 my ($modfname,$module,$pkg) = @{$o->{API}}{qw(modfname module pkg)};
  2         15  
167 2 50       13 my $coredev_suffix = $o->{ILSM}{INTERNAL} ? '_int' : '';
168 2         9 my @pack = [ "$modfname.pd", $modfname, $module ];
169             my $stdargs_func = $o->{ILSM}{INTERNAL}
170 2 50       18 ? \&pdlpp_stdargs_int : \&pdlpp_stdargs;
171 2         10 my %hash = $stdargs_func->(@pack);
172 2         9 delete $hash{VERSION_FROM};
173             my %options = (
174             %hash,
175             VERSION => $o->{API}{version} || "0.00",
176 2         43 %{$o->{ILSM}{MAKEFILE}},
177             NAME => $o->{API}{module},
178             INSTALLSITEARCH => $o->{API}{install_lib},
179             INSTALLDIRS => 'site',
180             INSTALLSITELIB => $o->{API}{install_lib},
181 2   50     22 MAN3PODS => {},
182             PM => {},
183             );
184 2         10 my @postamblepack = ("$modfname.pd", $modfname, $module);
185 2 100       9 push @postamblepack, $o->{ILSM}{PACKAGE} if $o->{ILSM}{PACKAGE};
186 2         10 local $Data::Dumper::Terse = 1;
187 2         15 local $Data::Dumper::Indent = 1;
188 2 50       332 open my $fh, ">", "$o->{API}{build_dir}/Makefile.PL" or croak;
189 2         8 print $fh <
190             use strict;
191             use warnings;
192             use ExtUtils::MakeMaker;
193             use PDL::Core::Dev;
194 2         34 my \$pack = @{[ Data::Dumper::Dumper(\@postamblepack) ]};
195             my %options = %\{
196             END
197 2         432 print $fh Data::Dumper::Dumper(\%options);
198 2         327 print $fh <
199             \};
200             WriteMakefile(%options);
201             sub MY::postamble { pdlpp_postamble$coredev_suffix(\$pack); }
202             END
203 2         147 close $fh;
204             }
205              
206             #==============================================================================
207             # Run the build process.
208             #==============================================================================
209             sub compile {
210 2     2 0 6 my $o = shift;
211             # grep is because on Windows, Cwd::abs_path blows up on non-exist dir
212             local $ENV{PERL5LIB} = join $Config{path_sep}, map abs_path($_), grep -e, @INC
213 2 50       9 unless defined $ENV{PERL5LIB};
214 2         26 $o->SUPER::compile;
215             }
216       2 0   sub fix_make { } # our Makefile.PL doesn't need this
217              
218             1;
219              
220             __END__