home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 March / PCWorld_2003-03_cd.bin / Software / Topware / activeperl / ActivePerl / Perl / lib / XSLoader.pm < prev   
Encoding:
Perl POD Document  |  2002-12-01  |  3.9 KB  |  139 lines

  1. # Generated from XSLoader.pm.PL (resolved %Config::Config value)
  2.  
  3. package XSLoader;
  4.  
  5. #   And Gandalf said: 'Many folk like to know beforehand what is to
  6. #   be set on the table; but those who have laboured to prepare the
  7. #   feast like to keep their secret; for wonder makes the words of
  8. #   praise louder.'
  9.  
  10. #   (Quote from Tolkien sugested by Anno Siegel.)
  11. #
  12. # See pod text at end of file for documentation.
  13. # See also ext/DynaLoader/README in source tree for other information.
  14. #
  15. # Tim.Bunce@ig.co.uk, August 1994
  16.  
  17. $VERSION = "0.01";    # avoid typo warning
  18.  
  19. # enable debug/trace messages from DynaLoader perl code
  20. # $dl_debug = $ENV{PERL_DL_DEBUG} || 0 unless defined $dl_debug;
  21.  
  22.   my $dl_dlext = 'dll';
  23.  
  24. package DynaLoader;
  25.  
  26. # No prizes for guessing why we don't say 'bootstrap DynaLoader;' here.
  27. # NOTE: All dl_*.xs (including dl_none.xs) define a dl_error() XSUB
  28. boot_DynaLoader('DynaLoader') if defined(&boot_DynaLoader) &&
  29.                                 !defined(&dl_error);
  30. package XSLoader;
  31.  
  32. 1; # End of main code
  33.  
  34. # The bootstrap function cannot be autoloaded (without complications)
  35. # so we define it here:
  36.  
  37. sub load {
  38.     package DynaLoader;
  39.  
  40.     my($module) = $_[0];
  41.  
  42.     # work with static linking too
  43.     my $b = "$module\::bootstrap";
  44.     goto &$b if defined &$b;
  45.  
  46.     goto retry unless $module and defined &dl_load_file;
  47.  
  48.     my @modparts = split(/::/,$module);
  49.     my $modfname = $modparts[-1];
  50.  
  51.     my $modpname = join('/',@modparts);
  52.     my $modlibname = (caller())[1];
  53.     my $c = @modparts;
  54.     $modlibname =~ s,[\\/][^\\/]+$,, while $c--;    # Q&D basename
  55.     my $file = "$modlibname/auto/$modpname/$modfname.$dl_dlext";
  56.  
  57. #   print STDERR "XSLoader::load for $module ($file)\n" if $dl_debug;
  58.  
  59.     my $bs = $file;
  60.     $bs =~ s/(\.\w+)?(;\d*)?$/\.bs/; # look for .bs 'beside' the library
  61.  
  62.     goto retry if not -f $file or -s $bs;
  63.  
  64.     my $bootname = "boot_$module";
  65.     $bootname =~ s/\W/_/g;
  66.     @dl_require_symbols = ($bootname);
  67.  
  68.     my $boot_symbol_ref;
  69.  
  70.     if ($^O eq 'darwin') {
  71.         if ($boot_symbol_ref = dl_find_symbol(0, $bootname)) {
  72.             goto boot; #extension library has already been loaded, e.g. darwin
  73.         }
  74.     }
  75.  
  76.     # Many dynamic extension loading problems will appear to come from
  77.     # this section of code: XYZ failed at line 123 of DynaLoader.pm.
  78.     # Often these errors are actually occurring in the initialisation
  79.     # C code of the extension XS file. Perl reports the error as being
  80.     # in this perl code simply because this was the last perl code
  81.     # it executed.
  82.  
  83.     my $libref = dl_load_file($file, 0) or do { 
  84.     require Carp;
  85.     Carp::croak("Can't load '$file' for module $module: " . dl_error());
  86.     };
  87.     push(@dl_librefs,$libref);  # record loaded object
  88.  
  89.     my @unresolved = dl_undef_symbols();
  90.     if (@unresolved) {
  91.     require Carp;
  92.     Carp::carp("Undefined symbols present after loading $file: @unresolved\n");
  93.     }
  94.  
  95.     $boot_symbol_ref = dl_find_symbol($libref, $bootname) or do {
  96.     require Carp;
  97.     Carp::croak("Can't find '$bootname' symbol in $file\n");
  98.     };
  99.  
  100.     push(@dl_modules, $module); # record loaded module
  101.  
  102.   boot:
  103.     my $xs = dl_install_xsub("${module}::bootstrap", $boot_symbol_ref, $file);
  104.  
  105.     # See comment block above
  106.     return &$xs(@_);
  107.  
  108.   retry:
  109.     require DynaLoader;
  110.     goto &DynaLoader::bootstrap_inherit;
  111. }
  112.  
  113. __END__
  114.  
  115. =head1 NAME
  116.  
  117. XSLoader - Dynamically load C libraries into Perl code
  118.  
  119. =head1 SYNOPSIS
  120.  
  121.     package YourPackage;
  122.     use XSLoader;
  123.  
  124.     XSLoader::load 'YourPackage', @args;
  125.  
  126. =head1 DESCRIPTION
  127.  
  128. This module defines a standard I<simplified> interface to the dynamic
  129. linking mechanisms available on many platforms.  Its primary purpose is
  130. to implement cheap automatic dynamic loading of Perl modules.
  131.  
  132. For more complicated interface see L<DynaLoader>.
  133.  
  134. =head1 AUTHOR
  135.  
  136. Ilya Zakharevich: extraction from DynaLoader.
  137.  
  138. =cut
  139.