[svn:parrot] r43569 - branches/one_make/tools/build

jkeenan at svn.parrot.org jkeenan at svn.parrot.org
Sat Jan 23 17:19:08 UTC 2010


Author: jkeenan
Date: Sat Jan 23 17:19:07 2010
New Revision: 43569
URL: https://trac.parrot.org/parrot/changeset/43569

Log:
1. Encapsulate heredoc in print_generated_file().
2. Rename some variables to be more self-documenting.

Modified:
   branches/one_make/tools/build/h2inc.pl

Modified: branches/one_make/tools/build/h2inc.pl
==============================================================================
--- branches/one_make/tools/build/h2inc.pl	Sat Jan 23 17:09:49 2010	(r43568)
+++ branches/one_make/tools/build/h2inc.pl	Sat Jan 23 17:19:07 2010	(r43569)
@@ -24,27 +24,21 @@
 
 my @defs = perform_directive($directive);
 my $target  = $directive->{file};
-my $gen;
+my $generated_text;
 if ($target =~ /\.pm$/) {
-    $gen = join "\n", const_to_perl(@defs);
-    $gen .= "\n1;";
+    $generated_text = join "\n", const_to_perl(@defs);
+    $generated_text .= "\n1;";
 }
 else {
-    $gen = join "\n", const_to_parrot(@defs);
+    $generated_text = join "\n", const_to_parrot(@defs);
 }
 
-open my $out_fh, '>', $out_file or die "Can't open $out_file: $!\n";
-print $out_fh <<"EOF";
-# DO NOT EDIT THIS FILE.
-#
-# This file is generated automatically from
-# $in_file by $0
-#
-# Any changes made here will be lost.
-#
-$gen
-EOF
-close $out_fh;
+print_generated_file( {
+    in      => $in_file,
+    out     => $out_file,
+    script  => $0,
+    gen     => $generated_text,
+} );
 
 =head1 SUBROUTINES
 
@@ -297,6 +291,22 @@
     transform_name( sub { $prefix . $_[0] }, @_ );
 }
 
+sub print_generated_file {
+    my $args = shift;
+    open my $out_fh, '>', $args->{out} or die "Can't open $args->{out}: $!\n";
+    print $out_fh <<"EOF";
+# DO NOT EDIT THIS FILE.
+#
+# This file is generated automatically from
+# $args->{in} by $args->{script}
+#
+# Any changes made here will be lost.
+#
+$args->{gen}
+EOF
+    close $out_fh;
+}
+
 1;
 
 # Local Variables:


More information about the parrot-commits mailing list