From: Rafael Kitover Date: Tue, 8 Nov 2011 15:43:48 +0000 (-0500) Subject: use temp file instead of IPC::Open2 for Win32 X-Git-Tag: 0.07012~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=310f3603f4dee670ce5b733c862c62c35d96cd3c;p=dbsrgits%2FDBIx-Class-Schema-Loader.git use temp file instead of IPC::Open2 for Win32 Change implementation of filter_generated_code with a string for program name from IPC::Open2 to File::Temp with redirection, because this code was hanging on Win32 (RT#72226). --- diff --git a/Changes b/Changes index 343657a..4fb5c90 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - use a temp file for filter_generated_code with a string program name + instead of IPC::Open2, which hangs on Win32 (RT#72226) - previous version referred to the wrong RT# for the uniq_to_primary change, it is actually (RT#51696) diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 0ea7f0b..09bd617 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -25,8 +25,7 @@ use Try::Tiny; use DBIx::Class (); use Encode qw/encode decode/; use List::MoreUtils qw/all firstidx/; -use IPC::Open2; -use Symbol 'gensym'; +use File::Temp 'tempfile'; use namespace::clean; our $VERSION = '0.07011'; @@ -1854,23 +1853,26 @@ sub _write_classfile { ); } else { - my ($out, $in) = (gensym, gensym); + my ($fh, $temp_file) = tempfile(); - my $pid = open2($out, $in, $filter) - or croak "Could not open pipe to $filter: $!"; - - print $in $text; + binmode $fh, ':encoding(UTF-8)'; + print $fh $text; + close $fh; - close $in; + open my $out, qq{$filter < "$temp_file"|} + or croak "Could not open pipe to $filter: $!"; $text = decode('UTF-8', do { local $/; <$out> }); $text =~ s/$CR?$LF/\n/g; - waitpid $pid, 0; + close $out; my $exit_code = $? >> 8; + unlink $temp_file + or croak "Could not remove temporary file '$temp_file': $!"; + if ($exit_code != 0) { croak "filter '$filter' exited non-zero: $exit_code"; }