home *** CD-ROM | disk | FTP | other *** search
/ Freelog 112 / FreelogNo112-NovembreDecembre2012.iso / Graphisme / XnViewMP / XnViewMP.exe / lib / AutoLoader.pm < prev    next >
Text File  |  2011-08-27  |  5KB  |  185 lines

  1. #line 1 "AutoLoader.pm"
  2. package AutoLoader;
  3.  
  4. use strict;
  5. use 5.006_001;
  6.  
  7. our($VERSION, $AUTOLOAD);
  8.  
  9. my $is_dosish;
  10. my $is_epoc;
  11. my $is_vms;
  12. my $is_macos;
  13.  
  14. BEGIN {
  15.     $is_dosish = $^O eq 'dos' || $^O eq 'os2' || $^O eq 'MSWin32' || $^O eq 'NetWare';
  16.     $is_epoc = $^O eq 'epoc';
  17.     $is_vms = $^O eq 'VMS';
  18.     $is_macos = $^O eq 'MacOS';
  19.     $VERSION = '5.60';
  20. }
  21.  
  22. AUTOLOAD {
  23.     my $sub = $AUTOLOAD;
  24.     my $filename;
  25.     # Braces used to preserve $1 et al.
  26.     {
  27.     # Try to find the autoloaded file from the package-qualified
  28.     # name of the sub. e.g., if the sub needed is
  29.     # Getopt::Long::GetOptions(), then $INC{Getopt/Long.pm} is
  30.     # something like '/usr/lib/perl5/Getopt/Long.pm', and the
  31.     # autoload file is '/usr/lib/perl5/auto/Getopt/Long/GetOptions.al'.
  32.     #
  33.     # However, if @INC is a relative path, this might not work.  If,
  34.     # for example, @INC = ('lib'), then $INC{Getopt/Long.pm} is
  35.     # 'lib/Getopt/Long.pm', and we want to require
  36.     # 'auto/Getopt/Long/GetOptions.al' (without the leading 'lib').
  37.     # In this case, we simple prepend the 'auto/' and let the
  38.     # C<require> take care of the searching for us.
  39.  
  40.     my ($pkg,$func) = ($sub =~ /(.*)::([^:]+)$/);
  41.     $pkg =~ s#::#/#g;
  42.     if (defined($filename = $INC{"$pkg.pm"})) {
  43.         if ($is_macos) {
  44.         $pkg =~ tr#/#:#;
  45.         $filename =~ s#^(.*)$pkg\.pm\z#$1auto:$pkg:$func.al#s;
  46.         } else {
  47.         $filename =~ s#^(.*)$pkg\.pm\z#$1auto/$pkg/$func.al#s;
  48.         }
  49.  
  50.         # if the file exists, then make sure that it is a
  51.         # a fully anchored path (i.e either '/usr/lib/auto/foo/bar.al',
  52.         # or './lib/auto/foo/bar.al'.  This avoids C<require> searching
  53.         # (and failing) to find the 'lib/auto/foo/bar.al' because it
  54.         # looked for 'lib/lib/auto/foo/bar.al', given @INC = ('lib').
  55.  
  56.         if (-r $filename) {
  57.         unless ($filename =~ m|^/|s) {
  58.             if ($is_dosish) {
  59.             unless ($filename =~ m{^([a-z]:)?[\\/]}is) {
  60.                  if ($^O ne 'NetWare') {
  61.                     $filename = "./$filename";
  62.                 } else {
  63.                     $filename = "$filename";
  64.                 }
  65.             }
  66.             }
  67.             elsif ($is_epoc) {
  68.             unless ($filename =~ m{^([a-z?]:)?[\\/]}is) {
  69.                  $filename = "./$filename";
  70.             }
  71.             }
  72.             elsif ($is_vms) {
  73.             # XXX todo by VMSmiths
  74.             $filename = "./$filename";
  75.             }
  76.             elsif (!$is_macos) {
  77.             $filename = "./$filename";
  78.             }
  79.         }
  80.         }
  81.         else {
  82.         $filename = undef;
  83.         }
  84.     }
  85.     unless (defined $filename) {
  86.         # let C<require> do the searching
  87.         $filename = "auto/$sub.al";
  88.         $filename =~ s#::#/#g;
  89.     }
  90.     }
  91.     my $save = $@;
  92.     local $!; # Do not munge the value. 
  93.     eval { local $SIG{__DIE__}; require $filename };
  94.     if ($@) {
  95.     if (substr($sub,-9) eq '::DESTROY') {
  96.         no strict 'refs';
  97.         *$sub = sub {};
  98.         $@ = undef;
  99.     } elsif ($@ =~ /^Can't locate/) {
  100.         # The load might just have failed because the filename was too
  101.         # long for some old SVR3 systems which treat long names as errors.
  102.         # If we can successfully truncate a long name then it's worth a go.
  103.         # There is a slight risk that we could pick up the wrong file here
  104.         # but autosplit should have warned about that when splitting.
  105.         if ($filename =~ s/(\w{12,})\.al$/substr($1,0,11).".al"/e){
  106.         eval { local $SIG{__DIE__}; require $filename };
  107.         }
  108.     }
  109.     if ($@){
  110.         $@ =~ s/ at .*\n//;
  111.         my $error = $@;
  112.         require Carp;
  113.         Carp::croak($error);
  114.     }
  115.     }
  116.     $@ = $save;
  117.     goto &$sub;
  118. }
  119.  
  120. sub import {
  121.     my $pkg = shift;
  122.     my $callpkg = caller;
  123.  
  124.     #
  125.     # Export symbols, but not by accident of inheritance.
  126.     #
  127.  
  128.     if ($pkg eq 'AutoLoader') {
  129.     no strict 'refs';
  130.     *{ $callpkg . '::AUTOLOAD' } = \&AUTOLOAD
  131.         if @_ and $_[0] =~ /^&?AUTOLOAD$/;
  132.     }
  133.  
  134.     #
  135.     # Try to find the autosplit index file.  Eg., if the call package
  136.     # is POSIX, then $INC{POSIX.pm} is something like
  137.     # '/usr/local/lib/perl5/POSIX.pm', and the autosplit index file is in
  138.     # '/usr/local/lib/perl5/auto/POSIX/autosplit.ix', so we require that.
  139.     #
  140.     # However, if @INC is a relative path, this might not work.  If,
  141.     # for example, @INC = ('lib'), then
  142.     # $INC{POSIX.pm} is 'lib/POSIX.pm', and we want to require
  143.     # 'auto/POSIX/autosplit.ix' (without the leading 'lib').
  144.     #
  145.  
  146.     (my $calldir = $callpkg) =~ s#::#/#g;
  147.     my $path = $INC{$calldir . '.pm'};
  148.     if (defined($path)) {
  149.     # Try absolute path name.
  150.     if ($is_macos) {
  151.         (my $malldir = $calldir) =~ tr#/#:#;
  152.         $path =~ s#^(.*)$malldir\.pm\z#$1auto:$malldir:autosplit.ix#s;
  153.     } else {
  154.         $path =~ s#^(.*)$calldir\.pm\z#$1auto/$calldir/autosplit.ix#;
  155.     }
  156.  
  157.     eval { require $path; };
  158.     # If that failed, try relative path with normal @INC searching.
  159.     if ($@) {
  160.         $path ="auto/$calldir/autosplit.ix";
  161.         eval { require $path; };
  162.     }
  163.     if ($@) {
  164.         my $error = $@;
  165.         require Carp;
  166.         Carp::carp($error);
  167.     }
  168.     } 
  169. }
  170.  
  171. sub unimport {
  172.     my $callpkg = caller;
  173.  
  174.     no strict 'refs';
  175.     my $symname = $callpkg . '::AUTOLOAD';
  176.     undef *{ $symname } if \&{ $symname } == \&AUTOLOAD;
  177.     *{ $symname } = \&{ $symname };
  178. }
  179.  
  180. 1;
  181.  
  182. __END__
  183.  
  184. #line 344
  185.