package Catalyst::Engine::CGI;
+use MRO::Compat;
+use mro 'c3';
use Moose;
extends 'Catalyst::Engine';
has env => (is => 'rw');
+no Moose;
+
=head1 NAME
Catalyst::Engine::CGI - The CGI Engine
$c->response->header( Status => $c->response->status );
- $self->{_header_buf}
+ $self->{_header_buf}
= $c->response->headers->as_string("\015\012") . "\015\012";
}
# set the request URI
my $path = $base_path . ( $ENV{PATH_INFO} || '' );
$path =~ s{^/+}{};
-
+
# Using URI directly is way too slow, so we construct the URLs manually
my $uri_class = "URI::$scheme";
-
+
# HTTP_HOST will include the port even if it's 80/443
$host =~ s/:(?:80|443)$//;
-
+
if ( $port !~ /^(?:80|443)$/ && $host !~ /:/ ) {
$host .= ":$port";
}
-
+
# Escape the path
$path =~ s/([^$URI::uric])/$URI::Escape::escapes{$1}/go;
$path =~ s/\?/%3F/g; # STUPID STUPID SPECIAL CASE
-
+
my $query = $ENV{QUERY_STRING} ? '?' . $ENV{QUERY_STRING} : '';
my $uri = $scheme . '://' . $host . '/' . $path . $query;
# set the base URI
# base must end in a slash
$base_path .= '/' unless $base_path =~ m{/$};
-
+
my $base_uri = $scheme . '://' . $host . $base_path;
$c->request->base( bless \$base_uri, $uri_class );
=cut
-around prepare_query_parameters => sub {
- my $orig = shift;
+sub prepare_query_parameters {
my ( $self, $c ) = @_;
local (*ENV) = $self->env || \%ENV;
if ( $ENV{QUERY_STRING} ) {
- $self->$orig( $c, $ENV{QUERY_STRING} );
+ $self->next::method( $c, $ENV{QUERY_STRING} );
}
-};
+}
=head2 $self->prepare_request($c, (env => \%env))
=cut
-before prepare_write => sub {
+sub prepare_write {
*STDOUT->autoflush(1);
-};
+ return shift->next::method(@_);
+}
=head2 $self->write($c, $buffer)
=cut
-around write => sub {
- my $orig = shift;
+sub write {
my ( $self, $c, $buffer ) = @_;
# Prepend the headers if they have not yet been sent
$buffer = $headers . $buffer;
}
- return $self->$orig( $c, $buffer );
-};
+ return $self->next::method( $c, $buffer );
+}
=head2 $self->read_chunk($c, $buffer, $length)