X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FApache%2FMVC.pm;h=465311293f122422537a498dccff44b7790930e5;hb=2e483f35964e1ddd2022df6adc2b6d6a631c0cbd;hp=4539c9dbdb5cf26593920f3be2466f0cfbe0d6e2;hpb=b6e2413ee413ce21b28429c05bbcc3f516a0754a;p=maypole.git diff --git a/lib/Apache/MVC.pm b/lib/Apache/MVC.pm index 4539c9d..4653112 100644 --- a/lib/Apache/MVC.pm +++ b/lib/Apache/MVC.pm @@ -1,29 +1,44 @@ package Apache::MVC; -our $VERSION = '2.05'; +our $VERSION = '2.10'; use strict; use warnings; use base 'Maypole'; -use mod_perl; use Maypole::Headers; +use Maypole::Constants; + +__PACKAGE__->mk_accessors( qw( ar ) ); + +BEGIN { + my $version; + eval 'use mod_perl2; $version = $mod_perl2::VERSION; '; + if ($@) { + use mod_perl; + $version = 0; + require Apache; + require Apache::Request; + } else { + require Apache2::RequestIO; + require Apache2::RequestRec; + require Apache2::RequestUtil; + require APR::URI; + require Apache2::Request; + } -use constant APACHE2 => $mod_perl::VERSION >= 1.99; - -if (APACHE2) { - require Apache2; - require Apache::RequestIO; - require Apache::RequestRec; - require Apache::RequestUtil; - require APR::URI; + use constant APACHE2 => $version; } -else { require Apache } -require Apache::Request; sub get_request { my ( $self, $r ) = @_; - $self->{ar} = Apache::Request->new($r); + $self->{ar} = (APACHE2) ? Apache2::Request->new($r) : Apache::Request->new($r); +} + +sub get_protocol { + my $self = shift; + my $protocol = ( $self->{ar}->protocol =~ m/https/i ) ? 'https' : 'http' ; + return $protocol; } sub parse_location { @@ -53,6 +68,29 @@ sub parse_args { $self->{query} = { $self->_mod_perl_args( $self->{ar} ) }; } +# FIXME: use headers_in to gather host and other information? +sub redirect_request { + my $self = shift; + my $redirect_url = $_[0]; + my $status = "302"; + if ($_[1]) { + my %args = @_; + if ($args{url}) { + $redirect_url = $args{url}; + } else { + my $path = $args{path} || $self->{path}; + my $host = $args{domain} || $self->{ar}->hostname; + my $protocol = $args{protocol} || ( $self->{ar}->protocol =~ m/https/i ) ? 'https' : 'http' ;; + $redirect_url = "${protocol}://${host}/${path}"; + } + $status = $args{status} if ($args{status}); + } + + $self->headers_out->set('Status' => $status); + $self->headers_out->set('Location' => $redirect_url); + return OK; +} + sub send_output { my $r = shift; $r->{ar}->content_type(