diff options
author | Nicholas Clark <nick@ccl4.org> | 2013-07-08 16:41:30 +0200 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2013-07-09 07:54:32 +0200 |
commit | a06cd52b4e4376cb0c4375a8943888ed7c9f37d2 (patch) | |
tree | 9867713523d7bc2fa81360678ba48331cade76e4 /ext/ExtUtils-Miniperl | |
parent | c6c8952117b3f95f22ad700d84fdb39432aaa4dd (diff) | |
download | perl-a06cd52b4e4376cb0c4375a8943888ed7c9f37d2.tar.gz |
ExtUtils::Miniperl::writemain()'s first argument can also be a filename.
Treat a reference to a scalar as the name of a file to open for output.
Any other reference is used as an output filehandle.
Otherwise the default remains to write to STDOUT.
Diffstat (limited to 'ext/ExtUtils-Miniperl')
-rw-r--r-- | ext/ExtUtils-Miniperl/lib/ExtUtils/Miniperl.pm | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/ext/ExtUtils-Miniperl/lib/ExtUtils/Miniperl.pm b/ext/ExtUtils-Miniperl/lib/ExtUtils/Miniperl.pm index 68a494005d..9aaf9540c3 100644 --- a/ext/ExtUtils-Miniperl/lib/ExtUtils/Miniperl.pm +++ b/ext/ExtUtils-Miniperl/lib/ExtUtils/Miniperl.pm @@ -10,9 +10,24 @@ use vars qw($VERSION @ISA @EXPORT); @EXPORT = qw(writemain); $VERSION = 1; +# blead will run this with miniperl, hence we can't use autodie or File::Temp +my $temp; + +END { + return if !defined $temp || !-e $temp; + unlink $temp or warn "Can't unlink '$temp': $!"; +} + sub writemain{ - my $fh; - if (ref $_[0]) { + my ($fh, $real); + + if (ref $_[0] eq 'SCALAR') { + $real = ${+shift}; + $temp = $real; + $temp =~ s/(?:.c)?\z/.new/; + open $fh, '>', $temp + or die "Can't open '$temp' for writing: $!"; + } elsif (ref $_[0]) { $fh = shift; } else { $fh = \*STDOUT; @@ -178,6 +193,11 @@ static void xs_init(pTHX) { EOT + + if ($real) { + close $fh or die "Can't close '$temp': $!"; + rename $temp, $real or die "Can't rename '$temp' to '$real': $!"; + } } 1; @@ -193,6 +213,8 @@ ExtUtils::Miniperl - write the C code for perlmain.c writemain(@directories); # or writemain($fh, @directories); + # or + writemain(\$filename, @directories); =head1 DESCRIPTION @@ -200,9 +222,9 @@ C<writemain()> takes an argument list of directories containing archive libraries that relate to perl modules and should be linked into a new perl binary. It writes a corresponding F<perlmain.c> file that is a plain C file containing all the bootstrap code to make the -modules associated with the libraries available from within perl. -If the first argument to C<writemain()> is a reference, it -is used as the file handle to write to. Otherwise output is to C<STDOUT>. +If the first argument to C<writemain()> is a reference to a scalar it is +used as the filename to open for ouput. Any other reference is used as +the filehandle to write to. Otherwise output defaults to C<STDOUT>. The typical usage is from within a Makefile generated by L<ExtUtils::MakeMaker>. So under normal circumstances you won't have to |