[PATCH] new need functions

2004-08-02 Thread Geoffrey Young
hi all

ok, attached is a patch that implements the new need variants and alters the
old have variants.  basically, all I did was a global rename of have to
need, then implement the have routines in terms of need with the AutoLoader.
 I thought this made a bit more sense than redefining all of those
subroutines again when the only difference was simply not populating
@SkipReasons.

the mod_perl test suite continues to run, as does the perl-framework, so
nothing (that I can see at least) should be broken.

anyway, comments welcome, as well as documentation - I couldn't decide where
to add the have stuff so I just didn't do anything.

--Geoff
Index: lib/Apache/Test.pm
===
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/Test.pm,v
retrieving revision 1.87
diff -u -r1.87 Test.pm
--- lib/Apache/Test.pm	31 Jul 2004 01:35:25 -	1.87
+++ lib/Apache/Test.pm	2 Aug 2004 15:46:28 -
@@ -22,7 +22,8 @@
 use Config;
 use Apache::TestConfig ();
 
-use vars qw(@ISA @EXPORT %EXPORT_TAGS $VERSION %SubTests @SkipReasons);
+use vars qw(@ISA @EXPORT %EXPORT_TAGS $VERSION %SubTests @SkipReasons 
+$AUTOLOAD);
 
 @ISA = qw(Exporter);
 @EXPORT = qw(ok skip sok plan have have_lwp have_http11
@@ -30,7 +31,12 @@
  have_min_apache_version have_apache_version have_perl 
  have_min_perl_version have_min_module_version
  have_threads under_construction skip_reason have_apache_mpm
- have_php);
+ have_php
+ need need_lwp need_http11 need_cgi need_access need_auth
+ need_module need_apache need_min_apache_version
+ need_apache_version need_perl need_min_perl_version
+ need_min_module_version need_threads need_apache_mpm
+ need_php);
 
 # everything but ok(), skip(), and plan() - Test::More provides these
 my @test_more_exports = grep { ! /^(ok|skip|plan)$/ } @EXPORT;
@@ -104,7 +110,7 @@
 $r-content_type('text/plain');
 }
 
