[Bps-public-commit] r9287 - IPC-Run-SafeHandles/lib/IPC/Run

clkao at bestpractical.com clkao at bestpractical.com
Fri Oct 12 13:21:17 EDT 2007


Author: clkao
Date: Fri Oct 12 13:21:16 2007
New Revision: 9287

Modified:
   IPC-Run-SafeHandles/lib/IPC/Run/SafeHandles.pm

Log:
* need to override the symbol of the caller as well.
  (maybe just those?)
* goto doesn't keep locals. use function call instead.


Modified: IPC-Run-SafeHandles/lib/IPC/Run/SafeHandles.pm
==============================================================================
--- IPC-Run-SafeHandles/lib/IPC/Run/SafeHandles.pm	(original)
+++ IPC-Run-SafeHandles/lib/IPC/Run/SafeHandles.pm	Fri Oct 12 13:21:16 2007
@@ -33,24 +33,17 @@
 
 my $wrapper_context = [];
 
-sub import {
-    _wrap_it('IPC::Run::run')   if $INC{'IPC/Run.pm'};
-    _wrap_it('IPC::Run3::run3') if $INC{'IPC/Run3.pm'};
-
-    unless (@$wrapper_context) {
-	Carp::carp "Use of IPC::Run::SafeHandles wihtout using IPC::Run or IPC::Run3 first";
-    }
-}
-
 sub _wrap_it {
     no strict 'refs';
     my $typeglob = shift;
+    my $caller = shift;
+
     my $original = *$typeglob{CODE};
     my $unwrap = 0;
 
     my $wrapper = sub {
 
-	goto &$original unless $ENV{FCGI_ROLE};
+        goto &$original unless $ENV{FCGI_ROLE};
 
 	my $stdout = IO::Handle->new;
 	$stdout->fdopen( 1, 'w' );
@@ -59,15 +52,28 @@
 	my $stderr = IO::Handle->new;
 	$stderr->fdopen( 2, 'w' );
 	local *STDERR = $stderr;
-	goto &$original;
+	$original->(@_);
     };
     no warnings 'redefine';
+    my $callerglob = $typeglob; $callerglob =~ s/IPC::Run3?/$caller/;
     *{$typeglob} = $wrapper;
+    *{$callerglob} = $wrapper;
     push @$wrapper_context,
 	bless(sub { no warnings 'redefine';
+                    *{$callerglob} = $original;
 		    *{$typeglob} = $original }, __PACKAGE__);
 }
 
+sub import {
+    my $caller = caller();
+    _wrap_it('IPC::Run::run', $caller)   if $INC{'IPC/Run.pm'};
+    _wrap_it('IPC::Run3::run3', $caller) if $INC{'IPC/Run3.pm'};
+
+    unless (@$wrapper_context) {
+	Carp::carp "Use of IPC::Run::SafeHandles wihtout using IPC::Run or IPC::Run3 first";
+    }
+}
+
 =head2 unimport
 
 When unimport, the original L<IPC::Run> and/or L<IPC::Run3> functions



More information about the Bps-public-commit mailing list