diff options
author | Nicholas Clark <nick@ccl4.org> | 2011-01-23 10:07:52 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2011-01-23 10:07:52 +0000 |
commit | f038801aea0ff24cf86511fa6679d7dcb859cd8d (patch) | |
tree | 8f46ea92b16a9121bab4ee0da59cdf219e43a254 /regen/overload.pl | |
parent | 396ce246b9969d83ec11500def9604b58fb4c726 (diff) | |
download | perl-f038801aea0ff24cf86511fa6679d7dcb859cd8d.tar.gz |
In regen/*.pl, refactor the repeated code for close and rename if different.
Pass the final file name as an optional second argument of safer_open() and
store it with the file handle. Add a function close_and_rename() which closes
the file handle, then retrieves the final name, and renames the temporary file
if the two differ.
Diffstat (limited to 'regen/overload.pl')
-rw-r--r-- | regen/overload.pl | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/regen/overload.pl b/regen/overload.pl index d01348a01f..7ff3f124ae 100644 --- a/regen/overload.pl +++ b/regen/overload.pl @@ -30,10 +30,10 @@ while (<DATA>) { push @names, $name; } -my $c = safer_open("overload.c-new"); -my $h = safer_open("overload.h-new"); +my $c = safer_open('overload.c-new', 'overload.c'); +my $h = safer_open('overload.h-new', 'overload.h'); mkdir("lib/overload", 0777) unless -d 'lib/overload'; -my $p = safer_open('lib/overload/numbers.pm-new'); +my $p = safer_open('lib/overload/numbers.pm-new', 'lib/overload/numbers.pm'); select $p; @@ -129,12 +129,9 @@ print $c <<"EOT"; }; EOT -safer_close($h); -safer_close($c); -safer_close($p); -rename_if_different("overload.c-new", "overload.c"); -rename_if_different("overload.h-new","overload.h"); -rename_if_different('lib/overload/numbers.pm-new', 'lib/overload/numbers.pm'); +close_and_rename($h); +close_and_rename($c); +close_and_rename($p); __DATA__ # Fallback should be the first |