X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FApache%2FMVC.pm;h=3294df0490a32d579d0bc224f09be96efdc20056;hb=9b27a09c3eefdad91ae3da125ea5dc71d08ed662;hp=e284b1e54e8df4b03f8aee8878c64fa24959ea5d;hpb=fb48746a79e660e7f5df5a22269ca9e22519eaa5;p=maypole.git diff --git a/lib/Apache/MVC.pm b/lib/Apache/MVC.pm index e284b1e..3294df0 100644 --- a/lib/Apache/MVC.pm +++ b/lib/Apache/MVC.pm @@ -1,13 +1,27 @@ package Apache::MVC; -use base 'Maypole'; -use Apache; -use Apache::Request; + use strict; use warnings; -our $VERSION = "0.3"; + +use base 'Maypole'; +use mod_perl; + +use constant APACHE2 => $mod_perl::VERSION >= 1.99; + +if ( APACHE2 ) { + require Apache2; + require Apache::RequestRec; + require Apache::RequestUtil; + require APR::URI; +} +else { require Apache } +require Apache::Request; + +our $VERSION = "0.4"; sub get_request { - shift->{ar} = Apache::Request->new(Apache->request); + my ( $self, $r ) = @_; + $self->{ar} = Apache::Request->new($r); } sub parse_location { @@ -17,22 +31,36 @@ sub parse_location { no warnings 'uninitialized'; $self->{path} =~ s/^($loc)?\///; $self->parse_path; + $self->parse_args; +} - $self->{params} = { $self->{ar}->content }; - $self->{query} = { $self->{ar}->args }; +sub parse_args { + my $self = shift; + $self->{params} = { $self->_mod_perl_args( $self->{ar} ) }; + $self->{query} = { $self->_mod_perl_args( $self->{ar} ) }; } sub send_output { my $r = shift; - $r->{ar}->content_type($r->{content_type}); - $r->{ar}->headers_out->set("Content-Length" => length $r->{output}); - $r->{ar}->send_http_header; - $r->{ar}->print($r->{output}); + $r->{ar}->content_type( $r->{content_type}."; charset=".$r->{document_encoding} ); + $r->{ar}->headers_out->set( "Content-Length" => length $r->{output} ); + APACHE2 || $r->{ar}->send_http_header; + $r->{ar}->print( $r->{output} ); } sub get_template_root { my $r = shift; - $r->{ar}->document_root . "/". $r->{ar}->location; + $r->{ar}->document_root . "/" . $r->{ar}->location; +} + +sub _mod_perl_args { + my ( $self, $apr ) = @_; + my %args; + foreach my $key ( $apr->param ) { + my @values = $apr->param($key); + $args{$key} = @values == 1 ? $values[0] : \@values; + } + return %args; } 1; @@ -127,6 +155,8 @@ see L. =head1 AUTHOR Simon Cozens, C +Marcus Ramberg, C +Screwed up by Sebastian Riedel, C =head1 LICENSE