File Coverage

blib/lib/Inline.pm
Criterion Covered Total %
statement 432 841 51.3
branch 152 440 34.5
condition 59 197 29.9
subroutine 60 132 45.4
pod 4 101 3.9
total 707 1711 41.3


line stmt bran cond sub pod time code
1 10     10   5109627 use strict; use warnings;
  10     10   39  
  10         393  
  10         45  
  10         24  
  10         847  
2             package Inline;
3              
4             our $VERSION = '0.87';
5              
6 10     10   4995 use Inline::denter;
  10         43  
  10         397  
7 10     10   67 use Config;
  10         17  
  10         474  
8 10     10   57 use Carp;
  10         21  
  10         641  
9 10     10   56 use Cwd qw(abs_path cwd);
  10         15  
  10         427  
10 10     10   3688 use Encode;
  10         116296  
  10         894  
11 10     10   64 use File::Spec;
  10         17  
  10         284  
12 10     10   42 use File::Spec::Unix;
  10         58  
  10         401  
13 10     10   86 use Fcntl qw(LOCK_EX LOCK_SH O_WRONLY O_CREAT);
  10         16  
  10         622  
14 10     10   2404 use version;
  10         11569  
  10         101  
15 10     10   4003 use utf8;
  10         1727  
  10         60  
16              
17 10   33     26345 use constant CAN_FLOCK => !(
18             $^O eq 'VMS' ||
19             $^O eq 'riscos' ||
20             $^O eq 'VOS'
21 10     10   647 );
  10         20  
