This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix warnings (used once) for O.pm
[perl5.git] / ext / B / O.pm
index 94ee754..09a905e 100644 (file)
@@ -2,15 +2,17 @@ package O;
 
 our $VERSION = '1.02';
 
-use B qw(minus_c save_BEGINs);
-use Carp;
+use B ();
+
+our $BEGIN_output;
+our $saveout_fh;
 
 sub import {
     my ($class, @options) = @_;
     my ($quiet, $veryquiet) = (0, 0);
     if ($options[0] eq '-q' || $options[0] eq '-qq') {
        $quiet = 1;
-       open (SAVEOUT, ">&STDOUT");
+       open ($saveout_fh, ">&", STDOUT);
        close STDOUT;
        open (STDOUT, ">", \$O::BEGIN_output);
        if ($options[0] eq '-qq') {
@@ -21,15 +23,15 @@ sub import {
     my $backend = shift (@options);
     eval q[
        BEGIN {
-           minus_c;
-           save_BEGINs;
+           B::minus_c;
+           B::save_BEGINs;
        }
 
        CHECK {
            if ($quiet) {
                close STDOUT;
-               open (STDOUT, ">&SAVEOUT");
-               close SAVEOUT;
+               open (STDOUT, ">&", $saveout_fh);
+               close $saveout_fh;
            }
 
            # Note: if you change the code after this 'use', please
@@ -51,7 +53,9 @@ sub import {
        }
     ];
     if ($@) {
-        croak "Loading compiler backend 'B::$backend' failed: $@";
+        my $msg = "$@";
+        require Carp;
+        Carp::croak("Loading compiler backend 'B::$backend' failed: $msg");
     }
 }