summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlya Zakharevich <ilya@math.berkeley.edu>2001-12-31 13:16:08 -0500
committerAbhijit Menon-Sen <ams@wiw.org>2002-01-01 04:44:28 +0000
commit0e57b4e8a1ce68a98d334e524872cae16942643b (patch)
treed00f607f14b8c1e04c134420b1a7ae66f5abb594
parent9de3b7c3f04d243540e2a381092bf0f918b7fe9e (diff)
downloadperl-0e57b4e8a1ce68a98d334e524872cae16942643b.tar.gz
Leaner exporter
Message-Id: <20011231181608.A29253@math.ohio-state.edu> p4raw-id: //depot/perl@13996
-rwxr-xr-xext/B/t/stash.t2
-rw-r--r--lib/Exporter.pm48
-rw-r--r--lib/Exporter/Heavy.pm11
3 files changed, 37 insertions, 24 deletions
diff --git a/ext/B/t/stash.t b/ext/B/t/stash.t
index e0ac3e9ff9..0a32a18841 100755
--- a/ext/B/t/stash.t
+++ b/ext/B/t/stash.t
@@ -38,7 +38,7 @@ $a =~ s/-uNetWare,// if $^O eq 'NetWare';
$a =~ s/-u(Cwd|File|File::Copy|OS2),//g if $^O eq 'os2';
$a =~ s/-uCwd,// if $^O eq 'cygwin';
$b = '-uCarp,-uCarp::Heavy,-uDB,-uExporter,-uExporter::Heavy,-uaccess,-uattributes,'
- . '-umain,-ustrict,-uutf8,-uwarnings';
+ . '-umain,-uutf8,-uwarnings';
if ($Is_VMS) {
$a =~ s/-uFile,-uFile::Copy,//;
$a =~ s/-uVMS,-uVMS::Filespec,//;
diff --git a/lib/Exporter.pm b/lib/Exporter.pm
index 00010892fa..61dcd0c2ab 100644
--- a/lib/Exporter.pm
+++ b/lib/Exporter.pm
@@ -2,33 +2,27 @@ package Exporter;
require 5.006;
-use strict;
-no strict 'refs';
+# Be lean.
+#use strict;
+#no strict 'refs';
our $Debug = 0;
our $ExportLevel = 0;
our $Verbose ||= 0;
-our $VERSION = '5.565';
+our $VERSION = '5.566';
$Carp::Internal{Exporter} = 1;
-sub export_to_level {
+sub as_heavy {
require Exporter::Heavy;
- goto &Exporter::Heavy::heavy_export_to_level;
+ # Unfortunately, this does not work if the caller is aliased as *name = \&foo
+ # Thus the need to create a lot of identical subroutines
+ my $c = (caller(1))[3];
+ $c =~ s/.*:://;
+ \&{"Exporter::Heavy::heavy_$c"};
}
sub export {
- require Exporter::Heavy;
- goto &Exporter::Heavy::heavy_export;
-}
-
-sub export_tags {
- require Exporter::Heavy;
- Exporter::Heavy::_push_tags((caller)[0], "EXPORT", \@_);
-}
-
-sub export_ok_tags {
- require Exporter::Heavy;
- Exporter::Heavy::_push_tags((caller)[0], "EXPORT_OK", \@_);
+ goto &{as_heavy()};
}
sub import {
@@ -65,7 +59,6 @@ sub import {
*{"$callpkg\::$_"} = \&{"$pkg\::$_"} foreach @_;
}
-
# Default methods
sub export_fail {
@@ -73,12 +66,25 @@ sub export_fail {
@_;
}
+# Unfortunately, caller(1)[3] "does not work" if the caller is aliased as
+# *name = \&foo. Thus the need to create a lot of identical subroutines
+# Otherwise we could have aliased them to export().
-sub require_version {
- require Exporter::Heavy;
- goto &Exporter::Heavy::require_version;
+sub export_to_level {
+ goto &{as_heavy()};
+}
+
+sub export_tags {
+ goto &{as_heavy()};
}
+sub export_ok_tags {
+ goto &{as_heavy()};
+}
+
+sub require_version {
+ goto &{as_heavy()};
+}
1;
__END__
diff --git a/lib/Exporter/Heavy.pm b/lib/Exporter/Heavy.pm
index d1c4a10e51..3bdc4b4f20 100644
--- a/lib/Exporter/Heavy.pm
+++ b/lib/Exporter/Heavy.pm
@@ -215,11 +215,18 @@ sub _push_tags {
}
}
-
-sub require_version {
+sub heavy_require_version {
my($self, $wanted) = @_;
my $pkg = ref $self || $self;
return ${pkg}->VERSION($wanted);
}
+sub heavy_export_tags {
+ _push_tags((caller)[0], "EXPORT", \@_);
+}
+
+sub heavy_export_ok_tags {
+ _push_tags((caller)[0], "EXPORT_OK", \@_);
+}
+
1;