From: Randy K. <ra...@th...> - 2005-05-22 02:39:25
|
mod_perl-2 underwent a namespace change recently - see http://perl.apache.org/docs/2.0/rename.html for details, and the reasons why. This new namespace is incorporated into the official mod_perl-2 release, which is just now on CPAN. The following patch works for me in getting SOAP::Lite to work for a simple mod_perl Apache::SOAP handler with the current CPAN mod_perl-2 - this is against the CPAN Soap-Lite-0.65_5 version, as I couldn't get a cvs diff working (an error about not being able to create a /tmp/some_dir arose): ============================================================ --- lib/SOAP/Transport/HTTP.pm.orig Wed Mar 30 02:58:34 2005 +++ lib/SOAP/Transport/HTTP.pm Sat May 21 20:26:26 2005 @@ -505,23 +505,22 @@ $self = $class->SUPER::new(@_); SOAP::Trace::objects('()'); } - die "Could not find or load mod_perl" - unless (eval "require mod_perl"); - die "Could not detect your version of mod_perl" - if (!defined($mod_perl::VERSION)); - if ($mod_perl::VERSION < 1.99) { - require Apache; + MOD_PERL: { + (eval { require Apache;} ) and do { require Apache::Constants; Apache::Constants->import('OK'); $self->{'MOD_PERL_VERSION'} = 1; - } elsif ($mod_perl::VERSION < 3) { - require Apache::RequestRec; - require Apache::RequestIO; - require Apache::Const; - Apache::Const->import(-compile => 'OK'); + last MOD_PERL; + }; + (eval { require Apache2::RequestRec;} ) and do { + require Apache2::RequestUtil; + require Apache2::RequestIO; + require Apache2::Const; + Apache2::Const->import(-compile => 'OK'); $self->{'MOD_PERL_VERSION'} = 2; - } else { - die "Unsupported version of mod_perl"; + last MOD_PERL; + }; + die "Unsupported version of mod_perl"; } return $self; } @@ -529,12 +528,17 @@ sub handler { my $self = shift->new; my $r = shift; - $r = Apache->request if (!$r && $self->{'MOD_PERL_VERSION'} == 1); + unless ($r) { + $r = ($self->{'MOD_PERL_VERSION'} == 1) ? + Apache->request : Apache2::RequestUtil->request(); + } + my $cl = ($self->{'MOD_PERL_VERSION'} == 1) ? + $r->header_in('Content-length') : $r->headers_in->{'Content-length'}; $self->request(HTTP::Request->new( $r->method() => $r->uri, HTTP::Headers->new($r->headers_in), - do { my ($c,$buf); while ($r->read($buf,$r->header_in('Content-length'))) { $c.=$buf; } $c; } + do { my ($c,$buf); while ($r->read($buf,$cl)) { $c.=$buf; } $c; } )); $self->SUPER::handle; @@ -545,10 +549,23 @@ # will emulate normal response, but with custom status code # which could also be 500. $r->status($self->response->code); - $self->response->headers->scan(sub { $r->header_out(@_) }); - $r->send_http_header(join '; ', $self->response->content_type); - $r->print($self->response->content); - return $self->{'MOD_PERL_VERSION'} == 2 ? &Apache::OK : &Apache::Constants::OK; + if ($self->{'MOD_PERL_VERSION'} == 1 ) { + $self->response->headers->scan(sub { $r->header_out(@_) }); + $r->send_http_header(join '; ', $self->response->content_type); + $r->print($self->response->content); + return &Apache::Constants::OK; + } + else { + $self->response->headers->scan(sub { + my %h = @_; + for (keys %h) { + $r->headers_out->{$_} = $h{$_}; + } + }); + $r->content_type(join '; ', $self->response->content_type); + $r->print($self->response->content); + return &Apache2::Const::OK; + } } sub configure { ================================================================= Also, the following diff: ================================================================ --- Makefile.PL.orig Sun Nov 14 13:30:46 2004 +++ Makefile.PL Sat May 21 21:23:28 2005 @@ -13,7 +13,8 @@ ["Client SMTP/sendmail support","SOAP::Transport::MAILTO::Client",{"MIME::Lite" => 0},1], ["Client FTP support","SOAP::Transport::FTP::Client",{"Net::FTP" => 0,"IO::File" => 0},0], ["Standalone HTTP server","SOAP::Transport::HTTP::Daemon",{"HTTP::Daemon" => 0},1], - ["Apache/mod_perl server","SOAP::Transport::HTTP::Apache",{"Apache" => 0},0], + ["Apache-1.3/mod_perl server","SOAP::Transport::HTTP::Apache",{"Apache" => 0},0], + ["Apache-2.0/mod_perl server","SOAP::Transport::HTTP::Apache",{"Apache2::RequestRec" => 0},0], ["FastCGI server","SOAP::Transport::HTTP::FCGI",{"FCGI" => 0},0], ["POP3 server","SOAP::Transport::POP3::Server",{"Net::POP3" => 0,"MIME::Parser" => 0},1], ["IO server","SOAP::Transport::IO::Server",{"IO::File" => 0},0], ======================================================================= alters the Makefile.PL prerequisites to enquire about adding either mod_perl-1 or mod_perl-2 support. -- best regards, randy kobes |