22              
23             my %CONFIG = ();
24             my @DATA_OBJS = ();
25             my $INIT = 0;
26             my $version_requested = 0;
27             my $version_printed = 0;
28             my $untaint = 0;
29             my $safemode = 0;
30              
31             our $languages = undef;
32              
33             our $did = '_Inline'; # Default Inline Directory
34              
35             # This is the config file written by create_config_file().
36             our $configuration_file = 'config-' . $Config::Config{'archname'} . '-' . $];
37              
38             my %shortcuts =
39             (
40             NOCLEAN => [CLEAN_AFTER_BUILD => 0],
41             CLEAN => [CLEAN_BUILD_AREA => 1],
42             FORCE => [FORCE_BUILD => 1],
43             INFO => [PRINT_INFO => 1],
44             VERSION => [PRINT_VERSION => 1],
45             REPORTBUG => [REPORTBUG => 1],
46             UNTAINT => [UNTAINT => 1],
47             SAFE => [SAFEMODE => 1],
48             UNSAFE => [SAFEMODE => 0],
49             GLOBAL => [GLOBAL_LOAD => 1],
50             NOISY => [BUILD_NOISY => 1],
51             TIMERS => [BUILD_TIMERS => 1],
52             NOWARN => [WARNINGS => 0],
53             _INSTALL_ => [_INSTALL_ => 1],
54             SITE_INSTALL => undef, # No longer supported.
55             );
56              
57             my $default_config =
58             {
59             NAME => '',
60             AUTONAME => -1,
61             VERSION => '',
62             DIRECTORY => '',
63             WITH => [],
64             USING => [],
65              
66             CLEAN_AFTER_BUILD => 1,
67             CLEAN_BUILD_AREA => 0,
68             FORCE_BUILD => 0,
69             PRINT_INFO => 0,
70             PRINT_VERSION => 0,
71             REPORTBUG => 0,
72             UNTAINT => 0,
73             NO_UNTAINT_WARN => 0,
74             REWRITE_CONFIG_FILE => 0,
75             SAFEMODE => -1,
76             GLOBAL_LOAD => 0,
77             BUILD_NOISY => 0,
78             BUILD_TIMERS => 0,
79             WARNINGS => 1,
80             _INSTALL_ => 0,
81             _TESTING => 0,
82             };
83              
84 248     248 0 1323 sub UNTAINT {$untaint}
85 5     2 0 30 sub SAFEMODE {$safemode}
86              
87             #==============================================================================
88             # This is where everything starts.
89             #==============================================================================
90             sub import {
91 36     33   2020 my $class = shift;
92 36         530 $class->import_heavy(@_);
93             }
94              
95             sub import_heavy {
96 33     32 0 199 local ($/, $") = ("\n", ' '); local ($\, $,);
  33         104  
97              
98 33         257 my $o;
99 33         235 my ($pkg, $script) = caller(1);
100             # Not sure what this is for. Let's see what breaks.
101             # $pkg =~ s/^.*[\/\\]//;
102 33         284 my $class = shift;
103 33 50       259 if ($class ne 'Inline') {
104 1 0       6 croak M01_usage_use($class) if $class =~ /^Inline::/;
105 1         2 croak M02_usage();
106             }
107              
108 32   66     219 $CONFIG{$pkg}{template} ||= $default_config;
109              
110 32 100       167 return unless @_;
111 30 50       82 &create_config_file(), return 1 if $_[0] eq '_CONFIG_';
112 30 50       178 goto &maker_utils if $_[0] =~ /^(install|makedist|makeppd)$/i;
113              
114 30         77 my $control = shift;
115              
116 30 100 33     399 if (uc $control eq uc 'with') {
    100          
    100          
    50          
117 3         100 return handle_with($pkg, @_);
118             }
119             elsif (uc $control eq uc 'Config') {
120 9         45 return handle_global_config($pkg, @_);
121             }
122             elsif (exists $shortcuts{uc($control)}) {
123 2         12 handle_shortcuts($pkg, $control, @_);
124 1         64 $version_requested = $CONFIG{$pkg}{template}{PRINT_VERSION};
125 1         5 return;
126             }
127             elsif ($control =~ /^\S+$/ and $control !~ /\n/) {
128 19         40 my $language_id = $control;
129 19   100     184 my $option = shift || '';
130 19         46 my @config = @_;
131 19         31 my $next = 0;
132 19         132 for (@config) {
133 13 100       47 next if $next++ % 2;
134 7 50       25 croak M02_usage() if /[\s\n]/;
135             }
136 19         155 $o = bless {}, $class;
137 19         127 $o->{INLINE}{version} = $VERSION;
138 19         48 $o->{API}{pkg} = $pkg;
139 19         106 $o->{API}{script} = $script;
140 19         103 $o->{API}{language_id} = $language_id;
141 19 50 66     393 if ($option =~ /^(FILE|BELOW)$/i or
    100 33        
    100 33        
      100        
142             not $option and
143             defined $INC{File::Spec::Unix->catfile('Inline','Files.pm')} and
144             Inline::Files::get_filename($pkg)
145             ) {
146 1         93 $o->read_inline_file;
147 1         5 $o->{CONFIG} = handle_language_config($o->{CONFIG}, @config);
148             }
149             elsif ($option eq 'DATA' or not $option) {
150 6         38 $o->{CONFIG} = handle_language_config($o->{CONFIG}, @config);
151 6         210 push @DATA_OBJS, $o;
152 6         85934 return;
153             }
154             elsif (uc $option eq uc 'Config') {
155 4         21 $CONFIG{$pkg}{$language_id} = handle_language_config($CONFIG{$pkg}{$language_id}, @config);
156 4         107 return;
157             }
158             else {
159 11         63 $o->receive_code($option);
160 11         45 $o->{CONFIG} = handle_language_config($o->{CONFIG}, @config);
161             }
162             }
163             else {
164 1         184 croak M02_usage();
165             }
166 15         360018 $o->glue;
167             }
168              
169             #==============================================================================
170             # Run time version of import (public method)
171             #==============================================================================
172             sub bind {
173 8     4 1 1129 local ($/, $") = ("\n", ' '); local ($\, $,);
  3         8  
174              
175 3         9 my ($code, @config);
176 3         0 my $o;
177 3         8 my ($pkg, $script) = caller;
178 3         5 my $class = shift;
179 3 50       9 croak M03_usage_bind() unless $class eq 'Inline';
180              
181 3   33     11 $CONFIG{$pkg}{template} ||= $default_config;
182              
183 3 50       8 my $language_id = shift or croak M03_usage_bind();
184 3 50 33     30 croak M03_usage_bind()
185             unless ($language_id =~ /^\S+$/ and $language_id !~ /\n/);
186 3 50       10 $code = shift or croak M03_usage_bind();
187 3         6 @config = @_;
188              
189 3         5 my $next = 0;
190 3         6 for (@config) {
191 0 0       0 next if $next++ % 2;
192 0 0       0 croak M03_usage_bind() if /[\s\n]/;
193             }
194 3         7 $o = bless {}, $class;
195 3         19 $o->{INLINE}{version} = $VERSION;
196 3         117 $o->{API}{pkg} = $pkg;
197 3         12 $o->{API}{script} = $script;
198 3         6 $o->{API}{language_id} = $language_id;
199 3         16 $o->receive_code($code);
200 3         16 $o->{CONFIG} = handle_language_config($o->{CONFIG}, @config);
201              
202 3         12 $o->glue;
203             }
204              
205             #==============================================================================
206             # Process delayed objects that don't have source code yet.
207             #==============================================================================
208             # This code is an ugly hack because of the fact that you can't use an
209             # INIT block at "run-time proper". So we kill the warning and tell users
210             # to use an Inline->init() call if they run into problems. (rare)
211              
212 10     10   63 eval <
  10         15  
  10         701  
213             no warnings;
214             \$INIT = \$INIT; # Needed by Sarathy's patch.
215             sub INIT {
216             \$INIT++;
217             &init;
218             }
219             END
220              
221             sub init {
222 7     8 0 96 local ($/, $") = ("\n", ' '); local ($\, $,);
  7         26  
223              
224 7         57 while (my $o = shift(@DATA_OBJS)) {
225 5         42 $o->read_DATA;
226 5         29 $o->glue;
227             }
228             }
229              
230             sub END {
231 15 50   15   198713 warn M51_unused_DATA() if @DATA_OBJS;
232 15 50 33     319 print_version() if $version_requested && not $version_printed;
233             }
234              
235             #==============================================================================
236             # Print a small report about the version of Inline
237             #==============================================================================
238             sub print_version {
239 0 0   1 1 0 return if $version_printed++;
240 0         0 print STDERR <
241              
242             You are using Inline.pm version $VERSION
243              
244             END
245             }
246              
247             #==============================================================================
248             # Compile the source if needed and then dynaload the object
249             #==============================================================================
250             sub glue {
251 18     19 0 66 my $o = shift;
252 18         37 my ($pkg, $language_id) = @{$o->{API}}{qw(pkg language_id)};
  18         67  
253 18         136 my @config = (%{$CONFIG{$pkg}{template}},
254 18 100       123 %{$CONFIG{$pkg}{$language_id} || {}},
255 18 50       31 %{$o->{CONFIG} || {}},
  18         222  
256             );
257 18         129 @config = $o->check_config(@config);
258 18         104 $o->fold_options;
259              
260 18         95 $o->check_installed;
261 18 50       64 $o->env_untaint if UNTAINT;
262 18 50       78 if (not $o->{INLINE}{object_ready}) {
263 18         110 $o->check_config_file; # Final DIRECTORY set here.
264 14         123 push @config, $o->with_configs;
265 14         55 my $language = $o->{API}{language};
266 14 50       55 croak M04_error_nocode($language_id) unless $o->{API}{code};
267 14         67 $o->check_module;
268             }
269 14 50       48 $o->env_untaint if UNTAINT;
270 14 50       40 $o->obj_untaint if UNTAINT;
271 14 50       42 print_version() if $version_requested;
272 14 50       68 $o->reportbug() if $o->{CONFIG}{REPORTBUG};
273 14 50 33     65 if (not $o->{INLINE}{object_ready}
274             or $o->{CONFIG}{PRINT_INFO}
275             ) {
276 14         1502 eval "require $o->{INLINE}{ILSM_module}";
277 14 50       70 croak M05_error_eval('glue', $@) if $@;
278 14         168 $o->push_overrides;
279 14         49 bless $o, $o->{INLINE}{ILSM_module};
280 14         65 $o->validate(@config);
281             }
282             else {
283 0         0 $o->{CONFIG} = {(%{$o->{CONFIG}}, @config)};
  0         0  
284             }
285 13 50       43 $o->print_info if $o->{CONFIG}{PRINT_INFO};
286 13 50 33     104 unless ($o->{INLINE}{object_ready} or
287             not length $o->{INLINE}{ILSM_suffix}) {
288 13         45 $o->build();
289 13 50       200 $o->write_inl_file() unless $o->{CONFIG}{_INSTALL_};
290             }
291 13 50 33     231 if ($o->{INLINE}{ILSM_suffix} ne 'so' and
      33        
      33        
      33        
292             $o->{INLINE}{ILSM_suffix} ne 'dll' and
293             $o->{INLINE}{ILSM_suffix} ne 'bundle' and
294             $o->{INLINE}{ILSM_suffix} ne 'sl' and
295             ref($o) eq 'Inline'
296             ) {
297 0         0 eval "require $o->{INLINE}{ILSM_module}";
298 0 0       0 croak M05_error_eval('glue', $@) if $@;
299 0         0 $o->push_overrides;
300 0         0 bless $o, $o->{INLINE}{ILSM_module};
301 0         0 $o->validate(@config);
302             }
303 13         65 $o->load;
304 13         132 $o->pop_overrides;
305             }
306              
307             #==============================================================================
308             # Set up the USING overrides
309             #==============================================================================
310             sub push_overrides {
311 14     15 0 35 my ($o) = @_;
312 14         94 my ($language_id) = $o->{API}{language_id};
313 14         41 my ($ilsm) = $o->{INLINE}{ILSM_module};
314 14         29 for (@{$o->{CONFIG}{USING}}) {
  14         73  
315 0 0       0 my $fixed_name = /^Parser?(Pegex|RegExp|RecDescent)$/ ? "Parser::$1" : $_;
316 0         0 $fixed_name =~ s/^:://;
317 0 0       0 my $using_module = /^::/
    0          
318             ? "Inline::${language_id}::$fixed_name"
319             : /::/
320             ? $_
321             : "Inline::${language_id}::$fixed_name";
322 0         0 eval "require $using_module";
323 0 0       0 croak "Invalid module '$using_module' in USING list:\n$@" if $@;
324 0         0 my $register;
325 0         0 eval "\$register = $using_module->register";
326 0 0       0 croak "Invalid module '$using_module' in USING list:\n$@" if $@;
327 0         0 for my $override (@{$register->{overrides}}) {
  0         0  
328 10     10   99 no strict 'refs';
  10         18  
  10         954  
329 0 0       0 next if defined $o->{OVERRIDDEN}{$ilsm . "::$override"};
330             $o->{OVERRIDDEN}{$ilsm . "::$override"} =
331 0         0 \&{$ilsm . "::$override"};
  0         0  
332             {
333 10     10   55 no warnings 'redefine';
  10         14  
  10         3281  
  0         0  
334 0         0 *{$ilsm . "::$override"} =
335 0         0 \&{$using_module . "::$override"};
  0         0  
336             }
337             }
338             }
339             }
340              
341             #==============================================================================
342             # Restore the modules original methods
343             #==============================================================================
344             sub pop_overrides {
345 13 50   14 0 58 my $nowarn = $] >= 5.006 ? "no warnings 'redefine';" : '';
346 13         970 eval ($nowarn .
347             'my ($o) = @_;
348             for my $override (keys %{$o->{OVERRIDDEN}}) {
349             no strict "refs";
350             *{$override} = $o->{OVERRIDDEN}{$override};
351             }
352             delete $o->{OVERRIDDEN};')
353             }
354              
355             #==============================================================================
356             # Get source from the DATA filehandle
357             #==============================================================================
358             my (%DATA, %DATA_read);
359             sub read_DATA {
360 5     6 0 2467 require Socket;
361 5         16351 my ($marker, $marker_tag);
362 5         17 my $o = shift;
363 5         13 my ($pkg, $language_id) = @{$o->{API}}{qw(pkg language_id)};
  5         31  
364 5 100       36 unless ($DATA_read{$pkg}++) {
365 10     10   67 no strict 'refs';
  10         14  
  10         35116  
366 3         6 *Inline::DATA = *{$pkg . '::DATA'};
  3         40  
367 3         19 local ($/);
368 3         19 my ($CR, $LF) = (&Socket::CR, &Socket::LF);
369 3         221 (my $data = ) =~ s/$CR?$LF/\n/g;
370 3         11 @{$DATA{$pkg}} = split /(?m)^[ \t]{0,}(__\S+?__\n)/, $data;
  3         48  
371 3 50 50     8 shift @{$DATA{$pkg}} unless ($ {$DATA{$pkg}}[0] || '') =~ /__\S+?__\n/;
  3         16  
372             }
373 5         9 ($marker, $o->{API}{code}) = splice @{$DATA{$pkg}}, 0, 2;
  5         32  
374 5 50       18 croak M08_no_DATA_source_code($language_id)
375             unless defined $marker;
376 5         46 ($marker_tag = $marker) =~ s/__(\S+?)__\n/$1/;
377 5 50       21 croak M09_marker_mismatch($marker, $language_id)
378             unless $marker_tag eq $language_id;
379             }
380              
381             #==============================================================================
382             # Validate and store the non language-specific config options
383             #==============================================================================
384             sub check_config {
385 18     19 0 55 my $o = shift;
386 18         34 my @others;
387 18         54 while (@_) {
388 402         583 my ($key, $value) = (shift, shift);
389 402 100       539 if (defined $default_config->{$key}) {
390 396 100       778 if ($key =~ /^(WITH|USING)$/) {
391 36 50 33     193 croak M10_usage_WITH_USING()
392             if (ref $value and ref $value ne 'ARRAY');
393 36 50       92 $value = [$value] unless ref $value;
394 36         82 $o->{CONFIG}{$key} = $value;
395 36         72 next;
396             }
397 360 100       898 $o->{CONFIG}{$key} = $value, next if not $value;
398 89 100       258 if ($key eq 'DIRECTORY') {
    50          
    50          
399 16 50       403 croak M11_usage_DIRECTORY($value) unless (-d $value);
400 16         352 $value = abs_path($value);
401             }
402             elsif ($key eq 'NAME') {
403 0 0       0 croak M12_usage_NAME($value)
404             unless $value =~ /^[a-zA-Z_](\w|::)*$/;
405             }
406             elsif ($key eq 'VERSION') {
407 0 0       0 croak M13_usage_VERSION($value)
408             unless version::is_lax($value);
409             }
410 89         239 $o->{CONFIG}{$key} = $value;
411             }
412             else {
413 6         26 push @others, $key, $value;
414             }
415             }
416 18         1849 return (@others);
417             }
418              
419             #==============================================================================
420             # Set option defaults based on current option settings.
421             #==============================================================================
422             sub fold_options {
423 18     19 0 60 my $o = shift;
424              
425             # The following small section of code seems, to me, to be unnecessary - which is the
426             # reason that I've commented it out. I've left it here (including its associated comments)
427             # in case it later becomes evident that there *is* good reason to include it. --sisyphus
428             #
429             ## This bit tries to enable UNTAINT automatically if required when running the test suite.
430             # my $env_ha = $ENV{HARNESS_ACTIVE} || 0 ;
431             # my ($harness_active) = $env_ha =~ /(.*)/ ;
432             # if (($harness_active)&&(! $o->{CONFIG}{UNTAINT})){
433             # eval {
434             # require Scalar::Util;
435             # $o->{CONFIG}{UNTAINT} =
436             # (Scalar::Util::tainted(Cwd::cwd()) ? 1 : 0) ;
437             ## Disable SAFEMODE in the test suite, we know what we are doing...
438             # $o->{CONFIG}{SAFEMODE} = 0 ;
439             # warn "\n-[tT] enabled for test suite.
440             #Automatically setting UNTAINT=1 and SAFEMODE=0.\n"
441             # unless $Inline::_TAINT_WARNING_ ;
442             # $Inline::_TAINT_WARNING_ = 1 ;
443             # } ;
444             # }
445             ##
446 18   50     99 $untaint = $o->{CONFIG}{UNTAINT} || 0;
447             $safemode = (($o->{CONFIG}{SAFEMODE} == -1) ?
448             ($untaint ? 1 : 0) :
449             $o->{CONFIG}{SAFEMODE}
450 18 50       79 );
    50          
451 18 0 33     45 if (UNTAINT and
      33        
452             SAFEMODE and
453             not $o->{CONFIG}{DIRECTORY}) {
454 0 0 0     0 croak M49_usage_unsafe(1) if ($< == 0 or $> == 0);
455 0 0       0 warn M49_usage_unsafe(0) if $^W;
456             }
457 18 50       98 if ($o->{CONFIG}{AUTONAME} == -1) {
458 18 50       82 $o->{CONFIG}{AUTONAME} = length($o->{CONFIG}{NAME}) ? 0 : 1;
459             }
460             $o->{API}{cleanup} =
461 18   33     126 ($o->{CONFIG}{CLEAN_AFTER_BUILD} and not $o->{CONFIG}{REPORTBUG});
462             }
463              
464             #==============================================================================
465             # Check if Inline extension is preinstalled
466             #==============================================================================
467             sub check_installed {
468 18     19 0 30 my $o = shift;
469 18         55 $o->{INLINE}{object_ready} = 0;
470 18 50       99 unless ($o->{API}{code} =~ /^[A-Fa-f0-9]{32}$/) {
471 18         133 require Digest::MD5;
472 18         69 my $encoded_code = $o->{API}{code};
473 18 100       81 if ( utf8::is_utf8($encoded_code)) {
474 1         6 $encoded_code = Encode::encode_utf8($encoded_code);
475             }
476 18         136 $o->{INLINE}{md5} = Digest::MD5::md5_hex($encoded_code);
477             }
478             else {
479 0         0 $o->{INLINE}{md5} = $o->{API}{code};
480             }
481 18 50       81 return if $o->{CONFIG}{_INSTALL_};
482 18 50       65 return unless $o->{CONFIG}{VERSION};
483             croak M26_error_version_without_name()
484 0 0       0 unless $o->{CONFIG}{NAME};
485              
486 0         0 my @pkgparts = split(/::/, $o->{API}{pkg});
487 0         0 my $realname = File::Spec->catfile(@pkgparts) . '.pm';
488 0         0 my $realname_unix = File::Spec::Unix->catfile(@pkgparts) . '.pm';
489 0 0       0 my $realpath = $INC{$realname_unix}
490             or croak M27_module_not_indexed($realname_unix);
491              
492 0         0 my ($volume,$dir,$file) = File::Spec->splitpath($realpath);
493 0         0 my @dirparts = File::Spec->splitdir($dir);
494 0 0       0 pop @dirparts unless $dirparts[-1];
495 0         0 push @dirparts, $file;
496 0         0 my @endparts = splice(@dirparts, 0 - @pkgparts);
497              
498 0 0 0     0 $dirparts[-1] = 'arch'
499             if $dirparts[-2] eq 'blib' && $dirparts[-1] eq 'lib';
500 0 0       0 File::Spec->catfile(@endparts) eq $realname
501             or croak M28_error_grokking_path($realpath);
502 0         0 $realpath =
503             File::Spec->catpath($volume,File::Spec->catdir(@dirparts),"");
504              
505 0         0 $o->{API}{version} = $o->{CONFIG}{VERSION};
506 0         0 $o->{API}{module} = $o->{CONFIG}{NAME};
507 0         0 my @modparts = split(/::/,$o->{API}{module});
508 0         0 $o->{API}{modfname} = $modparts[-1];
509 0         0 $o->{API}{modpname} = File::Spec->catdir(@modparts);
510              
511 0         0 my $suffix = $Config{dlext};
512             my $obj = File::Spec->catfile($realpath,'auto',$o->{API}{modpname},
513 0         0 "$o->{API}{modfname}.$suffix");
514             croak M30_error_no_obj($o->{CONFIG}{NAME}, $o->{API}{pkg},
515 0 0       0 $realpath) unless -f $obj;
516              
517 0         0 @{$o->{CONFIG}}{qw( PRINT_INFO
  0         0  
518             REPORTBUG
519             FORCE_BUILD
520             _INSTALL_
521             )} = (0, 0, 0, 0);
522              
523 0         0 $o->{install_lib} = $realpath;
524 0         0 $o->{INLINE}{ILSM_type} = 'compiled';
525 0         0 $o->{INLINE}{ILSM_module} = 'Inline::C';
526 0         0 $o->{INLINE}{ILSM_suffix} = $suffix;
527 0         0 $o->{INLINE}{object_ready} = 1;
528             }
529              
530             #==============================================================================
531             # Dynamically load the object module
532             #==============================================================================
533             sub load {
534 0     1 0 0 my $o = shift;
535              
536 0 0       0 return if $o->{CONFIG}{_INSTALL_};
537              
538 0         0 my ($pkg, $module) = @{$o->{API}}{qw(pkg module)};
  0         0  
539 0 0       0 croak M42_usage_loader() unless $o->{INLINE}{ILSM_type} eq 'compiled';
540              
541 0         0 require DynaLoader;
542 0         0 @Inline::ISA = qw(DynaLoader);
543              
544 0 0       0 my $global = $o->{CONFIG}{GLOBAL_LOAD} ? '0x01' : '0x00';
545 0   0     0 my $version = $o->{API}{version} || '0.00';
546              
547 0         0 eval <
548             package $pkg;
549             push \@$ {pkg}::ISA, qw($module)
550             unless \$module eq "$pkg";
551             local \$$ {module}::VERSION = '$version';
552              
553             package $module;
554             push \@$ {module}::ISA, qw(Exporter DynaLoader);
555             sub dl_load_flags { $global }
556             ${module}::->bootstrap;
557             END
558 0 0       0 croak M43_error_bootstrap($module, $@) if $@;
559             }
560              
561             #==============================================================================
562             # Create file that satisfies the Makefile dependency for this object
563             #==============================================================================
564              
565             sub satisfy_makefile_dep {
566 0     5 0 0 my $o = shift;
567              
568 0         0 my $inline = $o->{API}{modinlname};
569 0 0       0 open my $fh, ">", $inline
570             or croak M24_open_for_output_failed($inline);
571 0         0 print $fh "*** AUTOGENERATED by Inline.pm ***\n\n";
572 0         0 print $fh "This file satisfies the make dependency for ";
573 0         0 print $fh "$o->{API}{module}\n";
574 0         0 close $fh;
575 0         0 return;
576             }
577              
578             #==============================================================================
579             # Process the config options that apply to all Inline sections
580             #==============================================================================
581             sub handle_global_config {
582 8     8 0 17 my $pkg = shift;
583 8         30 while (@_) {
584 13         59 my ($key, $value) = (uc shift, shift);
585 13 50       49 croak M02_usage() if $key =~ /[\s\n]/;
586 13 100       59 if ($key =~ /^(ENABLE|DISABLE)$/) {
587 2 50       10 ($key, $value) = (uc $value, $key eq 'ENABLE' ? 1 : 0);
588             }
589             croak M47_invalid_config_option($key)
590 13 50       50 unless defined $default_config->{$key};
591 13         79827 $CONFIG{$pkg}{template}{$key} = $value;
592             }
593             }
594              
595             #==============================================================================
596             # Process the config options that apply to a particular language
597             #==============================================================================
598             sub handle_language_config {
599 21 100   21 0 40 my %merge_with = %{ shift || {} };
  21         183  
600 21         48 my @values;
601 21         61 while (@_) {
602 6         24 my ($key, $value) = (uc shift, shift);
603 6 50       23 croak M02_usage() if $key =~ /[\s\n]/;
604 6 100       36 if ($key eq 'ENABLE') {
    50          
605 4         23 push @values, uc $value, 1;
606             }
607             elsif ($key eq 'DISABLE') {
608 0         0 push @values, uc $value, 0;
609             }
610             else {
611 2         9 push @values, $key, $value;
612             }
613             }
614 21         90 return {%merge_with, @values};
615             }
616              
617             #==============================================================================
618             # Validate and store shortcut config options
619             #==============================================================================
620             sub handle_shortcuts {
621 1     1 0 3 my $pkg = shift;
622              
623 1         6 for my $option (@_) {
624 2         5 my $OPTION = uc($option);
625 2 50       9 if ($OPTION eq 'SITE_INSTALL') {
    100          
626 0         0 croak M58_site_install();
627             }
628             elsif ($shortcuts{$OPTION}) {
629 1         2 my ($method, $arg) = @{$shortcuts{$OPTION}};
  1         8  
630 1         7 $CONFIG{$pkg}{template}{$method} = $arg;
631             }
632             else {
633 1         35 croak M48_usage_shortcuts($option);
634             }
635             }
636             }
637              
638             #==============================================================================
639             # Process the with command
640             #==============================================================================
641             sub handle_with {
642 2     2 0 6 my $pkg = shift;
643 2 50       4 croak M45_usage_with() unless @_;
644 2         4 for (@_) {
645 2 50       15 croak M02_usage() unless /^[\w:]+$/;
646 2         94 eval "require $_;";
647 2 50       8 croak M46_usage_with_bad($_) . $@ if $@;
648 2         4 push @{$CONFIG{$pkg}{template}{WITH}}, $_;
  2         14  
649             }
650             }
651              
652             #==============================================================================
653             # Perform cleanup duties
654             #==============================================================================
655             sub DESTROY {
656 21     21   3089 my $o = shift;
657 21 50       335895 $o->clean_build if $o->{CONFIG}{CLEAN_BUILD_AREA};
658             }
659              
660             #==============================================================================
661             # Get the source code
662             #==============================================================================
663             sub receive_code {
664 13     13 0 22 my $o = shift;
665 13         21 my $code = shift;
666              
667 13 50 33     86 croak M02_usage() unless (defined $code and $code);
668              
669 13 50 66     104 if (ref $code eq 'CODE') {
    50          
    100          
670 0         0 $o->{API}{code} = &$code;
671             }
672             elsif (ref $code eq 'ARRAY') {
673 0         0 $o->{API}{code} = join '', @$code;
674             }
675             elsif ($code =~ m|[/\\:]| and
676             $code =~ m|^[/\\:\w.\-\ \$\[\]<>]+$|) {
677             open my $fh, "<", $code
678             or croak(
679 6     6   2805 $!{ENOENT}
  6         9913  
  6         60  
680 1 0       54 ? M07_code_file_does_not_exist($code)
    50          
681             : M06_code_file_failed_open($code)
682             );
683 1         4 local $/;
684 1         34 $o->{API}{code} = readline $fh;
685             }
686             else {
687 12         42 $o->{API}{code} = $code;
688             }
689             }
690              
691             #==============================================================================
692             # Get the source code from an Inline::Files filehandle
693             #==============================================================================
694             sub read_inline_file {
695 0     0 0 0 my $o = shift;
696 0         0 my ($lang, $pkg) = @{$o->{API}}{qw(language_id pkg)};
  0         0  
697 0         0 my $langfile = uc($lang);
698 0 0       0 croak M59_bad_inline_file($lang) unless $langfile =~ /^[A-Z]\w*$/;
699             croak M60_no_inline_files()
700 0 0 0     0 unless (defined $INC{File::Spec::Unix->catfile("Inline","Files.pm")} and
      0        
701             $Inline::Files::VERSION =~ /^\d\.\d\d$/ and
702             $Inline::Files::VERSION ge '0.51');
703 0 0       0 croak M61_not_parsed() unless $lang = Inline::Files::get_filename($pkg);
704             {
705 10     10   2751 no strict 'refs';
  10         18  
  10         7366  
  0         0  
706 0         0 local $/;
707 0         0 $Inline::FILE = \*{"${pkg}::$langfile"};
  0         0  
708             # open $Inline::FILE;
709 0         0 $o->{API}{code} = <$Inline::FILE>;
710             # close $Inline::FILE;
711             }
712             }
713              
714             #==============================================================================
715             # Read the cached config file from the Inline directory. This will indicate
716             # whether the Language code is valid or not.
717             #==============================================================================
718             sub check_config_file {
719 18     18 0 33 my ($DIRECTORY, %config);
720 18         36 my $o = shift;
721              
722 18 50       49 croak M14_usage_Config() if $Inline::Config::VERSION;
723             croak M63_no_source($o->{API}{pkg})
724 18 50       69 if $o->{INLINE}{md5} eq $o->{API}{code};
725              
726             # First make sure we have the DIRECTORY
727 18 50       48 if ($o->{CONFIG}{_INSTALL_}) {
728             croak M15_usage_install_directory()
729 0 0       0 if $o->{CONFIG}{DIRECTORY};
730 0         0 my $cwd = Cwd::cwd();
731             $DIRECTORY =
732 0         0 $o->{INLINE}{DIRECTORY} = File::Spec->catdir($cwd, $did);
733 0 0       0 _mkdir($DIRECTORY, 0777)
734             or croak M16_DIRECTORY_mkdir_failed($DIRECTORY);
735             }
736             else {
737             $DIRECTORY = $o->{INLINE}{DIRECTORY} =
738 18   66     86 $o->{CONFIG}{DIRECTORY} || $o->find_temp_dir;
739             }
740              
741 18 100       88 if($o->{CONFIG}{REWRITE_CONFIG_FILE}) {
742 1 50       51 if(-e File::Spec->catfile($DIRECTORY, $configuration_file)) {
743 1         160 my $unlink = unlink(File::Spec->catfile($DIRECTORY, $configuration_file));
744 1 50       9 if(!$unlink) {warn "REWRITE_CONFIG_FILE is set, but removal of config file failed"}
  0         0  
745 1 50       23 else {warn "config file removal successful\n" if $o->{CONFIG}{_TESTING}}
746             }
747             }
748              
749             my $load_cfg = sub {
750 22 100   22   1171 $o->create_config_file($DIRECTORY)
751             if not -s File::Spec->catfile($DIRECTORY, $configuration_file);
752              
753 22 50       6104 open my $fh, "<", File::Spec->catfile($DIRECTORY,$configuration_file)
754             or croak M17_config_open_failed($DIRECTORY);
755 22         335 flock($fh, LOCK_SH) if CAN_FLOCK;
756 22         61 my $config = do { local $/; readline $fh };
  22         235  
  22         965  
757 22         295 close $fh;
758              
759 22 50       263 unless($config =~ /^version :/) {
760 0         0 warn "\$load_cfg sub: \$config: *${config}*\n";
761 0         0 croak M62_invalid_config_file(File::Spec->catfile($DIRECTORY,$configuration_file));
762             }
763              
764 22 50       213 if(UNTAINT) {
765             warn "In Inline::check_config_file(): Blindly untainting Inline configuration file information.\n"
766 0 0       0 unless $o->{CONFIG}{NO_UNTAINT_WARN};
767 0         0 ($config) = $config =~ /(.*)/s;
768             }
769              
770 22         567 %config = Inline::denter->new()->undent($config);
771 18         219 } ;
772              
773 18         57 $load_cfg->() ;
774 18 100       202 if (! defined $config{languages}->{$o->{API}{language_id}}){
775 4         730 my $unlink = unlink(File::Spec->catfile($DIRECTORY, $configuration_file));
776 4 50       33 if(!$unlink) {warn "Failed to remove config file"}
  0         0  
777 4 100       46 else {warn "config file removed\n" if $o->{CONFIG}{_TESTING}}
778 4         82 $load_cfg->() ;
779             }
780              
781 18         186 $Inline::languages = $config{languages};
782              
783             {
784 10     10   104 no warnings ('numeric'); # These warnings were a pain with devel releases.
  10         21  
  10         33616  
  18         71  
785             # If there's a problem with the version number, the
786             # error message will output $config{version} anyway.
787             croak M18_error_old_version($config{version}, $DIRECTORY)
788             unless (defined $config{version} and
789             $config{version} =~ /TRIAL/ or
790 18 50 33     383 $config{version} >= 0.40);
      33        
791             } # numeric warnings re-enabled.
792              
793             croak M19_usage_language($o->{API}{language_id}, $DIRECTORY)
794 18 100       165 unless defined $config{languages}->{$o->{API}{language_id}};
795 14         120 $o->{API}{language} = $config{languages}->{$o->{API}{language_id}};
796 14 100       112 if ($o->{API}{language} ne $o->{API}{language_id}) {
797 1 50       6 if (defined $o->{$o->{API}{language_id}}) {
798 0         0 $o->{$o->{API}{language}} = $o->{$o->{API}{language_id}};
799 0         0 delete $o->{$o->{API}{language_id}};
800             }
801             }
802              
803 14         119 $o->{INLINE}{ILSM_type} = $config{types}->{$o->{API}{language}};
804 14         158 $o->{INLINE}{ILSM_module} = $config{modules}->{$o->{API}{language}};
805 14         2231 $o->{INLINE}{ILSM_suffix} = $config{suffixes}->{$o->{API}{language}};
806             }
807              
808             sub derive_minus_I {
809 15     15 0 504 my $o = shift;
810 15         118 require Cwd;
811             my @libexclude = (
812             # perl has these already
813             (grep length, map $Config{$_},
814             qw(archlibexp privlibexp sitearchexp sitelibexp vendorarchexp vendorlibexp)),
815             (defined $ENV{PERL5LIB} ? (
816 15         35 map { my $l = $_; ($l, map File::Spec->catdir($l, $Config{$_}), qw(version archname)) }
  15         345  
817             split $Config{path_sep}, $ENV{PERL5LIB}
818 15 50       1504 ) : ()),
819             );
820 15 50       97 if ($^O eq 'MSWin32') {
821             # Strawberry Perl Unix-ises its @INC, so we need to add Unix-y versions
822             push @libexclude,
823 0         0 map { my $d = $_; $d =~ s#\\#/#g; $d }
  0         0  
  0         0  
  0         0  
824             @libexclude;
825             }
826 15         37 my %libexclude = map { $_=>1 } @libexclude;
  105         292  
827 15         49 my @libinclude = grep !$libexclude{$_}, grep { $_ ne '.' } @INC;
  140         295  
828             # grep is because on Windows, Cwd::abs_path blows up on non-exist dir
829 15         1480 @libinclude = map Cwd::abs_path($_), grep -e, @libinclude;
830 15         42 my %seen; @libinclude = grep !$seen{$_}++, @libinclude; # de-dup
  15         102  
831 15 50       35 @libinclude = map /(.*)/s, @libinclude if UNTAINT;
832 15         124 @libinclude;
833             }
834              
835             #==============================================================================
836             # Auto-detect installed Inline language support modules
837             #==============================================================================
838             sub create_config_file {
839 12     12 0 49 my ($o, $dir) = @_;
840              
841             # This subroutine actually fires off another instance of perl.
842             # with arguments that make this routine get called again.
843             # That way the queried modules don't stay loaded.
844 12 50       49 if (defined $o) {
845 12 50       34 ($dir) = $dir =~ /(.*)/s if UNTAINT;
846 12         782 my $perl = $Config{perlpath};
847 12 50       311 $perl = $^X unless -f $perl;
848 12 50       34 ($perl) = $perl =~ /(.*)/s if UNTAINT;
849 12 50       157 local $ENV{PERL5OPT} if defined $ENV{PERL5OPT};
850              
851 12         64 my @_inc = map "-I$_", $o->derive_minus_I;
852 12 50       949472 system $perl, @_inc, "-MInline=_CONFIG_", "-e1", "$dir"
853             and croak M20_config_creation_failed($dir);
854 12         1219 return;
855             }
856              
857 0         0 my ($lib, $mod, $register, %checked,
858             %languages, %types, %modules, %suffixes);
859 0         0 for my $lib (@INC) {
860 0 0       0 next unless -d File::Spec->catdir($lib,"Inline");
861 0 0       0 opendir my $dh, File::Spec->catdir($lib,"Inline")
862             or warn(M21_opendir_failed(File::Spec->catdir($lib,"Inline"))), next;
863 0         0 while ($mod = readdir($dh)) {
864 0 0       0 next unless $mod =~ /\.pm$/;
865 0         0 $mod =~ s/\.pm$//;
866 0 0       0 next if ($checked{$mod}++);
867 0 0       0 if ($mod eq 'Config') { # Skip Inline::Config
868 0         0 warn M14_usage_Config();
869 0         0 next;
870             }
871 0 0       0 next if $mod =~ /^(MakeMaker|denter|messages)$/;
872             # @INC is made safe by -T disallowing PERL5LIB et al
873 0         0 ($mod) = $mod =~ /(.*)/;
874 0         0 eval "require Inline::$mod;";
875 0 0       0 warn($@), next if $@;
876 0         0 eval "\$register=&Inline::${mod}::register";
877 0 0       0 next if $@;
878             my $language = ($register->{language})
879 0 0       0 or warn(M22_usage_register($mod)), next;
880 0         0 for (@{$register->{aliases}}) {
  0         0  
881             warn(M23_usage_alias_used($mod, $_, $languages{$_})), next
882 0 0       0 if defined $languages{$_};
883 0         0 $languages{$_} = $language;
884             }
885 0         0 $languages{$language} = $language;
886 0         0 $types{$language} = $register->{type};
887 0         0 $modules{$language} = "Inline::$mod";
888 0         0 $suffixes{$language} = $register->{suffix};
889             }
890 0         0 closedir $dh;
891             }
892              
893 0         0 my $file = File::Spec->catfile($ARGV[0], $configuration_file);
894 0 0       0 sysopen my $fh, $file, O_WRONLY | O_CREAT, 0666
895             or croak M24_open_for_output_failed($file);
896 0         0 flock($fh, LOCK_EX) if CAN_FLOCK;
897 0         0 truncate($fh, 0);
898 0         0 print $fh Inline::denter->new()
899             ->indent(*version => $Inline::VERSION,
900             *languages => \%languages,
901             *types => \%types,
902             *modules => \%modules,
903             *suffixes => \%suffixes,
904             );
905 0         0 close $fh;
906 0         0 exit 0;
907             }
908              
909             #==============================================================================
910             # Check to see if code has already been compiled
911             #==============================================================================
912             sub check_module {
913 14     14 0 31 my ($module, $module2);
914 14         55 my $o = shift;
915 14 50       71 return $o->install if $o->{CONFIG}{_INSTALL_};
916              
917 14 50       79 if ($o->{CONFIG}{NAME}) {
    100          
918 0         0 $module = $o->{CONFIG}{NAME};
919             }
920             elsif ($o->{API}{pkg} eq 'main') {
921 13         41 $module = $o->{API}{script};
922 13         472 my($v,$d,$file) = File::Spec->splitpath($module);
923 13         33 $module = $file;
924 13         94 $module =~ s|\W|_|g;
925 13         34 $module =~ s|^_+||;
926 13         47 $module =~ s|_+$||;
927 13 50       75 $module = 'FOO' if $module =~ /^_*$/;
928 13 50       74 $module = "_$module" if $module =~ /^\d/;
929             }
930             else {
931 1         3 $module = $o->{API}{pkg};
932             }
933              
934 14         95 $o->{API}{suffix} = $o->{INLINE}{ILSM_suffix};
935 14         57 $o->{API}{directory} = $o->{INLINE}{DIRECTORY};
936              
937 14         34 my $auto_level = 2;
938 14         54 while ($auto_level <= 5) {
939 14 50       46 if ($o->{CONFIG}{AUTONAME}) {
940             $module2 =
941 14         67 $module . '_' . substr($o->{INLINE}{md5}, 0, 2 + $auto_level);
942 14         26 $auto_level++;
943             } else {
944 0         0 $module2 = $module;
945 0         0 $auto_level = 6; # Don't loop on non-autoname objects
946             }
947 14         80 $o->{API}{module} = $module2;
948 14         53 my @modparts = split /::/, $module2;
949 14         56 $o->{API}{modfname} = $modparts[-1];
950 14         188 $o->{API}{modpname} = File::Spec->catdir(@modparts);
951             $o->{API}{build_dir} =
952             File::Spec->catdir($o->{INLINE}{DIRECTORY},
953 14         147 'build',$o->{API}{modpname});
954             $o->{API}{install_lib} =
955 14         100 File::Spec->catdir($o->{INLINE}{DIRECTORY}, 'lib');
956              
957             my $inl = File::Spec->catfile($o->{API}{install_lib},"auto",
958 14         187 $o->{API}{modpname},"$o->{API}{modfname}.inl");
959             $o->{API}{location} =
960             File::Spec->catfile($o->{API}{install_lib},"auto",$o->{API}{modpname},
961 14         169 "$o->{API}{modfname}.$o->{INLINE}{ILSM_suffix}");
962 14 50       910 last unless -f $inl;
963 0         0 my %inl;
964             {
965 0 0       0 open my $fh, "<", $inl or croak M31_inline_open_failed($inl);
  0         0  
966 0         0 local $/;
967 0         0 %inl = Inline::denter->new()->undent(readline $fh);
968             }
969 0 0       0 next unless ($o->{INLINE}{md5} eq $inl{md5});
970 0 0       0 next unless ($inl{inline_version} ge '0.40');
971 0 0       0 next unless ($inl{Config}{version} eq $Config::Config{version});
972 0 0       0 next unless ($inl{Config}{archname} eq $Config::Config{archname});
973 0 0       0 unless (-f $o->{API}{location}) {
974 0 0       0 warn <
975             Missing object file: $o->{API}{location}
976             For Inline file: $inl
977             END
978 0         0 next;
979             }
980 0 0       0 $o->{INLINE}{object_ready} = 1 unless $o->{CONFIG}{FORCE_BUILD};
981 0         0 last;
982             }
983 14         126 unshift @::INC, $o->{API}{install_lib};
984             }
985              
986             #==============================================================================
987             # Set things up so that the extension gets installed into the blib/arch.
988             # Then 'make install' will do the right thing.
989             #==============================================================================
990             sub install {
991 0     0 0 0 my ($module, $DIRECTORY);
992 0         0 my $o = shift;
993              
994             croak M64_install_not_c($o->{API}{language_id})
995 0 0       0 unless uc($o->{API}{language_id}) =~ /^(C|CPP|Java|Python|Ruby|Lisp|Pdlpp)$/ ;
996             croak M36_usage_install_main()
997 0 0       0 if ($o->{API}{pkg} eq 'main');
998             croak M37_usage_install_auto()
999 0 0       0 if $o->{CONFIG}{AUTONAME};
1000             croak M38_usage_install_name()
1001 0 0       0 unless $o->{CONFIG}{NAME};
1002             croak M39_usage_install_version()
1003 0 0       0 unless $o->{CONFIG}{VERSION};
1004             croak M40_usage_install_badname($o->{CONFIG}{NAME}, $o->{API}{pkg})
1005 0 0       0 unless $o->{CONFIG}{NAME} eq $o->{API}{pkg};
1006             # $o->{CONFIG}{NAME} =~ /^$o->{API}{pkg}::\w(\w|::)+$/
1007             # );
1008              
1009             my ($mod_name, $mod_ver, $ext_name, $ext_ver) =
1010 0         0 ($o->{API}{pkg}, $ARGV[0], @{$o->{CONFIG}}{qw(NAME VERSION)});
  0         0  
1011 0 0       0 croak M41_usage_install_version_mismatch($mod_name, $mod_ver,
1012             $ext_name, $ext_ver)
1013             unless ($mod_ver eq $ext_ver);
1014 0         0 $o->{INLINE}{INST_ARCHLIB} = $ARGV[1];
1015              
1016 0         0 $o->{API}{version} = $o->{CONFIG}{VERSION};
1017 0         0 $o->{API}{module} = $o->{CONFIG}{NAME};
1018 0         0 my @modparts = split(/::/,$o->{API}{module});
1019 0         0 $o->{API}{modfname} = $modparts[-1];
1020 0         0 $o->{API}{modpname} = File::Spec->catdir(@modparts);
1021 0         0 $o->{API}{modinlname} = join('-',@modparts).'.inl';
1022 0         0 $o->{API}{suffix} = $o->{INLINE}{ILSM_suffix};
1023             $o->{API}{build_dir} = File::Spec->catdir($o->{INLINE}{DIRECTORY},'build',
1024 0         0 $o->{API}{modpname});
1025 0         0 $o->{API}{directory} = $o->{INLINE}{DIRECTORY};
1026 0         0 my $cwd = Cwd::cwd();
1027             $o->{API}{install_lib} =
1028 0         0 File::Spec->catdir($cwd,$o->{INLINE}{INST_ARCHLIB});
1029             $o->{API}{location} =
1030             File::Spec->catfile($o->{API}{install_lib},"auto",$o->{API}{modpname},
1031 0         0 "$o->{API}{modfname}.$o->{INLINE}{ILSM_suffix}");
1032 0         0 unshift @::INC, $o->{API}{install_lib};
1033 0         0 $o->{INLINE}{object_ready} = 0;
1034             }
1035              
1036             #==============================================================================
1037             # Create the .inl file for an object
1038             #==============================================================================
1039             sub write_inl_file {
1040 13     13 0 32 my $o = shift;
1041             my $inl =
1042             File::Spec->catfile($o->{API}{install_lib},"auto",$o->{API}{modpname},
1043 13         206 "$o->{API}{modfname}.inl");
1044 13 50       1914 open my $fh, ">", $inl
1045             or croak "Can't create Inline validation file $inl: $!";
1046 13   33     2036 my $apiversion = $Config{apiversion} || $Config{xs_apiversion};
1047             print $fh Inline::denter->new()
1048             ->indent(*md5, $o->{INLINE}{md5},
1049             *name, $o->{API}{module},
1050             *version, $o->{CONFIG}{VERSION},
1051             *language, $o->{API}{language},
1052             *language_id, $o->{API}{language_id},
1053             *installed, $o->{CONFIG}{_INSTALL_},
1054             *date_compiled, scalar localtime,
1055             *inline_version, $Inline::VERSION,
1056 39         208 *ILSM, { map {($_, $o->{INLINE}{"ILSM_$_"})}
1057             (qw( module suffix type ))
1058             },
1059 13         142 *Config, { (map {($_,$Config{$_})}
  104         1180  
1060             (qw( archname osname osvers
1061             cc ccflags ld so version
1062             ))),
1063             (apiversion => $apiversion),
1064             },
1065             );
1066 13         811 close $fh;
1067             }
1068              
1069             #==============================================================================
1070             # Get config hints
1071             #==============================================================================
1072             sub with_configs {
1073 14     14 0 30 my $o = shift;
1074 14         30 my @configs;
1075 14         25 for my $mod (@{$o->{CONFIG}{WITH}}) {
  14         134  
1076 1         2 my $ref = eval { $mod->Inline($o->{API}{language}); };
  1         8  
1077 1 50       9 croak M25_no_WITH_support($mod, $@) if $@;
1078 1 50       3 croak M65_WITH_not_lang($mod, $o->{API}{language}) unless $ref;
1079 1         5 push @configs, %$ref;
1080             }
1081 14         93 return @configs;
1082             }
1083              
1084             #==============================================================================
1085             # Blindly untaint tainted fields in %ENV.
1086             #==============================================================================
1087             sub env_untaint {
1088 0     0 0 0 my $o = shift;
1089 0 0       0 warn "In Inline::env_untaint() : Blindly untainting tainted fields in %ENV.\n" unless $o->{CONFIG}{NO_UNTAINT_WARN};
1090              
1091             {
1092 10     10   100 no warnings ('uninitialized'); # In case $ENV{$_} is set to undef.
  10         42  
  10         10783  
  0         0  
1093 0         0 for (keys %ENV) {
1094 0         0 ($ENV{$_}) = $ENV{$_} =~ /(.*)/;
1095             }
1096             }
1097              
1098             # only accept dirs that are absolute and not world-writable
1099             $ENV{PATH} = $^O eq 'MSWin32' ?
1100 0 0       0 join ';', grep {not /^\./ and -d $_
1101             } split /;/, $ENV{PATH}
1102             :
1103 0 0 0     0 join ':', grep {/^\// and -d $_ and $< == $> ? 1 : not (-W $_ or -O $_)
    0 0        
1104 0 0       0 } split /:/, $ENV{PATH};
1105              
1106 0         0 map {($_) = /(.*)/} @INC;
  0         0  
1107              
1108             # list cherry-picked from `perldoc perlrun`
1109 0         0 delete @ENV{qw(PERL5OPT PERL5SHELL PERL_ROOT IFS CDPATH ENV BASH_ENV)};
1110 0 0       0 $ENV{SHELL} = '/bin/sh' if -x '/bin/sh';
1111              
1112 0 0       0 $< = $> if $< != $>; # so child processes retain euid - ignore failure
1113             }
1114             #==============================================================================
1115             # Blindly untaint tainted fields in Inline object.
1116             #==============================================================================
1117             sub obj_untaint {
1118 0     0 0 0 my $o = shift;
1119 0 0       0 warn "In Inline::obj_untaint() : Blindly untainting tainted fields in Inline object.\n" unless $o->{CONFIG}{NO_UNTAINT_WARN};
1120 0         0 ($o->{INLINE}{ILSM_module}) = $o->{INLINE}{ILSM_module} =~ /(.*)/;
1121 0         0 ($o->{API}{directory}) = $o->{API}{directory} =~ /(.*)/;
1122 0         0 ($o->{API}{build_dir}) = $o->{API}{build_dir} =~ /(.*)/;
1123 0         0 ($o->{CONFIG}{DIRECTORY}) = $o->{CONFIG}{DIRECTORY} =~ /(.*)/;
1124 0         0 ($o->{API}{install_lib}) = $o->{API}{install_lib} =~ /(.*)/;
1125 0         0 ($o->{API}{modpname}) = $o->{API}{modpname} =~ /(.*)/;
1126 0         0 ($o->{API}{modfname}) = $o->{API}{modfname} =~ /(.*)/;
1127 0         0 ($o->{API}{language}) = $o->{API}{language} =~ /(.*)/;
1128 0         0 ($o->{API}{pkg}) = $o->{API}{pkg} =~ /(.*)/;
1129 0         0 ($o->{API}{module}) = $o->{API}{module} =~ /(.*)/;
1130             }
1131              
1132             #==============================================================================
1133             # Clean the build directory from previous builds
1134             #==============================================================================
1135             sub clean_build {
1136 0     0 0 0 my $o = shift;
1137              
1138 0         0 my $prefix = $o->{INLINE}{DIRECTORY};
1139 0 0       0 opendir(my $dh, $prefix)
1140             or croak "Can't open build directory: $prefix for cleanup $!\n";
1141              
1142 0         0 while (my $dir = readdir($dh)) {
1143 0         0 my $maybedir = File::Spec->catdir($prefix,$dir);
1144 0 0 0     0 if (($maybedir and -d $maybedir) and ($dir =~ /\w{36,}/)) {
      0        
1145 0         0 $o->rmpath($prefix,$dir);
1146             }
1147             }
1148              
1149 0         0 close $dh;
1150             }
1151              
1152             #==============================================================================
1153             # Apply a list of filters to the source code
1154             #==============================================================================
1155             sub filter {
1156 0     0 0 0 my $o = shift;
1157 0         0 my $new_code = $o->{API}{code};
1158 0         0 for (@_) {
1159 0 0       0 croak M52_invalid_filter($_) unless ref;
1160 0 0       0 if (ref eq 'CODE') {
1161 0         0 $new_code = $_->($new_code);
1162             }
1163             else {
1164 0         0 $new_code = $_->filter($o, $new_code);
1165             }
1166             }
1167 0         0 return $new_code;
1168             }
1169              
1170             #==============================================================================
1171             # User wants to report a bug
1172             #==============================================================================
1173             sub reportbug {
1174 0     0 1 0 my $o = shift;
1175 0 0       0 return if $o->{INLINE}{reportbug_handled}++;
1176 0         0 print STDERR <
1177             <-----------------------REPORTBUG Section------------------------------------->
1178              
1179             REPORTBUG mode in effect.
1180              
1181             Your Inline $o->{API}{language_id} code will be processed in the build directory:
1182              
1183             $o->{API}{build_dir}
1184              
1185             A perl-readable bug report including your perl configuration and run-time
1186             diagnostics will also be generated in the build directory.
1187              
1188             When the program finishes please bundle up the above build directory with:
1189              
1190             tar czf Inline.REPORTBUG.tar.gz $o->{API}{build_dir}
1191              
1192             and send "Inline.REPORTBUG.tar.gz" as an email attachment to the author
1193             of the offending Inline::* module with the subject line:
1194              
1195             REPORTBUG: Inline.pm
1196              
1197             Include in the email, a description of the problem and anything else that
1198             you think might be helpful. Patches are welcome! :-\)
1199              
1200             <-----------------------End of REPORTBUG Section------------------------------>
1201             END
1202 0         0 my %versions;
1203             {
1204 10     10   78 no strict 'refs';
  10         16  
  10         2434  
  0         0  
1205 0         0 %versions = map {eval "use $_();"; ($_, $ {$_ . '::VERSION'})}
  0         0  
  0         0  
  0         0  
1206             qw (Digest::MD5 Parse::RecDescent
1207             ExtUtils::MakeMaker File::Path FindBin
1208             Inline
1209             );
1210             }
1211              
1212 0         0 $o->mkpath($o->{API}{build_dir});
1213             open my $fh, ">", File::Spec->catfile($o->{API}{build_dir},"REPORTBUG")
1214             or croak M24_open_for_output_failed
1215 0 0       0 (File::Spec->catfile($o->{API}{build_dir},"REPORTBUG"));
1216 0         0 %Inline::REPORTBUG_Inline_Object = ();
1217 0         0 %Inline::REPORTBUG_Perl_Config = ();
1218 0         0 %Inline::REPORTBUG_Module_Versions = ();
1219 0         0 print $fh Inline::denter->new()
1220             ->indent(*REPORTBUG_Inline_Object, $o,
1221             *REPORTBUG_Perl_Config, \%Config::Config,
1222             *REPORTBUG_Module_Versions, \%versions,
1223             );
1224 0         0 close $fh;
1225             }
1226              
1227             #==============================================================================
1228             # Print a small report if PRINT_INFO option is set.
1229             #==============================================================================
1230             sub print_info {
1231 10     10   59 use strict;
  10         19  
  10         2759  
1232 0     0 1 0 my $o = shift;
1233              
1234 0         0 print STDERR <
1235             <-----------------------Information Section----------------------------------->
1236              
1237             Information about the processing of your Inline $o->{API}{language_id} code:
1238              
1239             END
1240              
1241 0 0       0 print STDERR <{INLINE}{object_ready});
1242             Your module is already compiled. It is located at:
1243             $o->{API}{location}
1244              
1245             END
1246              
1247 0 0 0     0 print STDERR <{INLINE}{object_ready} and $o->{CONFIG}{FORCE_BUILD});
1248             But the FORCE_BUILD option is set, so your code will be recompiled.
1249             I\'ll use this build directory:
1250             $o->{API}{build_dir}
1251              
1252             and I\'ll install the executable as:
1253             $o->{API}{location}
1254              
1255             END
1256 0 0       0 print STDERR <{INLINE}{object_ready});
1257             Your source code needs to be compiled. I\'ll use this build directory:
1258             $o->{API}{build_dir}
1259              
1260             and I\'ll install the executable as:
1261             $o->{API}{location}
1262              
1263             END
1264              
1265 0         0 eval {
1266 0         0 print STDERR $o->info;
1267             };
1268 0 0       0 print $@ if $@;
1269              
1270 0         0 print STDERR <
1271              
1272             <-----------------------End of Information Section---------------------------->
1273             END
1274             }
1275              
1276             #==============================================================================
1277             # Hand off this invocation to Inline::MakeMaker
1278             #==============================================================================
1279             sub maker_utils {
1280 0     0 0 0 require Inline::MakeMaker;
1281 0         0 goto &Inline::MakeMaker::utils;
1282             }
1283              
1284             #==============================================================================
1285             # Utility subroutines
1286             #==============================================================================
1287              
1288             #==============================================================================
1289             # Make a path
1290             #==============================================================================
1291             sub mkpath {
1292 10     10   68 use strict;
  10         16  
  10         1841  
1293 13     13 0 44 my ($o, $mkpath) = @_;
1294 13         105 my($volume,$dirs,$nofile) = File::Spec->splitpath($mkpath,1);
1295 13         199 my @parts = File::Spec->splitdir($dirs);
1296 13         24 my @done;
1297 13         39 foreach (@parts){
1298 117         1163 push(@done,$_);
1299 117         957 my $path = File::Spec->catpath($volume,File::Spec->catdir(@done),"");
1300 117         353 _mkdir($path, 0777);
1301             }
1302 13 50       337 croak M53_mkdir_failed($mkpath)
1303             unless -d $mkpath;
1304             }
1305              
1306             #==============================================================================
1307             # Nuke a path (nicely)
1308             #==============================================================================
1309             sub rmpath {
1310 10     10   85 use strict;
  10         89  
  10         33546  
1311 0     0 0 0 my ($o, $prefix, $rmpath) = @_;
1312             # Nuke the target directory
1313 0 0       0 _rmtree(File::Spec->catdir($prefix ? ($prefix,$rmpath) : ($rmpath)));
1314             # Remove any empty directories underneath the requested one
1315 0         0 my @parts = File::Spec->splitdir($rmpath);
1316 0         0 while (@parts){
1317 0 0       0 $rmpath = File::Spec->catdir($prefix ? ($prefix,@parts) : @parts);
1318 0 0       0 ($rmpath) = $rmpath =~ /(.*)/ if UNTAINT;
1319 0 0       0 rmdir $rmpath
1320             or last; # rmdir failed because dir was not empty
1321 0         0 pop @parts;
1322             }
1323             }
1324              
1325             sub _rmtree {
1326 0     0   0 my($roots) = @_;
1327 0 0       0 $roots = [$roots] unless ref $roots;
1328 0         0 my($root);
1329 0         0 foreach $root (@{$roots}) {
  0         0  
1330 0 0       0 if ( -d $root ) {
1331 0         0 my(@names,@paths);
1332 0 0       0 if (opendir my $dh, $root) {
1333 0         0 @names = readdir $dh;
1334 0         0 closedir $dh;
1335             }
1336             else {
1337 0         0 croak M21_opendir_failed($root);
1338             }
1339              
1340 0         0 my $dot = File::Spec->curdir();
1341 0         0 my $dotdot = File::Spec->updir();
1342 0         0 foreach my $name (@names) {
1343 0 0 0     0 next if $name eq $dot or $name eq $dotdot;
1344 0         0 my $maybefile = File::Spec->catfile($root,$name);
1345 0 0 0     0 push(@paths,$maybefile),next if $maybefile and -f $maybefile;
1346 0         0 push(@paths,File::Spec->catdir($root,$name));
1347             }
1348              
1349 0         0 _rmtree(\@paths);
1350 0 0       0 ($root) = $root =~ /(.*)/ if UNTAINT;
1351 0 0       0 rmdir($root) or croak M54_rmdir_failed($root);
1352             }
1353             else {
1354 0 0       0 ($root) = $root =~ /(.*)/ if UNTAINT;
1355 0 0       0 unlink($root) or croak M55_unlink_failed($root);
1356             }
1357             }
1358             }
1359              
1360             #==============================================================================
1361             # Find the 'Inline' directory to use.
1362             #==============================================================================
1363             my $TEMP_DIR;
1364             sub find_temp_dir {
1365 2 100   2 0 8 return $TEMP_DIR if $TEMP_DIR;
1366              
1367 1         1 my ($temp_dir, $home, $bin, $cwd, $env);
1368 1         2 $temp_dir = '';
1369 1   50     3 $env = $ENV{PERL_INLINE_DIRECTORY} || '';
1370 1 50       20 $home = $ENV{HOME} ? abs_path($ENV{HOME}) : '';
1371              
1372 1 50 33     77 if ($env and
    50 33        
      33        
      33        
      33        
1373             -d $env and
1374             -w $env) {
1375 0         0 $temp_dir = $env;
1376             }
1377             elsif ($cwd = abs_path('.') and
1378             $cwd ne $home and
1379             -d File::Spec->catdir($cwd,".Inline") and
1380             -w File::Spec->catdir($cwd,".Inline")) {
1381 0         0 $temp_dir = File::Spec->catdir($cwd,".Inline");
1382             }
1383             else {
1384 1         598 require FindBin ;
1385 1 50 33     1177 if ($bin = $FindBin::Bin and
    50 33        
    50 33        
    50 33        
    50 33        
    0 33        
      33        
      33        
      33        
      33        
      33        
      33        
      33        
      33        
      0        
      0        
      0        
      0        
1386             -d File::Spec->catdir($bin,".Inline") and
1387             -w File::Spec->catdir($bin,".Inline")) {
1388 0         0 $temp_dir = File::Spec->catdir($bin,".Inline");
1389             }
1390             elsif ($home and
1391             -d File::Spec->catdir($home,".Inline") and
1392             -w File::Spec->catdir($home,".Inline")) {
1393 0         0 $temp_dir = File::Spec->catdir($home,".Inline");
1394             }
1395             elsif (defined $cwd and $cwd and
1396             -d File::Spec->catdir($cwd, $did) and
1397             -w File::Spec->catdir($cwd, $did)) {
1398 0         0 $temp_dir = File::Spec->catdir($cwd, $did);
1399             }
1400             elsif (defined $bin and $bin and
1401             -d File::Spec->catdir($bin, $did) and
1402             -w File::Spec->catdir($bin, $did)) {
1403 0         0 $temp_dir = File::Spec->catdir($bin, $did);
1404             }
1405             elsif (defined $cwd and $cwd and
1406             -d $cwd and
1407             -w $cwd and
1408             _mkdir(File::Spec->catdir($cwd, $did), 0777)) {
1409 1         8 $temp_dir = File::Spec->catdir($cwd, $did);
1410             }
1411             elsif (defined $bin and $bin and
1412             -d $bin and
1413             -w $bin and
1414             _mkdir(File::Spec->catdir($bin, $did), 0777)) {
1415 0         0 $temp_dir = File::Spec->catdir($bin, $did);
1416             }
1417             }
1418              
1419 1 50       3 croak M56_no_DIRECTORY_found()
1420             unless $temp_dir;
1421 1         30 return $TEMP_DIR = abs_path($temp_dir);
1422             }
1423              
1424             sub _mkdir {
1425 118     118   156 my $dir = shift;
1426 118   50     204 my $mode = shift || 0777;
1427 118 50       192 ($dir) = ($dir =~ /(.*)/) if UNTAINT;
1428 118         285 $dir =~ s|[/\\:]$||;
1429 118   66     3703 return mkdir($dir, $mode) || $!{EEXIST};
1430             }
1431              
1432             #==============================================================================
1433             # Error messages
1434             #==============================================================================
1435              
1436             sub M01_usage_use {
1437 0     0 0 0 my ($module) = @_;
1438 0         0 return <
1439             It is invalid to use '$module' directly. Please consult the Inline
1440             documentation for more information.
1441              
1442             END
1443             }
1444              
1445             sub M02_usage {
1446 0     0 0 0 my $usage = <
1447             Invalid usage of Inline module. Valid usages are:
1448             use Inline;
1449             use Inline language => "source-string", config-pair-list;
1450             use Inline language => "source-file", config-pair-list;
1451             use Inline language => [source-line-list], config-pair-list;
1452             use Inline language => 'DATA', config-pair-list;
1453             use Inline language => 'Config', config-pair-list;
1454             use Inline Config => config-pair-list;
1455             use Inline with => module-list;
1456             use Inline shortcut-list;
1457             END
1458             # This is broken ????????????????????????????????????????????????????
1459 0 0       0 $usage .= <
1460              
1461             Supported languages:
1462 0         0 ${\ join(', ', sort keys %$Inline::languages)}
1463              
1464             END
1465 0         0 return $usage;
1466             }
1467              
1468             sub M03_usage_bind {
1469 0     0 0 0 my $usage = <
1470             Invalid usage of the Inline->bind() function. Valid usages are:
1471             Inline->bind(language => "source-string", config-pair-list);
1472             Inline->bind(language => "source-file", config-pair-list);
1473             Inline->bind(language => [source-line-list], config-pair-list);
1474             END
1475              
1476 0 0       0 $usage .= <
1477              
1478             Supported languages:
1479 0         0 ${\ join(', ', sort keys %$Inline::languages)}
1480              
1481             END
1482 0         0 return $usage;
1483             }
1484              
1485             sub M04_error_nocode {
1486 0     0 0 0 my ($language) = @_;
1487 0         0 return <
1488             No $language source code found for Inline.
1489              
1490             END
1491             }
1492              
1493             sub M05_error_eval {
1494 0     0 0 0 my ($subroutine, $msg) = @_;
1495 0         0 return <
1496             An eval() failed in Inline::$subroutine:
1497             $msg
1498              
1499             END
1500             }
1501              
1502             sub M06_code_file_failed_open {
1503 0     0 0 0 my ($file) = @_;
1504 0         0 return <
1505             Couldn't open Inline code file '$file':
1506             $!
1507              
1508             END
1509             #'
1510             }
1511              
1512             sub M07_code_file_does_not_exist {
1513 0     0 0 0 my ($file) = @_;
1514 0         0 return <
1515             Inline assumes '$file' is a filename,
1516             and that file does not exist.
1517              
1518             END
1519             }
1520              
1521             sub M08_no_DATA_source_code {
1522 0     0 0 0 my ($lang) = @_;
1523 0         0 return <
1524             No source code in DATA section for Inline '$lang' section.
1525              
1526             END
1527             }
1528              
1529             sub M09_marker_mismatch {
1530 0     0 0 0 my ($marker, $lang) = @_;
1531 0         0 return <
1532             Marker '$marker' does not match Inline '$lang' section.
1533              
1534             END
1535             }
1536              
1537             sub M10_usage_WITH_USING {
1538 0     0 0 0 return <
1539             Config option WITH or USING must be a module name or an array ref
1540             of module names.
1541              
1542             END
1543             }
1544              
1545             sub M11_usage_DIRECTORY {
1546 0     0 0 0 my ($value) = @_;
1547 0         0 return <
1548             Invalid value '$value' for config option DIRECTORY
1549              
1550             END
1551             }
1552              
1553             sub M12_usage_NAME {
1554 0     0 0 0 my ($name) = @_;
1555 0         0 return <
1556             Invalid value for NAME config option: '$name'
1557              
1558             END
1559             }
1560              
1561             sub M13_usage_VERSION {
1562 0     0 0 0 my ($version) = @_;
1563 0         0 return <
1564             Invalid (according to version.pm) VERSION config option: '$version'
1565             (Should also be specified as a string rather than a floating point number)
1566              
1567             END
1568             }
1569              
1570             sub M14_usage_Config {
1571 0     0 0 0 return <
1572             As of Inline v0.30, use of the Inline::Config module is no longer supported
1573             or allowed. If Inline::Config exists on your system, it can be removed. See
1574             the Inline documentation for information on how to configure Inline.
1575              
1576             END
1577             }
1578              
1579             sub M15_usage_install_directory {
1580 0     0 0 0 return <
1581             Can't use the DIRECTORY option when installing an Inline extension module.
1582              
1583             END
1584             #'
1585             }
1586              
1587             sub M16_DIRECTORY_mkdir_failed {
1588 0     0 0 0 my ($dir) = @_;
1589 0         0 return <
1590             Can't mkdir $dir to build Inline code.
1591              
1592             END
1593             #'
1594             }
1595              
1596             sub M17_config_open_failed {
1597 0     0 0 0 my ($dir) = @_;
1598 0         0 my $file = File::Spec->catfile(${dir}, $configuration_file);
1599 0         0 return <
1600             Can't open ${file} for input.
1601              
1602             END
1603             #'
1604             }
1605              
1606             sub M18_error_old_version {
1607 0     0 0 0 my ($old_version, $directory) = @_;
1608 0   0     0 $old_version ||= '???';
1609 0         0 return <
1610             You are using Inline version $Inline::VERSION with a directory that was
1611             configured by Inline version $old_version. This version is no longer supported.
1612             Please delete the following directory and try again:
1613              
1614             $directory
1615              
1616             END
1617             }
1618              
1619             sub M19_usage_language {
1620 4     4 0 52 my ($language, $directory) = @_;
1621 4         117 require Config;
1622 4         23 return <
1623             Error. You have specified '$language' as an Inline programming language.
1624              
1625             I currently only know about the following languages:
1626 4 50       1216 ${ defined $Inline::languages ?
1627             \ join(', ', sort keys %$Inline::languages) : \ ''
1628             }
1629              
1630             If you have installed a support module for this language, try deleting the
1631             config-${Config::Config{'archname'}}-$] file from the following Inline DIRECTORY, and run again:
1632              
1633             $directory
1634              
1635             (And if that works, please file a bug report.)
1636              
1637             END
1638             }
1639              
1640             sub M20_config_creation_failed {
1641 0     0 0 0 my ($dir) = @_;
1642 0         0 my $file = File::Spec->catfile(${dir}, $configuration_file);
1643 0         0 return <
1644             Failed to autogenerate ${file}.
1645              
1646             END
1647             }
1648              
1649             sub M21_opendir_failed {
1650 0     0 0 0 my ($dir) = @_;
1651 0         0 return <
1652             Can't open directory '$dir'.
1653              
1654             END
1655             #'
1656             }
1657              
1658             sub M22_usage_register {
1659 0     0 0 0 my ($language, $error) = @_;
1660 0         0 return <
1661             The module Inline::$language does not support the Inline API, because it does
1662             properly support the register() method. This module will not work with Inline
1663             and should be uninstalled from your system. Please advise your sysadmin.
1664              
1665             The following error was generating from this module:
1666             $error
1667              
1668             END
1669             }
1670              
1671             sub M23_usage_alias_used {
1672 0     0 0 0 my ($new_mod, $alias, $old_mod) = @_;
1673 0         0 return <
1674             The module Inline::$new_mod is attempting to define $alias as an alias.
1675             But $alias is also an alias for Inline::$old_mod.
1676              
1677             One of these modules needs to be corrected or removed.
1678             Please notify the system administrator.
1679              
1680             END
1681             }
1682              
1683             sub M24_open_for_output_failed {
1684 0     0 0 0 my ($file) = @_;
1685 0         0 return <
1686             Can't open $file for output.
1687             $!
1688              
1689             END
1690             #'
1691             }
1692              
1693             sub M25_no_WITH_support {
1694 0     0 0 0 my ($mod, $err) = @_;
1695 0         0 return <
1696             You have requested "use Inline with => '$mod'"
1697             but '$mod' does not work with Inline.
1698              
1699             $err
1700              
1701             END
1702             }
1703              
1704             sub M26_error_version_without_name {
1705 0     0 0 0 return <
1706             Specifying VERSION option without NAME option is not permitted.
1707              
1708             END
1709             }
1710              
1711             sub M27_module_not_indexed {
1712 0     0 0 0 my ($mod) = @_;
1713 0         0 return <
1714             You are attempting to load an extension for '$mod',
1715             but there is no entry for that module in %INC.
1716              
1717             END
1718             }
1719              
1720             sub M28_error_grokking_path {
1721 0     0 0 0 my ($path) = @_;
1722 0         0 return <
1723             Can't calculate a path from '$path' in %INC
1724              
1725             END
1726             }
1727              
1728             sub M29_error_relative_path {
1729 0     0 0 0 my ($name, $path) = @_;
1730 0         0 return <
1731             Can't load installed extension '$name'
1732             from relative path '$path'.
1733              
1734             END
1735             #'
1736             }
1737              
1738             sub M30_error_no_obj {
1739 0     0 0 0 my ($name, $pkg, $path) = @_;
1740 0         0 <
1741             The extension '$name' is not properly installed in path:
1742             '$path'
1743              
1744             If this is a CPAN/distributed module, you may need to reinstall it on your
1745             system.
1746              
1747             To allow Inline to compile the module in a temporary cache, simply remove the
1748             Inline config option 'VERSION=' from the $pkg module.
1749              
1750             END
1751             }
1752              
1753             sub M31_inline_open_failed {
1754 0     0 0 0 my ($file) = @_;
1755 0         0 return <
1756             Can't open Inline validate file:
1757              
1758             $file
1759              
1760             $!
1761              
1762             END
1763             #'
1764             }
1765              
1766             sub M32_error_md5_validation {
1767 0     0 0 0 my ($md5, $inl) = @_;
1768 0         0 return <
1769             The source code fingerprint:
1770              
1771             $md5
1772              
1773             does not match the one in:
1774              
1775             $inl
1776              
1777             This module needs to be reinstalled.
1778              
1779             END
1780             }
1781              
1782             sub M33_error_old_inline_version {
1783 0     0 0 0 my ($inl) = @_;
1784 0         0 return <
1785             The following extension is not compatible with this version of Inline.pm.
1786              
1787             $inl
1788              
1789             You need to reinstall this extension.
1790              
1791             END
1792             }
1793              
1794             sub M34_error_incorrect_version {
1795 0     0 0 0 my ($inl) = @_;
1796 0         0 return <
1797             The version of your extension does not match the one indicated by your
1798             Inline source code, according to:
1799              
1800             $inl
1801              
1802             This module should be reinstalled.
1803              
1804             END
1805             }
1806              
1807             sub M35_error_no_object_file {
1808 0     0 0 0 my ($obj, $inl) = @_;
1809 0         0 return <
1810             There is no object file:
1811             $obj
1812              
1813             For Inline validation file:
1814             $inl
1815              
1816             This module should be reinstalled.
1817              
1818             END
1819             }
1820              
1821             sub M36_usage_install_main {
1822 0     0 0 0 return <
1823             Can't install an Inline extension module from package 'main'.
1824              
1825             END
1826             #'
1827             }
1828              
1829             sub M37_usage_install_auto {
1830 0     0 0 0 return <
1831             Can't install an Inline extension module with AUTONAME enabled.
1832              
1833             END
1834             #'
1835             }
1836              
1837             sub M38_usage_install_name {
1838 0     0 0 0 return <
1839             An Inline extension module requires an explicit NAME.
1840              
1841             END
1842             }
1843              
1844             sub M39_usage_install_version {
1845 0     0 0 0 return <
1846             An Inline extension module requires an explicit VERSION.
1847              
1848             END
1849             }
1850              
1851             sub M40_usage_install_badname {
1852 0     0 0 0 my ($name, $pkg) = @_;
1853 0         0 return <
1854             The NAME '$name' is illegal for this Inline extension.
1855             The NAME must match the current package name:
1856             $pkg
1857              
1858             END
1859             }
1860              
1861             sub M41_usage_install_version_mismatch {
1862 0     0 0 0 my ($mod_name, $mod_ver, $ext_name, $ext_ver) = @_;
1863 0         0 <
1864             The version '$mod_ver' for module '$mod_name' doe not match
1865             the version '$ext_ver' for Inline section '$ext_name'.
1866              
1867             END
1868             }
1869              
1870             sub M42_usage_loader {
1871 0     0 0 0 return <
1872             ERROR. The loader that was invoked is for compiled languages only.
1873              
1874             END
1875             }
1876              
1877             sub M43_error_bootstrap {
1878 0     0 0 0 my ($mod, $err) = @_;
1879 0         0 return <
1880             Had problems bootstrapping Inline module '$mod'
1881              
1882             $err
1883              
1884             END
1885             }
1886              
1887             sub M45_usage_with {
1888 0     0 0 0 return <
1889             Syntax error detected using 'use Inline with ...'.
1890             Should be specified as:
1891              
1892             use Inline with => 'module1', 'module2', ..., 'moduleN';
1893              
1894             END
1895             }
1896              
1897             sub M46_usage_with_bad {
1898 0     0 0 0 my $mod = shift;
1899 0         0 return <
1900             Syntax error detected using 'use Inline with => "$mod";'.
1901             '$mod' could not be found.
1902              
1903             END
1904             }
1905              
1906             sub M47_invalid_config_option {
1907 0     0 0 0 my ($option) = @_;
1908 0         0 return <
1909             Invalid Config option '$option'
1910              
1911             END
1912             #'
1913             }
1914              
1915             sub M48_usage_shortcuts {
1916 1     1 0 4 my ($shortcut) = @_;
1917 1         252 return <
1918             Invalid shortcut '$shortcut' specified.
1919              
1920             Valid shortcuts are:
1921             VERSION, INFO, FORCE, NOCLEAN, CLEAN, UNTAINT, SAFE, UNSAFE,
1922             GLOBAL, NOISY and REPORTBUG
1923              
1924             END
1925             }
1926              
1927             sub M49_usage_unsafe {
1928 0     0 0 0 my ($terminate) = @_;
1929             return <
1930             You are using the Inline.pm module with the UNTAINT and SAFEMODE options,
1931             but without specifying the DIRECTORY option. This is potentially unsafe.
1932             Either use the DIRECTORY option or turn off SAFEMODE.
1933              
1934             END
1935 0 0       0 ($terminate ? <
1936             Since you are running as a privileged user, Inline.pm is terminating.
1937              
1938             END
1939             }
1940              
1941             sub M51_unused_DATA {
1942 0     0 0 0 return <
1943             One or more DATA sections were not processed by Inline.
1944              
1945             END
1946             }
1947              
1948             sub M52_invalid_filter {
1949 0     0 0 0 my ($filter) = @_;
1950 0         0 return <
1951             Invalid filter '$filter' is not a reference.
1952              
1953             END
1954             }
1955              
1956             sub M53_mkdir_failed {
1957 0     0 0 0 my ($dir) = @_;
1958 0         0 return <
1959             Couldn't make directory path '$dir'.
1960              
1961             END
1962             #'
1963             }
1964              
1965             sub M54_rmdir_failed {
1966 0     0 0 0 my ($dir) = @_;
1967 0         0 return <
1968             Can't remove directory '$dir':
1969              
1970             $!
1971              
1972             END
1973             #'
1974             }
1975              
1976             sub M55_unlink_failed {
1977 0     0 0 0 my ($file) = @_;
1978 0         0 return <
1979             Can't unlink file '$file':
1980              
1981             $!
1982              
1983             END
1984             #'
1985             }
1986              
1987             sub M56_no_DIRECTORY_found {
1988 0     0 0 0 return <
1989             Couldn't find an appropriate DIRECTORY for Inline to use.
1990              
1991             END
1992             #'
1993             }
1994              
1995             sub M57_wrong_architecture {
1996 0     0 0 0 my ($ext, $arch, $thisarch) = @_;
1997 0         0 return <
1998             The extension '$ext'
1999             is built for perl on the '$arch' platform.
2000             This is the '$thisarch' platform.
2001              
2002             END
2003             }
2004              
2005             sub M58_site_install {
2006 0     0 0 0 return <
2007             You have specified the SITE_INSTALL command. Support for this option has
2008             been removed from Inline since version 0.40. It has been replaced by the
2009             use of Inline::MakeMaker in your Makefile.PL. Please see the Inline
2010             documentation for more help on creating and installing Inline based modules.
2011              
2012             END
2013             }
2014              
2015             sub M59_bad_inline_file {
2016 0     0 0 0 my ($lang) = @_;
2017 0         0 return <
2018             Could not find any Inline source code for the '$lang' language using
2019             the Inline::Files module.
2020              
2021             END
2022             }
2023              
2024             sub M60_no_inline_files {
2025 0     0 0 0 return <
2026             It appears that you have requested to use Inline with Inline::Files.
2027             You need to explicitly 'use Inline::Files;' before your 'use Inline'.
2028              
2029             END
2030             }
2031              
2032             sub M61_not_parsed {
2033 0     0 0 0 return <
2034             It does not appear that your program has been properly parsed by Inline::Files.
2035              
2036             END
2037             }
2038              
2039             sub M62_invalid_config_file {
2040 0     0 0 0 my ($config) = @_;
2041 0         0 return <
2042             You are using a config file that was created by an older version of Inline:
2043              
2044             $config
2045              
2046             This file and all the other components in its directory are no longer valid
2047             for this version of Inline. The best thing to do is simply delete all the
2048             contents of the directory and let Inline rebuild everything for you. Inline
2049             will do this automatically when you run your programs.
2050              
2051             END
2052             }
2053              
2054             sub M63_no_source {
2055 0     0 0 0 my ($pkg) = @_;
2056 0         0 return <
2057             This module $pkg can not be loaded and has no source code.
2058             You may need to reinstall this module.
2059              
2060             END
2061             }
2062              
2063             sub M64_install_not_c {
2064 0     0 0 0 my ($lang) = @_;
2065 0         0 return <
2066             Invalid attempt to install an Inline module using the '$lang' language.
2067              
2068             Only C and CPP (C++) based modules are currently supported.
2069              
2070             END
2071             }
2072              
2073             sub M65_WITH_not_lang {
2074 0     0 0 0 my ($mod, $lang) = @_;
2075 0         0 return <
2076             $mod gave no 'with' hints for $lang.
2077             END
2078             }
2079              
2080             1;