This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
This is my patch patch.1i for perl5.001.
[perl5.git] / lib / AutoLoader.pm
CommitLineData
8990e307 1package AutoLoader;
a0d0e21e 2use Carp;
8990e307 3
f06db76b
AD
4=head1 NAME
5
6AutoLoader - load functions only on demand
7
8=head1 SYNOPSIS
9
10 package FOOBAR;
11 use Exporter;
12 use AutoLoader;
13 @ISA = (Exporter, AutoLoader);
14
15=head1 DESCRIPTION
16
17This module tells its users that functions in the FOOBAR package are to be
18autoloaded from F<auto/$AUTOLOAD.al>. See L<perlsub/"Autoloading">.
19
20=cut
21
8990e307
LW
22AUTOLOAD {
23 my $name = "auto/$AUTOLOAD.al";
24 $name =~ s#::#/#g;
25 eval {require $name};
26 if ($@) {
a0d0e21e
LW
27 # The load might just have failed because the filename was too
28 # long for some old SVR3 systems which treat long names as errors.
29 # If we can succesfully truncate a long name then it's worth a go.
30 # There is a slight risk that we could pick up the wrong file here
31 # but autosplit should have warned about that when splitting.
32 if ($name =~ s/(\w{12,})\.al$/substr($1,0,11).".al"/e){
33 eval {require $name};
34 }
748a9306
LW
35 elsif ($AUTOLOAD =~ /::DESTROY$/) {
36 eval "sub $AUTOLOAD {}";
37 }
a0d0e21e
LW
38 if ($@){
39 $@ =~ s/ at .*\n//;
40 croak $@;
41 }
8990e307
LW
42 }
43 goto &$AUTOLOAD;
44}
f06db76b
AD
45
46sub import
47{
48 my ($callclass, $callfile, $callline,$path,$callpack) = caller(0);
49 ($callpack = $callclass) =~ s#::#/#;
50 if (defined($path = $INC{$callpack . '.pm'}))
51 {
52 if ($path =~ s#^(.*)$callpack\.pm$#$1auto/$callpack/autosplit.ix# && -e $path)
53 {
54 eval {require $path};
55 carp $@ if ($@);
56 }
57 else
58 {
59 croak "Have not loaded $callpack.pm";
60 }
61 }
62}
8990e307
LW
63
641;