10 unlink "XSLoader.pm" if -f "XSLoader.pm";
11 open OUT, ">XSLoader.pm" or die $!;
13 # Generated from XSLoader.pm.PL (resolved %Config::Config value)
17 # And Gandalf said: 'Many folk like to know beforehand what is to
18 # be set on the table; but those who have laboured to prepare the
19 # feast like to keep their secret; for wonder makes the words of
22 # (Quote from Tolkien sugested by Anno Siegel.)
24 # See pod text at end of file for documentation.
25 # See also ext/DynaLoader/README in source tree for other information.
27 # Tim.Bunce@ig.co.uk, August 1994
29 $VERSION = "0.01"; # avoid typo warning
31 # enable debug/trace messages from DynaLoader perl code
32 # $dl_debug = $ENV{PERL_DL_DEBUG} || 0 unless defined $dl_debug;
36 print OUT ' my $dl_dlext = ', to_string($Config::Config{'dlext'}), ";\n" ;
42 # No prizes for guessing why we don't say 'bootstrap DynaLoader;' here.
43 # NOTE: All dl_*.xs (including dl_none.xs) define a dl_error() XSUB
44 boot_DynaLoader('DynaLoader') if defined(&boot_DynaLoader) &&
50 # The bootstrap function cannot be autoloaded (without complications)
51 # so we define it here:
58 # work with static linking too
59 my $b = "$module\::bootstrap";
60 goto &$b if defined &$b;
62 goto retry unless $module and defined &dl_load_file;
64 my @modparts = split(/::/,$module);
65 my $modfname = $modparts[-1];
69 print OUT <<'EOT' if defined &DynaLoader::mod2fname;
70 # Some systems have restrictions on files names for DLL's etc.
71 # mod2fname returns appropriate file base name (typically truncated)
72 # It may also edit @modparts if required.
73 $modfname = &mod2fname(\@modparts) if defined &mod2fname;
78 my $modpname = join('/',@modparts);
79 my $modlibname = (caller())[1];
81 $modlibname =~ s,[\\/][^\\/]+$,, while $c--; # Q&D basename
82 my $file = "$modlibname/auto/$modpname/$modfname.$dl_dlext";
84 # print STDERR "XSLoader::load for $module ($file)\n" if $dl_debug;
87 $bs =~ s/(\.\w+)?(;\d*)?$/\.bs/; # look for .bs 'beside' the library
89 goto retry if not -f $file or -s $bs;
91 my $bootname = "boot_$module";
92 $bootname =~ s/\W/_/g;
93 @dl_require_symbols = ($bootname);
97 if ($^O eq 'darwin') {
98 if ($boot_symbol_ref = dl_find_symbol(0, $bootname)) {
99 goto boot; #extension library has already been loaded, e.g. darwin
103 # Many dynamic extension loading problems will appear to come from
104 # this section of code: XYZ failed at line 123 of DynaLoader.pm.
105 # Often these errors are actually occurring in the initialisation
106 # C code of the extension XS file. Perl reports the error as being
107 # in this perl code simply because this was the last perl code
110 my $libref = dl_load_file($file, 0) or do {
112 Carp::croak("Can't load '$file' for module $module: " . dl_error());
114 push(@dl_librefs,$libref); # record loaded object
116 my @unresolved = dl_undef_symbols();
119 Carp::carp("Undefined symbols present after loading $file: @unresolved\n");
122 $boot_symbol_ref = dl_find_symbol($libref, $bootname) or do {
124 Carp::croak("Can't find '$bootname' symbol in $file\n");
127 push(@dl_modules, $module); # record loaded module
130 my $xs = dl_install_xsub("${module}::bootstrap", $boot_symbol_ref, $file);
132 # See comment block above
137 goto &DynaLoader::bootstrap_inherit;
144 XSLoader - Dynamically load C libraries into Perl code
151 XSLoader::load 'YourPackage', @args;
155 This module defines a standard I<simplified> interface to the dynamic
156 linking mechanisms available on many platforms. Its primary purpose is
157 to implement cheap automatic dynamic loading of Perl modules.
159 For more complicated interface see L<DynaLoader>. Many (most)
160 features of DynaLoader are not implemented in XSLoader, like for
161 example the dl_load_flags is not honored by XSLoader.
165 Ilya Zakharevich: extraction from DynaLoader.