Subject: | Assumes method handler |
Date: | Wed, 28 Oct 2009 20:26:37 +0000 |
To: | bug-Test-Apache2 [...] rt.cpan.org |
From: | ilmari [...] ilmari.org (Dagfinn Ilmari Mannsåker) |
According to the mod_perl documentation[1], handler() should be invoked
as a method only when it has the "method" attribute. Attached is a patch
that implements this, with tests (and the existing tests adjusted
accordingly).
commit ea913b9808f0b4c6110ce6faf3d98d402cadf2ec
Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Date: Wed Oct 28 20:19:31 2009 +0000
Handle non-method handler()
diff --git a/lib/Test/Apache2/Server.pm b/lib/Test/Apache2/Server.pm
index 7999cee..140d2fa 100644
--- a/lib/Test/Apache2/Server.pm
+++ b/lib/Test/Apache2/Server.pm
@@ -6,6 +6,7 @@ __PACKAGE__->mk_accessors(qw(host));
use Test::Apache2::RequestRec;
use HTTP::Response;
+use attributes ();
sub new {
my ($class, @args) = @_;
@@ -67,7 +68,13 @@ sub _request {
{
local *STDOUT;
open STDOUT, '>', \$buffer;
- $class->handler($req);
+ my $handler = $class->can('handler');
+ if (grep { $_ eq 'method' } attributes::get($handler)) {
+ $class->$handler($req);
+ }
+ else {
+ $handler->($req);
+ }
}
if ($buffer) {
diff --git a/t/FooHandler.pm b/t/FooHandler.pm
index dcc28ba..980a21a 100644
--- a/t/FooHandler.pm
+++ b/t/FooHandler.pm
@@ -3,7 +3,7 @@ use strict;
use warnings;
use Apache2::Const;
-sub handler {
+sub handler :method {
my ($class_or_obj, $req) = @_;
$req->content_type('text/plain');
diff --git a/t/NonMethodHandler.pm b/t/NonMethodHandler.pm
new file mode 100644
index 0000000..6d4e3ee
--- /dev/null
+++ b/t/NonMethodHandler.pm
@@ -0,0 +1,13 @@
+package t::NonMethodHandler;
+use strict;
+use warnings;
+use Apache2::Const;
+
+sub handler {
+ my ($req) = @_;
+ $req->content_type('text/plain');
+ $req->print('not a method');
+ return Apache2::Const::OK;
+}
+
+1;
diff --git a/t/Util.pm b/t/Util.pm
index d1d038a..57c0d22 100644
--- a/t/Util.pm
+++ b/t/Util.pm
@@ -24,7 +24,7 @@ use strict;
use warnings;
our $HANDLER;
-sub handler {
+sub handler :method {
$HANDLER->(@_);
}
--
ilmari
"A disappointingly low fraction of the human race is,
at any given time, on fire." - Stig Sandbeck Mathisen