[ trimmed mod_perl mailing list from cc ]
On Fri, 29 Aug 2003, Randy Kobes wrote:
On Thu, 28 Aug 2003, Stas Bekman wrote:
Several people have asked for having a new feature in Apache::Test: they want to configure it once (where the server, apxs, etx are) and run Apache::Test without needing to pass any arguments. Matt suggested that it should remember the values passed the first time it's used and then re-use them. However on a system with several users and different preferences, this won't work. Therefore we need to be able to support per-user preferences. CPAN.pm's setup seems to provide a good solution to the same problem (CPAN/Config.pm and ~user/.cpan/CPAN/Config.pm). So I thought that someone would like to port the functionality from CPAN.pm to Apache::Test and send the patches here. It's all pure perl, so you have no excuses that it's XS/C ;)
I have a mostly functional version of this, save for the ability to use a $HOME/.apache-test/Config.pm, which shouldn't be too hard to add. I'll try to finish it off this weekend.
A stab at this follows ... It's rough, as I wanted to make sure this was on the right track; basically, what's supposed to happen is - if a Apache::MyTestConfig is found, use the values for
Apache::TestMyConfig? so that we keep all Apache/Test*.pm and it's My Config, not My Test... but see below
apxs, httpd, user, group, and port stored in there. These values get overridden if they appear as arguments to 'perl Makefile.PL'.
which embeds them in t/TEST, so in effect if they are passed to the code that runs a subclass of Apache::TestRun
- if no Apache::MyTestConfig is present, or a '-save' option is passed to 'perl t/TEST', Apache::MyTestConfig is created, and then installed. - the location of Apache::MyTestConfig is, first of all, under $HOME/.apache-test/, or if this is not present, under the system @INC.
If it's under system-wide @INC, it probably should be called My because it's not user specific (I'm trying to mimic CPAN.pm here. BTW, I haven't been using CPANPLUS, how do they do it?) But then it'll collide with the existing Apache/TestConfig.pm. So may be we just have Apache/TestConfigData.pm (or something like that) and then we don't need My at all, as we will just look first under $HOME/.apache-test and then under @INC?
I think when Apache::Test is installed, the config data module should go into @INC's location. when it's used for the first time it should go into $HOME/.apache-test/.
Won't ~/.apache-test have probs on some filesystems? Is it a safe path?
I'm not sure I'm putting the values of Apache::MyTestConfig in the right, or best, place; I haven't tested it extensively, as my linux box is a live server.
========================================================= Index: TestConfig.pm =================================================================== RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfig.pm,v retrieving revision 1.171 diff -u -r1.171 TestConfig.pm --- TestConfig.pm 13 Aug 2003 19:02:51 -0000 1.171 +++ TestConfig.pm 1 Sep 2003 03:51:13 -0000 @@ -3,6 +3,22 @@ use strict; use warnings FATAL => 'all';
+require File::Spec; +sub has_config { + my $has_config = 0; + if ($ENV{HOME}) { + eval + {require File::Spec->catfile($ENV{HOME}, + '.apache-test', 'MyTestConfig.pm');};
That won't work when invoked from the server side, since HOME isn't normally propogated. Probably need to detect whether we are running under mod_perl 2.0 and then retrieve the username the server is running under, but wait, normally it runs under 'nobody' or a such, so it won't have this setup...
in any case for now you probably need to check first whether $ENV{HOME} exists and put some XXX to fix it later so it'll work under mod_perl as well...
@@ -24,8 +40,8 @@ use File::Path (); use File::Spec::Functions qw(catfile abs2rel splitdir canonpath catdir file_name_is_absolute); -use Cwd qw(fastcwd);
+use Cwd qw(fastcwd);
weird...
use Apache::TestConfigPerl (); use Apache::TestConfigParse (); use Apache::TestTrace; @@ -34,6 +50,8 @@
use vars qw(%Usage);
+use constant HAS_CONFIG => has_config(); + %Usage = ( top_dir => 'top-level directory (default is $PWD)', t_dir => 'the t/ test directory (default is $top_dir/t)', @@ -72,6 +90,12 @@
sub filter_args { my($args, $wanted_args) = @_; + if (HAS_CONFIG) { + for (qw(group user apxs port httpd)) { + next unless defined $Apache::MyTestConfig->{$_}; + unshift @$args, "-$_", $Apache::MyTestConfig->{$_}; + } + }
may be it's better to do it at a later stage? this just used to generate t/TEST and similar scripts. If MyConfig has changed since t/TEST was generated the changes won't affect t/TEST.
[...]my(@pass, %keep);
my @filter = @$args; Index: TestRun.pm ===================================================================
+ $self->write_config() if
+ ($self->{opts}->{save} || not HAS_CONFIG);
Do you mind to have 'or not' or '|| !' ;)
+ }
my @oh = qw(jeez golly gosh darn shucks dangit rats nuts dangnabit crap); @@ -915,6 +924,75 @@ # require Carp; # Carp::cluck('exiting'); CORE::exit $_[0]; +} + +sub write_config { + my $self = shift; + my $dir; + for (@INC) { + my $candidate = catfile($_, 'Apache', 'Test.pm'); + if (-e $candidate) { + $dir = dirname($candidate); + last; + } + } + unless (-w $dir) { + $dir = catdir($ENV{HOME}, '.apache-test'); + unless (-d $dir) { + mkdir $dir or do { + warn "Cannot mkdir $dir: $!"; + return; + }; + } + }
Probably this should be an explicit attempt to write to ~/.apache-test if run as non-root, since it'll most likely fail to write to the system-wide @INC. Of course it may have a local non-root libs, in @INC. And we can simplify this further by creating Apache/TestConfigData.pm (or whatever we call it), when we install Apache::Test for the first time. So we don't have to look for Apache/Test.pm. So it'll just have:
+ my $pkg = << "EOC";
+package Apache::MyTestConfig;
+\$Apache::MyTestConfig = {
+};
+1;
+
+=head1 NAME
+
+Apache::MyTestConfig - Configuration file for Apache::Test
+
+=cut
+EOCor may be having all the keys, but just no values?
+ for (qw(group user apxs port httpd)) {
+ next unless $vars->{$_};
+ $config_dump .= "$_ => ''\n";
+ }__________________________________________________________________ Stas Bekman JAm_pH ------> Just Another mod_perl Hacker http://stason.org/ mod_perl Guide ---> http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
