summaryrefslogtreecommitdiff
path: root/cpan/AutoLoader
diff options
context:
space:
mode:
authorSteffen Mueller <smueller@cpan.org>2012-10-16 17:27:47 +0200
committerSteffen Mueller <smueller@cpan.org>2012-10-16 17:27:47 +0200
commit07e2e970a070734488a530ac34f1ae7b61e43a43 (patch)
treeae44c0f138886c85430b43316938acdf310f6354 /cpan/AutoLoader
parent4e375cef4c9fb6974eb23e2ace1fb9ef0f42ce3f (diff)
downloadperl-07e2e970a070734488a530ac34f1ae7b61e43a43.tar.gz
cpan: Upgrade AutoLoader to 5.73
Just syncing to CPAN release.
Diffstat (limited to 'cpan/AutoLoader')
-rw-r--r--cpan/AutoLoader/lib/AutoLoader.pm30
-rw-r--r--cpan/AutoLoader/t/01AutoLoader.t19
2 files changed, 45 insertions, 4 deletions
diff --git a/cpan/AutoLoader/lib/AutoLoader.pm b/cpan/AutoLoader/lib/AutoLoader.pm
index 8dab836ab3..955f852cbf 100644
--- a/cpan/AutoLoader/lib/AutoLoader.pm
+++ b/cpan/AutoLoader/lib/AutoLoader.pm
@@ -15,11 +15,18 @@ BEGIN {
$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 = $@;
@@ -48,7 +55,8 @@ AUTOLOAD {
}
}
$@ = $save;
- goto &$sub;
+
+ return 1;
}
sub find_filename {
@@ -335,6 +343,21 @@ create the individual files. L<ExtUtils::MakeMaker> will invoke
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
@@ -376,7 +399,8 @@ can benefit from bug fixes.
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.
diff --git a/cpan/AutoLoader/t/01AutoLoader.t b/cpan/AutoLoader/t/01AutoLoader.t
index dcee5c518a..aa52904d1f 100644
--- a/cpan/AutoLoader/t/01AutoLoader.t
+++ b/cpan/AutoLoader/t/01AutoLoader.t
@@ -18,7 +18,7 @@ BEGIN
unshift @INC, $dir;
}
-use Test::More tests => 18;
+use Test::More tests => 21;
sub write_file {
my ($file, $text) = @_;
@@ -53,6 +53,12 @@ write_file( File::Spec->catfile( $fulldir, 'blechanawilla.al' ), $blechanawilla_
# 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;
@@ -61,6 +67,7 @@ AutoLoader->import( 'AUTOLOAD' );
sub new { bless {}, shift };
sub foo;
sub bazmarkhianish;
+sub notreached;
package main;
@@ -118,6 +125,16 @@ EOT
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' );