Re: [PATCH B::Deparse] fix string uninterpretation
[p5sagit/p5-mst-13.2.git] / ext / B / O.pm
index 338d803..89352fb 100644 (file)
@@ -3,7 +3,16 @@ use B qw(minus_c save_BEGINs);
 use Carp;    
 
 sub import {
-    my ($class, $backend, @options) = @_;
+    my ($class, @options) = @_;
+    my $quiet = 0;
+    if ($options[0] eq '-q') {
+       $quiet = 1;
+       shift @options;
+       open (SAVEOUT, ">&STDOUT");
+       close STDOUT;
+       open (STDOUT, ">", \$O::BEGIN_output);
+    }
+    my $backend = shift (@options);
     eval q[
        BEGIN {
            minus_c;
@@ -11,6 +20,11 @@ sub import {
        }
 
        CHECK {
+           if ($quiet) {
+               close STDOUT;
+               open (STDOUT, ">&SAVEOUT");
+               close SAVEOUT;
+           }
            use B::].$backend.q[ ();
            if ($@) {
                croak "use of backend $backend failed: $@";
@@ -38,12 +52,21 @@ O - Generic interface to Perl Compiler backends
 
 =head1 SYNOPSIS
 
-       perl -MO=Backend[,OPTIONS] foo.pl
+       perl -MO=[-q,]Backend[,OPTIONS] foo.pl
 
 =head1 DESCRIPTION
 
 This is the module that is used as a frontend to the Perl Compiler.
 
+If you pass the C<-q> option to the module, then the STDOUT
+filehandle will be redirected into the variable C<$O::BEGIN_output>
+during compilation.  This has the effect that any output printed
+to STDOUT by BEGIN blocks or use'd modules will be stored in this
+variable rather than printed. It's useful with those backends which
+produce output themselves (C<Deparse>, C<Concise> etc), so that
+their output is not confused with that generated by the code
+being compiled.
+
 =head1 CONVENTIONS
 
 Most compiler backends use the following conventions: OPTIONS