develooper Front page | perl.perl5.porters | Postings from December 2015

Re: Proposal: Add {-as => 'new_name'} feature to Exporter.pm

Thread Previous | Thread Next
From:
Chad Granum
Date:
December 17, 2015 23:14
Subject:
Re: Proposal: Add {-as => 'new_name'} feature to Exporter.pm
Message ID:
CAJFr3kuB5CFmx6a14q7zj3r2-apV_m8eZ-dmSHunBDnkSADfqw@mail.gmail.com
From 9984a1ac3b522a563b8567d9ce361753018199fe Mon Sep 17 00:00:00 2001
From: Chad Granum <exodist7@gmail.com>
Date: Thu, 17 Dec 2015 14:53:13 -0800
Subject: [PATCH] fix

---
 lib/Exporter/Heavy.pm | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/Exporter/Heavy.pm b/lib/Exporter/Heavy.pm
index 21b67c1..98d3743 100755
--- a/lib/Exporter/Heavy.pm
+++ b/lib/Exporter/Heavy.pm
@@ -145,7 +145,7 @@ sub heavy_export {
 			$cache_is_current = 1;
 		    }
 
-		    if (!$export_cache->{$sym}) {
+		    if (!$export_cache->{$sym} && ref($sym) ne 'HASH') {
 			# accumulate the non-exports
 			push @carp,
 			  qq["$sym" is not exported by the $pkg module\n];
@@ -194,13 +194,15 @@ sub heavy_export {
     warn "Importing into $callpkg from $pkg: ",
 		join(", ",sort @imports) if $Exporter::Verbose;
 
-    foreach $sym (@imports) {
+    while (my $sym  = shift @imports) {
+        my $spec = (@imports && ref($imports[0]) eq 'HASH') ? shift @imports : undef;
+        my $name = ($spec && $spec->{'-as'}) ? $spec->{'-as'} : $sym;
 	# shortcut for the common case of no type character
-	(*{"${callpkg}::$sym"} = \&{"${pkg}::$sym"}, next)
+	(*{"${callpkg}::$name"} = \&{"${pkg}::$sym"}, next)
 	    unless $sym =~ s/^(\W)//;
 	$type = $1;
 	no warnings 'once';
-	*{"${callpkg}::$sym"} =
+	*{"${callpkg}::$name"} =
 	    $type eq '&' ? \&{"${pkg}::$sym"} :
 	    $type eq '$' ? \${"${pkg}::$sym"} :
 	    $type eq '@' ? \@{"${pkg}::$sym"} :
-- 
1.9.1


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About