File Coverage

blib/lib/Inline/Pdlapp.pm
Criterion Covered Total %
statement 95 99 95.9
branch 10 22 45.4
condition 9 22 40.9
subroutine 22 23 95.6
pod 1 15 6.6
total 137 181 75.6


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