This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Generate @POSIX::EXPORT_OK from %reimpl, %replacement and an exception list.
authorNicholas Clark <nick@ccl4.org>
Thu, 1 Sep 2011 19:32:13 +0000 (21:32 +0200)
committerNicholas Clark <nick@ccl4.org>
Thu, 1 Sep 2011 19:54:14 +0000 (21:54 +0200)
This is considerably terser than listing all the entries for @EXPORT_OK
longhand. With this change we can no longer delete from %replacement in
AUTOLOAD(), as import() and load_imports() may be called after AUTOLOAD()
has already been run.

ext/POSIX/lib/POSIX.pm

index 94a706b..75785f8 100644 (file)
@@ -189,7 +189,7 @@ eval join ';', map "sub $_", keys %replacement, keys %reimpl;
 sub AUTOLOAD {
     my ($func) = ($AUTOLOAD =~ /.*::(.*)/);
 
-    if (my $code = delete $reimpl{$func}) {
+    if (my $code = $reimpl{$func}) {
        my ($num, $arg) = (0, '');
        if ($code =~ s/^(.*?) *=> *//) {
            $arg = $1;
@@ -390,65 +390,11 @@ our %EXPORT_TAGS = (
   # Doing the de-dup with a temporary hash has the advantage that the SVs in
   # @EXPORT are actually shared hash key scalars, which will save some memory.
   our @EXPORT = keys %export;
-}
 
-our @EXPORT_OK = qw(
-               abs
-               alarm
-               atan2
-               chdir
-               chmod
-               chown
-               close
-               closedir
-               cos
-               exit
-               exp
-               fcntl
-               fileno
-               fork
-               getc
-               getgrgid
-               getgrnam
-               getlogin
-               getpgrp
-               getppid
-               getpwnam
-               getpwuid
-               gmtime
-               kill
-               lchown
-               link
-               localtime
-               log
-               mkdir
-               nice
-               open
-               opendir
-               pipe
-               printf
-               rand
-               read
-               readdir
-               rename
-               rewinddir
-               rmdir
-               sin
-               sleep
-               sprintf
-               sqrt
-               srand
-               stat
-               system
-               time
-               times
-               umask
-               unlink
-               utime
-               wait
-               waitpid
-               write
-);
+  our @EXPORT_OK = (qw(close lchown nice open pipe read times write
+                      printf sprintf),
+                   grep {!exists $export{$_}} keys %reimpl, keys %replacement);
+}
 
 require Exporter;
 }