Re: [abigail@foad.org: [ID 20000901.065] -MO=Deparse and $^W and $[ in same string.]
[p5sagit/p5-mst-13.2.git] / ext / B / O.pm
index d07c4a5..338d803 100644 (file)
@@ -1,20 +1,31 @@
 package O;
-use B qw(minus_c);
+use B qw(minus_c save_BEGINs);
 use Carp;    
 
 sub import {
     my ($class, $backend, @options) = @_;
-    eval "use B::$backend ()";
-    if ($@) {
-       croak "use of backend $backend failed: $@";
-    }
-    my $compilesub = &{"B::${backend}::compile"}(@options);
-    if (ref($compilesub) eq "CODE") {
-       minus_c;
-       eval 'STOP { &$compilesub() }';
-    } else {
-       die $compilesub;
-    }
+    eval q[
+       BEGIN {
+           minus_c;
+           save_BEGINs;
+       }
+
+       CHECK {
+           use B::].$backend.q[ ();
+           if ($@) {
+               croak "use of backend $backend failed: $@";
+           }
+
+
+           my $compilesub = &{"B::${backend}::compile"}(@options);
+           if (ref($compilesub) ne "CODE") {
+               die $compilesub;
+           }
+
+           &$compilesub();
+       }
+    ];
+    die $@ if $@;
 }
 
 1;
@@ -59,7 +70,7 @@ C<B::Backend> module and calls the C<compile> function in that
 package, passing it OPTIONS. That function is expected to return
 a sub reference which we'll call CALLBACK. Next, the "compile-only"
 flag is switched on (equivalent to the command-line option C<-c>)
-and a STOP block is registered which calls CALLBACK. Thus the main
+and a CHECK block is registered which calls CALLBACK. Thus the main
 Perl program mentioned on the command-line is read in, parsed and
 compiled into internal syntax tree form. Since the C<-c> flag is
 set, the program does not start running (excepting BEGIN blocks of