httpd-test-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stas Bekman <s...@stason.org>
Subject [patch] Apache::TestConfig::write_perlscript()
Date Thu, 13 Dec 2001 18:33:59 GMT
I need to autogenerate a few executable Perl scripts at
APACHE_TEST_CONFIGURE and have them persist till -clean. So I've added
this function.

p.s. I'm adding a similar one to Apache::TestUtil, but cannot use it here
since it'll delete the file at the end of -config.

BTW, we have a duplication of file/dir create, file write subs in
TestConfig and TestUtil. The only difference is that TestConfig requires
$config object and the created files/dirs persist till -clean, whereas
TestUtil's functions are for request duration only.


Index: Apache-Test/lib/Apache/TestConfig.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfig.pm,v
retrieving revision 1.96
diff -u -r1.96 TestConfig.pm
--- Apache-Test/lib/Apache/TestConfig.pm	2001/12/13 17:13:03	1.96
+++ Apache-Test/lib/Apache/TestConfig.pm	2001/12/13 18:28:21
@@ -645,6 +645,37 @@
     close $fh;
 }

+# gen + write excutable perl script file
+sub write_perlscript {
+    my($self, $file, $content) = @_;
+
+    # create the parent dir if it doesn't exist yet
+    my $dir = dirname $file;
+    $self->makepath($dir);
+
+    my $name = abs2rel $file, $self->{vars}->{t_dir};
+    $self->trace("generating $name");
+
+    my $fh = Symbol::gensym();
+    open $fh, ">$file" or die "open $file: $!";
+
+    # shebang
+    print $fh "#!$Config{perlpath}\n";
+
+    if (my $msg = $self->genwarning($file)) {
+        print $fh $msg, "\n";
+    }
+
+    if ($content) {
+        print $fh $content;
+    }
+
+    $self->{clean}->{files}->{$file} = 1;
+
+    close $fh;
+    chmod 0555, $file;
+}
+
 sub cpfile {
     my($self, $from, $to) = @_;
     File::Copy::copy($from, $to);



_____________________________________________________________________
Stas Bekman             JAm_pH      --   Just Another mod_perl Hacker
http://stason.org/      mod_perl Guide   http://perl.apache.org/guide
mailto:stas@stason.org  http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/


Mime
View raw message