]> git.decadent.org.uk Git - maypole.git/blobdiff - lib/CGI/Maypole.pm
Updated patches for 2.13.
[maypole.git] / lib / CGI / Maypole.pm
index 9b2ee7988faaf69d7f8451d06436758219094468..6448480c16241561846d83feedcd720d265f2afd 100644 (file)
@@ -7,9 +7,9 @@ use CGI::Simple;
 use Maypole::Headers;
 use Maypole::Constants;
 
-our $VERSION = '2.10';
+our $VERSION = '2.13';
 
-__PACKAGE__->mk_accessors( qw( cgi ) );
+__PACKAGE__->mk_accessors( qw/cgi/ );
 
 =head1 NAME
 
@@ -54,10 +54,19 @@ Call this from your CGI script to start the Maypole application.
 
 =cut
 
-sub run 
-{
-    my $self = shift;
-    return $self->handler;
+sub run  {
+  my $self = shift;
+  my $status = $self->handler;
+  if ($status != OK) {
+    print <<EOT;
+Status: 500 Maypole application error
+Content-Type: text/html
+
+<title>Maypole application error</h1>
+<h1>Maypole application error</h1>
+EOT
+  }
+  return $status;
 }
 
 =head1 Implementation
@@ -71,9 +80,11 @@ functionality. See L<Maypole> for these:
 
 =cut
 
-sub get_request 
-{
-    shift->cgi( CGI::Simple->new );
+sub get_request {
+  my $self = shift;
+  my $request_options = $self->config->request_options || {};
+  $CGI::Simple::POST_MAX = $request_options->{POST_MAX} if ($request_options->{POST_MAX});
+  $self->cgi( CGI::Simple->new );
 }
 
 =item parse_location
@@ -92,12 +103,18 @@ sub parse_location
         $r->headers_in->set($field_name => $cgi->http($http_header));
     }
 
+    $r->preprocess_location();
+
     my $path = $cgi->url( -absolute => 1, -path_info => 1 );
     my $loc = $cgi->url( -absolute => 1 );
     {
         no warnings 'uninitialized';
         $path .= '/' if $path eq $loc;
-        $path =~ s/^($loc)?\///;
+       if ($loc =~ /\/$/) {
+         $path =~ s/^($loc)?//;
+       } else {
+         $path =~ s/^($loc)?\///;
+       }
     }
     $r->path($path);
     
@@ -105,6 +122,17 @@ sub parse_location
     $r->parse_args;
 }
 
+=item warn
+
+=cut
+
+sub warn {
+    my ($self,@args) = @_;
+    my ($package, $line) = (caller)[0,2];
+    warn "[$package line $line] ", @args ;
+    return;
+}
+
 =item parse_args
 
 =cut
@@ -164,12 +192,28 @@ sub get_protocol
 
 =item send_output
 
+Generates output (using C<collect_output>) and prints it. 
+
 =cut
 
 sub send_output 
 {
     my $r = shift;
+    print $r->collect_output;
+}
+
+=item collect_output
+
+Gathers headers and output together into a string and returns it.
+
+Splitting this code out of C<send_output> supports L<Maypole::HTTPD::Frontend>.
 
+=cut
+
+sub collect_output
+{
+    my $r = shift;
+    
     # Collect HTTP headers
     my %headers = (
         -type            => $r->content_type,
@@ -181,7 +225,7 @@ sub send_output
         $headers{"-$_"} = $r->headers_out->get($_);
     }
 
-    print $r->cgi->header(%headers), $r->output;
+    return $r->cgi->header(%headers) . $r->output;
 }
 
 =item get_template_root