home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / perl / 5.8.8 / DynaLoader.pm < prev    next >
Encoding:
Perl POD Document  |  2007-03-05  |  8.7 KB  |  256 lines

  1. # Generated from DynaLoader.pm.PL
  2.  
  3. package DynaLoader;
  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 suggested 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. use vars qw($VERSION *AUTOLOAD);
  18.  
  19. $VERSION = '1.04';    # avoid typo warning
  20.  
  21. require AutoLoader;
  22. *AUTOLOAD = \&AutoLoader::AUTOLOAD;
  23.  
  24. use Config;
  25.  
  26. # The following require can't be removed during maintenance
  27. # releases, sadly, because of the risk of buggy code that does 
  28. # require Carp; Carp::croak "..."; without brackets dying 
  29. # if Carp hasn't been loaded in earlier compile time. :-( 
  30. # We'll let those bugs get found on the development track.
  31. require Carp if $] < 5.00450; 
  32.  
  33. # enable debug/trace messages from DynaLoader perl code
  34. $dl_debug = $ENV{PERL_DL_DEBUG} || 0 unless defined $dl_debug;
  35.  
  36. #
  37. # Flags to alter dl_load_file behaviour.  Assigned bits:
  38. #   0x01  make symbols available for linking later dl_load_file's.
  39. #         (only known to work on Solaris 2 using dlopen(RTLD_GLOBAL))
  40. #         (ignored under VMS; effect is built-in to image linking)
  41. #
  42. # This is called as a class method $module->dl_load_flags.  The
  43. # definition here will be inherited and result on "default" loading
  44. # behaviour unless a sub-class of DynaLoader defines its own version.
  45. #
  46.  
  47. sub dl_load_flags { 0x00 }
  48.  
  49. # ($dl_dlext, $dlsrc)
  50. #         = @Config::Config{'dlext', 'dlsrc'};
  51.   ($dl_dlext, $dlsrc) = ('so','dl_dlopen.xs')
  52. ;
  53. # Some systems need special handling to expand file specifications
  54. # (VMS support by Charles Bailey <bailey@HMIVAX.HUMGEN.UPENN.EDU>)
  55. # See dl_expandspec() for more details. Should be harmless but
  56. # inefficient to define on systems that don't need it.
  57. $Is_VMS    = $^O eq 'VMS';
  58. $do_expand = $Is_VMS;
  59. $Is_MacOS  = $^O eq 'MacOS';
  60.  
  61. my $Mac_FS;
  62. $Mac_FS = eval { require Mac::FileSpec::Unixish } if $Is_MacOS;
  63.  
  64. @dl_require_symbols = ();       # names of symbols we need
  65. @dl_resolve_using   = ();       # names of files to link with
  66. @dl_library_path    = ();       # path to look for files
  67.  
  68. #XSLoader.pm may have added elements before we were required
  69. #@dl_librefs         = ();       # things we have loaded
  70. #@dl_modules         = ();       # Modules we have loaded
  71.  
  72. # This is a fix to support DLD's unfortunate desire to relink -lc
  73. @dl_resolve_using = dl_findfile('-lc') if $dlsrc eq "dl_dld.xs";
  74.  
  75. # Initialise @dl_library_path with the 'standard' library path
  76. # for this platform as determined by Configure.
  77.  
  78. push(@dl_library_path, split(' ', $Config::Config{libpth}));
  79.  
  80. my $ldlibpthname         = $Config::Config{ldlibpthname};
  81. my $ldlibpthname_defined = defined $Config::Config{ldlibpthname};
  82. my $pthsep               = $Config::Config{path_sep};
  83.  
  84. # Add to @dl_library_path any extra directories we can gather from environment
  85. # during runtime.
  86.  
  87. if ($ldlibpthname_defined &&
  88.     exists $ENV{$ldlibpthname}) {
  89.     push(@dl_library_path, split(/$pthsep/, $ENV{$ldlibpthname}));
  90. }
  91.  
  92. # E.g. HP-UX supports both its native SHLIB_PATH *and* LD_LIBRARY_PATH.
  93.  
  94. if ($ldlibpthname_defined &&
  95.     $ldlibpthname ne 'LD_LIBRARY_PATH' &&
  96.     exists $ENV{LD_LIBRARY_PATH}) {
  97.     push(@dl_library_path, split(/$pthsep/, $ENV{LD_LIBRARY_PATH}));
  98. }
  99.  
  100. # No prizes for guessing why we don't say 'bootstrap DynaLoader;' here.
  101. # NOTE: All dl_*.xs (including dl_none.xs) define a dl_error() XSUB
  102. boot_DynaLoader('DynaLoader') if defined(&boot_DynaLoader) &&
  103.                                 !defined(&dl_error);
  104.  
  105. if ($dl_debug) {
  106.     print STDERR "DynaLoader.pm loaded (@INC, @dl_library_path)\n";
  107.     print STDERR "DynaLoader not linked into this perl\n"
  108.         unless defined(&boot_DynaLoader);
  109. }
  110.  
  111. 1; # End of main code
  112.  
  113. sub croak   { require Carp; Carp::croak(@_)   }
  114.  
  115. sub bootstrap_inherit {
  116.     my $module = $_[0];
  117.     local *isa = *{"$module\::ISA"};
  118.     local @isa = (@isa, 'DynaLoader');
  119.     # Cannot goto due to delocalization.  Will report errors on a wrong line?
  120.     bootstrap(@_);
  121. }
  122.  
  123. # The bootstrap function cannot be autoloaded (without complications)
  124. # so we define it here:
  125.  
  126. sub bootstrap {
  127.     # use local vars to enable $module.bs script to edit values
  128.     local(@args) = @_;
  129.     local($module) = $args[0];
  130.     local(@dirs, $file);
  131.  
  132.     unless ($module) {
  133.     require Carp;
  134.     Carp::confess("Usage: DynaLoader::bootstrap(module)");
  135.     }
  136.  
  137.     # A common error on platforms which don't support dynamic loading.
  138.     # Since it's fatal and potentially confusing we give a detailed message.
  139.     croak("Can't load module $module, dynamic loading not available in this perl.\n".
  140.     "  (You may need to build a new perl executable which either supports\n".
  141.     "  dynamic loading or has the $module module statically linked into it.)\n")
  142.     unless defined(&dl_load_file);
  143.  
  144.     my @modparts = split(/::/,$module);
  145.     my $modfname = $modparts[-1];
  146.  
  147.     # Some systems have restrictions on files names for DLL's etc.
  148.     # mod2fname returns appropriate file base name (typically truncated)
  149.     # It may also edit @modparts if required.
  150.     $modfname = &mod2fname(\@modparts) if defined &mod2fname;
  151.  
  152.     # Truncate the module name to 8.3 format for NetWare
  153.     if (($^O eq 'NetWare') && (length($modfname) > 8)) {
  154.         $modfname = substr($modfname, 0, 8);
  155.     }
  156.  
  157.     my $modpname = join(($Is_MacOS ? ':' : '/'),@modparts);
  158.  
  159.     print STDERR "DynaLoader::bootstrap for $module ",
  160.         ($Is_MacOS
  161.                ? "(:auto:$modpname:$modfname.$dl_dlext)\n" :
  162.                "(auto/$modpname/$modfname.$dl_dlext)\n")
  163.     if $dl_debug;
  164.  
  165.     foreach (@INC) {
  166.     chop($_ = VMS::Filespec::unixpath($_)) if $Is_VMS;
  167.     my $dir;
  168.     if ($Is_MacOS) {
  169.         my $path = $_;
  170.         if ($Mac_FS && ! -d $path) {
  171.         $path = Mac::FileSpec::Unixish::nativize($path);
  172.         }
  173.         $path .= ":"  unless /:$/;
  174.         $dir = "${path}auto:$modpname";
  175.     } else {
  176.         $dir = "$_/auto/$modpname";
  177.     }
  178.     
  179.     next unless -d $dir; # skip over uninteresting directories
  180.     
  181.     # check for common cases to avoid autoload of dl_findfile
  182.     my $try = $Is_MacOS ? "$dir:$modfname.$dl_dlext" : "$dir/$modfname.$dl_dlext";
  183.     last if $file = ($do_expand) ? dl_expandspec($try) : ((-f $try) && $try);
  184.     
  185.     # no luck here, save dir for possible later dl_findfile search
  186.     push @dirs, $dir;
  187.     }
  188.     # last resort, let dl_findfile have a go in all known locations
  189.     $file = dl_findfile(map("-L$_",@dirs,@INC), $modfname) unless $file;
  190.  
  191.     croak("Can't locate loadable object for module $module in \@INC (\@INC contains: @INC)")
  192.     unless $file;    # wording similar to error from 'require'
  193.  
  194.     $file = uc($file) if $Is_VMS && $Config::Config{d_vms_case_sensitive_symbols};
  195.     my $bootname = "boot_$module";
  196.     $bootname =~ s/\W/_/g;
  197.     @dl_require_symbols = ($bootname);
  198.  
  199.     # Execute optional '.bootstrap' perl script for this module.
  200.     # The .bs file can be used to configure @dl_resolve_using etc to
  201.     # match the needs of the individual module on this architecture.
  202.     my $bs = $file;
  203.     $bs =~ s/(\.\w+)?(;\d*)?$/\.bs/; # look for .bs 'beside' the library
  204.     if (-s $bs) { # only read file if it's not empty
  205.         print STDERR "BS: $bs ($^O, $dlsrc)\n" if $dl_debug;
  206.         eval { do $bs; };
  207.         warn "$bs: $@\n" if $@;
  208.     }
  209.  
  210.     my $boot_symbol_ref;
  211.  
  212.     if ($^O eq 'darwin') {
  213.         if ($boot_symbol_ref = dl_find_symbol(0, $bootname)) {
  214.             goto boot; #extension library has already been loaded, e.g. darwin
  215.         }
  216.     }
  217.  
  218.     # Many dynamic extension loading problems will appear to come from
  219.     # this section of code: XYZ failed at line 123 of DynaLoader.pm.
  220.     # Often these errors are actually occurring in the initialisation
  221.     # C code of the extension XS file. Perl reports the error as being
  222.     # in this perl code simply because this was the last perl code
  223.     # it executed.
  224.  
  225.     my $libref = dl_load_file($file, $module->dl_load_flags) or
  226.     croak("Can't load '$file' for module $module: ".dl_error());
  227.  
  228.     push(@dl_librefs,$libref);  # record loaded object
  229.  
  230.     my @unresolved = dl_undef_symbols();
  231.     if (@unresolved) {
  232.     require Carp;
  233.     Carp::carp("Undefined symbols present after loading $file: @unresolved\n");
  234.     }
  235.  
  236.     $boot_symbol_ref = dl_find_symbol($libref, $bootname) or
  237.          croak("Can't find '$bootname' symbol in $file\n");
  238.  
  239.     push(@dl_modules, $module); # record loaded module
  240.  
  241.   boot:
  242.     my $xs = dl_install_xsub("${module}::bootstrap", $boot_symbol_ref, $file);
  243.  
  244.     # See comment block above
  245.     &$xs(@args);
  246. }
  247.  
  248. #sub _check_file {   # private utility to handle dl_expandspec vs -f tests
  249. #    my($file) = @_;
  250. #    return $file if (!$do_expand && -f $file); # the common case
  251. #    return $file if ( $do_expand && ($file=dl_expandspec($file)));
  252. #    return undef;
  253. #}
  254.  
  255. # Let autosplit and the autoloader deal with these functions:
  256.