-sub have_http11 {
+sub need_http11 {
 require Apache::TestRequest;
 if (Apache::TestRequest::install_http11()) {
 return 1;
@@ -116,12 +122,12 @@
 }
 }
 
-sub have_ssl {
+sub need_ssl {
 my $vars = vars();
-have_module([$vars-{ssl_module_name}, 'Net::SSL']);
+need_module([$vars-{ssl_module_name}, 'Net::SSL']);
 }
 
-sub have_lwp {
+sub need_lwp {
 require Apache::TestRequest;
 if (Apache::TestRequest::has_lwp()) {
 return 1;
@@ -150,7 +156,7 @@
 }
 elsif ($ref eq 'ARRAY') {
 #plan tests $n, [qw(php4 rewrite)];
-$meets_condition = have_module($condition);
+$meets_condition = need_module($condition);
 }
 else {
 die don't know how to handle a condition of type $ref;
@@ -178,29 +184,29 @@
 print # Using Apache/Test.pm version $VERSION\n;
 }
 
-sub have {
-my $have_all = 1;
+sub need {
+my $need_all = 1;
 for my $cond (@_) {
 if (ref $cond eq 'HASH') {
 while (my($reason, $value) = each %$cond) {
 $value = $value-() if ref $value eq 'CODE';
 next if $value;
 push @SkipReasons, $reason;
-$have_all = 0;
+$need_all = 0;
 }
 }
 elsif ($cond =~ /^(0|1)$/) {
-$have_all = 0 if $cond == 0;
+$need_all = 0 if $cond == 0;
 }
 else {
-$have_all = 0 unless have_module($cond);
+$need_all = 0 unless need_module($cond);
 }
 }
-return $have_all;
+return $need_all;
 
 }
 
-sub have_module {
+sub need_module {
 my $cfg = config();
 my @modules = ref($_[0]) ? @{ $_[0] } : @_;
 
@@ -234,7 +240,7 @@
 }
 }
 
-sub have_min_perl_version {
+sub need_min_perl_version {
 my $version = shift;
 
 return 1 if $] = $version;
@@ -244,11 +250,11 @@
 }
 
 # currently supports only perl modules
-sub have_min_module_version {
+sub need_min_module_version {
 my($module, $version) = @_;
 
-# have_module requires the perl module
-return 0 unless have_module($module);
+# need_module requires the perl module
+return 0 unless need_module($module);
 
 return 1 if eval { $module-VERSION($version) };
 
@@ -256,23 +262,23 @@
 return 0;
 }
 
-sub have_cgi {
-have_module('cgi') || have_module('cgid');
+sub need_cgi {
+need_module('cgi') || need_module('cgid');
 }
 
-sub have_php {
-have_module('php4') || have_module('php5');
+sub need_php {
+need_module('php4') || need_module('php5');
 }
 
-sub have_access {
-have_module('access') || have_module('authz_host');
+sub need_access {
+need_module('access') || need_module('authz_host');
 }
 
-sub have_auth {
-have_module('auth') || have_module('auth_basic');
+sub need_auth {
+need_module('auth') || need_module('auth_basic');
 }
 
-sub have_apache {

Re: [PATCH] new need functions

2004-08-02 Thread Stas Bekman
Geoffrey Young wrote:
hi all
ok, attached is a patch that implements the new need variants and alters the
old have variants.  basically, all I did was a global rename of have to
need, then implement the have routines in terms of need with the AutoLoader.
 I thought this made a bit more sense than redefining all of those
subroutines again when the only difference was simply not populating
@SkipReasons.
the mod_perl test suite continues to run, as does the perl-framework, so
nothing (that I can see at least) should be broken.
anyway, comments welcome, as well as documentation - I couldn't decide where
to add the have stuff so I just didn't do anything.
I'd suggest to simply explain that there are have_ and need_ functions 
at the beginning of that section that explains need_* ones. And one 
should use need_* inside plan(), because of the skip messages. Otherwise 
use have_*.

Please don't commit w/o the docs. Once it's committed, the docs are most 
likely will be forgotten.

You don't want to remember to update two places when you add new 
functions. So there should be a need* functions array and when you 
populate the @EXPORT list you generate the have* list. Also there should 
be no have() function, but only need(). The rest map need_* = have_*.

Next you can use that have* list to generate the actual functions on the 
fly, similar to the generation of the subs similar to log levels subs in 
Apache::TestTrace. So you don't really need AUTOLOAD. It'll take the 
same amount of code w/o AUTOLOAD.

+sub AUTOLOAD {
+
+use vars qw($AUTOLOAD @SkipReasons);
haven't you declared the two at the top of Test.pm already?
+(my $method) = $AUTOLOAD =~ m/.*::(.*)/;
+
+return unless $method =~ m/^have/;
+
+$method =~ s/^have/need/;
+
+if (my $cv = Apache::Test-can($method)) {
+my @skip = @SkipReasons;
+my $rc = $cv-(@_);
+@SkipReasons = @skip;
+return $rc;
why not just:
 local @SkipReasons;
 return $cv-(@_);
+}
+else {
+die could not find function $AUTOLOAD;
+} 
+}
+

--
__
Stas BekmanJAm_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


Re: [PATCH] new need functions

2004-08-02 Thread Geoffrey Young

 I'd suggest to simply explain that there are have_ and need_ functions
 at the beginning of that section that explains need_* ones. And one
 should use need_* inside plan(), because of the skip messages. Otherwise
 use have_*.

ok, done.

 
 Please don't commit w/o the docs. Once it's committed, the docs are most
 likely will be forgotten.

of course, no reminder necessary :)

 
 You don't want to remember to update two places when you add new
 functions. So there should be a need* functions array and when you
 populate the @EXPORT list you generate the have* list. Also there should
 be no have() function, but only need(). The rest map need_* = have_*.

good idea, done.

 
 Next you can use that have* list to generate the actual functions on the
 fly, similar to the generation of the subs similar to log levels subs in
 Apache::TestTrace. So you don't really need AUTOLOAD. It'll take the
 same amount of code w/o AUTOLOAD.

except that the autoload code is already written :)

 
 +sub AUTOLOAD {
 +
 +use vars qw($AUTOLOAD @SkipReasons);
 
 
 haven't you declared the two at the top of Test.pm already?

sorry, leftover debugging foo.


 why not just:
 
  local @SkipReasons;
  return $cv-(@_);

yeah, that's better.

new patch attached.

--Geoff
Index: lib/Apache/Test.pm
===
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/Test.pm,v
retrieving revision 1.87
diff -u -r1.87 Test.pm
--- lib/Apache/Test.pm	31 Jul 2004 01:35:25 -	1.87
+++ lib/Apache/Test.pm	2 Aug 2004 18:08:44 -
@@ -22,15 +22,19 @@
 use Config;
 use Apache::TestConfig ();
 
-use vars qw(@ISA @EXPORT %EXPORT_TAGS $VERSION %SubTests @SkipReasons);
+use vars qw(@ISA @EXPORT %EXPORT_TAGS $VERSION %SubTests @SkipReasons 
+$AUTOLOAD);
+
+my @need = qw(need_lwp need_http11 need_cgi need_access need_auth
+  need_module need_apache need_min_apache_version
+  need_apache_version need_perl need_min_perl_version
+  need_min_module_version need_threads need_apache_mpm
+  need_php);
+
+my @have = map { (my $need = $_) =~ s/need/have/; $need } @need;
 
 @ISA = qw(Exporter);
[EMAIL PROTECTED] = qw(ok skip sok plan have have_lwp have_http11
- have_cgi have_access have_auth have_module have_apache
- have_min_apache_version have_apache_version have_perl 
- have_min_perl_version have_min_module_version
- have_threads under_construction skip_reason have_apache_mpm
- have_php);
[EMAIL PROTECTED] = (qw(ok skip sok plan skip_reason under_construction need), @need, @have);
 
 # everything but ok(), skip(), and plan() - Test::More provides these
 my @test_more_exports = grep { ! /^(ok|skip|plan)$/ } @EXPORT;
@@ -104,7 +108,7 @@
 $r-content_type('text/plain');
 }
 
-sub have_http11 {
+sub need_http11 {
 require Apache::TestRequest;
 if (Apache::TestRequest::install_http11()) {
 return 1;
@@ -116,12 +120,12 @@
 }
 }
 
-sub have_ssl {
+sub need_ssl {
 my $vars = vars();
-have_module([$vars-{ssl_module_name}, 'Net::SSL']);
+need_module([$vars-{ssl_module_name}, 'Net::SSL']);
 }
 
-sub have_lwp {
+sub need_lwp {
 require Apache::TestRequest;
 if (Apache::TestRequest::has_lwp()) {
 return 1;
@@ -150,7 +154,7 @@
 }
 elsif ($ref eq 'ARRAY') {
 #plan tests $n, [qw(php4 rewrite)];
-$meets_condition = have_module($condition);
+$meets_condition = need_module($condition);
 }
 else {
 die don't know how to handle a condition of type $ref;
@@ -178,29 +182,29 @@
 print # Using Apache/Test.pm version $VERSION\n;
 }
 
-sub have {
-my $have_all = 1;
+sub need {
+my $need_all = 1;
 for my $cond (@_) {
 if (ref $cond eq 'HASH') {
 while (my($reason, $value) = each %$cond) {
 $value = $value-() if ref $value eq 'CODE';
 next if $value;
 push @SkipReasons, $reason;
-$have_all = 0;
+$need_all = 0;
 }
 }
 elsif ($cond =~ /^(0|1)$/) {
-$have_all = 0 if $cond == 0;
+$need_all = 0 if $cond == 0;
 }
 else {
-$have_all = 0 unless have_module($cond);
+$need_all = 0 unless need_module($cond);
 }
 }
-return $have_all;
+return $need_all;
 
 }
 
-sub have_module {
+sub need_module {
 my $cfg = config();
 my @modules = ref($_[0]) ? @{ $_[0] } : @_;
 
@@ -234,7 +238,7 @@
 }
 }
 
-sub have_min_perl_version {
+sub need_min_perl_version {
 my $version = shift;
 
 return 1 if $] = $version;
@@ -244,11 +248,11 @@
 }
 
 # currently supports only perl modules
-sub have_min_module_version {
+sub need_min_module_version {
 my($module, $version) = @_;
 
-# have_module requires the perl