-
Notifications
You must be signed in to change notification settings - Fork 4
/
al.patch
131 lines (116 loc) · 5.05 KB
/
al.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
--- AutoLoader.pm.orig Wed Aug 13 01:11:29 1997
+++ AutoLoader.pm Fri Aug 22 00:21:52 1997
@@ -1,7 +1,7 @@
package AutoLoader;
use Carp;
-use vars qw(@EXPORT @EXPORT_OK);
+use vars qw(@EXPORT @EXPORT_OK $Verbose $Notruncate);
BEGIN {
require Exporter;
@@ -9,6 +9,9 @@
@EXPORT_OK = qw(AUTOLOAD);
}
+$Verbose = 0 unless $Verbose;
+$Notruncate = 0 unless $Notruncate;
+
AUTOLOAD {
my $name;
# Braces used to preserve $1 et al.
@@ -31,15 +34,18 @@
if ($@) {
if (substr($AUTOLOAD,-9) eq '::DESTROY') {
*$AUTOLOAD = sub {};
- } else {
+ }
+ else {
# The load might just have failed because the filename was too
# long for some old SVR3 systems which treat long names as errors.
# If we can succesfully truncate a long name then it's worth a go.
# There is a slight risk that we could pick up the wrong file here
# but autosplit should have warned about that when splitting.
- if ($name =~ s/(\w{12,})\.al$/substr($1,0,11).".al"/e){
- eval {local $SIG{__DIE__};require $name};
- }
+ if (!$Notruncate &&
+ $name =~ s/(\w{12,})\.al$/substr($1,0,11).".al"/e)
+ {
+ eval {local $SIG{__DIE__};require $name};
+ }
if ($@){
$@ =~ s/ at .*\n//;
croak $@;
@@ -47,6 +53,7 @@
}
}
$@ = $save;
+ carp "AutoLoaded $AUTOLOAD" if $Verbose;
goto &$AUTOLOAD;
}
@@ -134,6 +141,18 @@
Once this process completes for a given funtion, it is defined, so
future calls to the subroutine will bypass the AUTOLOAD mechanism.
+You can say C<BEGIN { $AutoLoader::Verbose=1 }> to see which routines are
+being autoloaded from which points in your code.
+
+Normally if B<AutoLoader> fails to successfully read and evaluate the
+C<.al> file corresponding to a subroutine, another attempt will be made
+with the filename shortened to 14 characters. If this attempt fails, an
+exception is raised. While this allows B<AutoLoader> to function on
+machines without long filename support, it causes some difficulties because
+the filename returned in the exception is the truncated one. To avoid
+this, the truncation behavior can be turned off by saying C<BEGIN {
+$AutoLoader::Notruncate=1 }>.
+
=head2 Subroutine Stubs
In order for object method lookup and/or prototype checking to operate
@@ -142,10 +161,10 @@
L<perlsub/"SYNOPSIS">. Such forward declaration creates "subroutine
stubs", which are place holders with no code.
-The AutoSplit and B<AutoLoader> modules automate the creation of forward
-declarations. The AutoSplit module creates an 'index' file containing
-forward declarations of all the AutoSplit subroutines. When the
-AutoLoader module is 'use'd it loads these declarations into its callers
+The B<AutoSplit> and B<AutoLoader> modules automate the creation of forward
+declarations. The B<AutoSplit> module creates an 'index' file containing
+forward declarations of all the B<AutoSplit> subroutines. When the
+AutoLoaded module is 'use'd it loads these declarations into its callers
package.
Because of this mechanism it is important that B<AutoLoader> is always
@@ -188,7 +207,7 @@
}
If any module's own AUTOLOAD subroutine has no need to fallback to the
-AutoLoader's AUTOLOAD subroutine (because it doesn't have any AutoSplit
+AutoLoader's AUTOLOAD subroutine (because it doesn't have any B<AutoSplit>
subroutines), then that module should not use B<AutoLoader> at all.
=head2 Package Lexicals
@@ -205,6 +224,18 @@
visible to any autoloaded routines (but will not be invisible outside
the package, unfortunately).
+=head2 B<AutoLoader> and C<use>d modules
+
+Because B<AutoLoader> simply C<require>s the appropriate C<.al> file to
+complete a call to an autoloaded subroutine, it can also be used to delay
+the loading of the modules that are called by said subroutine. If modules
+are C<use>d before the C<__END__> tag, they will be loaded when the package
+is C<use>d, but if the modules are C<use>d directly before the definition
+of a subroutines that calls them, their loading will be delayed until that
+subroutine is called. (This works because B<AutoSplit> will place the
+C<use> of the module in the C<.al> file for the subroutine. Thus the
+C<use> will not happen until the subroutine is autoloaded.)
+
=head2 B<AutoLoader> vs. B<SelfLoader>
The B<AutoLoader> is similar in purpose to B<SelfLoader>: both delay the
@@ -233,8 +264,15 @@
On systems with restrictions on file name length, the file corresponding
to a subroutine may have a shorter name that the routine itself. This
-can lead to conflicting file names. The I<AutoSplit> package warns of
+can lead to conflicting file names. The B<AutoSplit> package warns of
these potential conflicts when used to split a module.
+
+The setting of C<AutoLoader::Notruncate> is not intended as an alternative
+to removing the C<__END__> tag and the inclusion of the AutoLoader module.
+The former only gives you the correct name of the failed file in the case
+of a parsing error, while the latter is the only way to completely check
+for syntax errors since autoloading also delays syntax checking until
+runtime.
=head1 SEE ALSO