'AutoLoader' => {
'MAINTAINER' => 'smueller',
- 'DISTRIBUTION' => 'SMUELLER/AutoLoader-5.72.tar.gz',
+ 'DISTRIBUTION' => 'SMUELLER/AutoLoader-5.73.tar.gz',
'FILES' => q[cpan/AutoLoader],
'EXCLUDED' => ['t/00pod.t'],
'UPSTREAM' => 'cpan',
$is_epoc = $^O eq 'epoc';
$is_vms = $^O eq 'VMS';
$is_macos = $^O eq 'MacOS';
- $VERSION = '5.72';
+ $VERSION = '5.73';
}
AUTOLOAD {
my $sub = $AUTOLOAD;
+ autoload_sub($sub);
+ goto &$sub;
+}
+
+sub autoload_sub {
+ my $sub = shift;
+
my $filename = AutoLoader::find_filename( $sub );
my $save = $@;
}
}
$@ = $save;
- goto &$sub;
+
+ return 1;
}
sub find_filename {
B<AutoSplit> automatically if B<AutoLoader> is used in a module source
file.
+=head2 Forcing AutoLoader to Load a Function
+
+Sometimes, it can be necessary or useful to make sure that a certain
+function is fully loaded by AutoLoader. This is the case, for example,
+when you need to wrap a function to inject debugging code. It is also
+helpful to force early loading of code before forking to make use of
+copy-on-write as much as possible.
+
+Starting with AutoLoader 5.73, you can call the
+C<AutoLoader::autoload_sub> function with the fully-qualified name of
+the function to load from its F<.al> file. The behaviour is exactly
+the same as if you called the function, triggering the regular
+C<AUTOLOAD> mechanism, but it does not actually execute the
+autoloaded function.
+
=head1 CAVEATS
AutoLoaders prior to Perl 5.002 had a slightly different interface. Any
This package has the same copyright and license as the perl core:
Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011
+ 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
+ 2011, 2012
by Larry Wall and others
All rights reserved.
unshift @INC, $dir;
}
-use Test::More tests => 18;
+use Test::More tests => 21;
sub write_file {
my ($file, $text) = @_;
# to find the above file so we duplicate it where they should find it.
write_file( File::Spec->catfile( $fulldir, 'blechanawil.al' ), $blechanawilla_text );
+write_file( File::Spec->catfile( $fulldir, 'notreached.al' ), <<'EOT' );
+package Foo;
+sub notreached { die "Should not be reached!" }
+1;
+EOT
+
# Let's define the package
package Foo;
require AutoLoader;
sub new { bless {}, shift };
sub foo;
sub bazmarkhianish;
+sub notreached;
package main;
Foo::a();
+# Test whether autoload_sub works without actually executing the function
+ok(!defined(&Foo::notreached), "Foo::notreached unknown to boot");
+AutoLoader::autoload_sub("Foo::notreached");
+ok(defined(&Foo::notreached), "Foo::notreached loaded by autoload_sub");
+
+# Make sure that repeatedly calling autoload_sub is not a problem:
+AutoLoader::autoload_sub("Foo::notreached");
+eval {Foo::notreached;};
+ok($@ && $@ =~ /Should not/, "Foo::notreached works as expected");
+
package Bar;
AutoLoader->import();
::ok( ! defined &AUTOLOAD, 'AutoLoader should not export AUTOLOAD by default' );