8 use Maypole::Constants;
10 our $VERSION = '2.13';
12 __PACKAGE__->mk_accessors( qw/cgi/ );
16 CGI::Maypole - CGI-based front-end to Maypole
21 use Maypole::Application;
30 Now to access the beer database, type this URL into your browser:
31 http://your.site/cgi-bin/beer.cgi/frontpage
33 NOTE: this Maypole frontend requires additional modules that won't be installed
34 or included with Maypole. Please see below.
38 This is a CGI platform driver for Maypole. Your application can inherit from
39 CGI::Maypole directly, but it is recommended that you use
40 L<Maypole::Application>.
42 This module requires CGI::Simple which you will have to install yourself via
51 Call this from your CGI script to start the Maypole application.
59 my $status = $self->handler;
62 Status: 500 Maypole application error
63 Content-Type: text/html
65 <title>Maypole application error</h1>
66 <h1>Maypole application error</h1>
74 This class overrides a set of methods in the base Maypole class to provide it's
75 functionality. See L<Maypole> for these:
85 my $request_options = $self->config->request_options || {};
86 $CGI::Simple::POST_MAX = $request_options->{POST_MAX} if ($request_options->{POST_MAX});
87 $self->cgi( CGI::Simple->new );
99 # Reconstruct the request headers (as far as this is possible)
100 $r->headers_in(Maypole::Headers->new);
101 for my $http_header ($cgi->http) {
102 (my $field_name = $http_header) =~ s/^HTTPS?_//;
103 $r->headers_in->set($field_name => $cgi->http($http_header));
106 $r->preprocess_location();
108 my $path = $cgi->url( -absolute => 1, -path_info => 1 );
109 my $loc = $cgi->url( -absolute => 1 );
111 no warnings 'uninitialized';
112 $path .= '/' if $path eq $loc;
114 $path =~ s/^($loc)?//;
116 $path =~ s/^($loc)?\///;
130 my ($self,@args) = @_;
131 my ($package, $line) = (caller)[0,2];
132 warn "[$package line $line] ", @args ;
143 my (%vars) = $r->cgi->Vars;
144 while ( my ( $key, $value ) = each %vars ) {
145 my @values = split "\0", $value;
146 $vars{$key} = @values <= 1 ? $values[0] : \@values;
148 $r->params( {%vars} );
149 $r->query( $r->params );
152 =item redirect_request
156 # FIXME: use headers_in to gather host and other information?
160 my $redirect_url = $_[0];
165 $redirect_url = $args{url};
167 my $path = $args{path} || $r->cgi->url(-absolute => 1, -query=>1);
168 my $host = $args{domain};
169 ($host = $r->cgi->url(-base => 1)) =~ s/^https?:\/\///i unless ($host);
170 my $protocol = $args{protocol} || $r->get_protocol;
171 $redirect_url = "${protocol}://${host}/${path}";
173 $status = $args{status} if ($args{status});
176 $r->headers_out->set('Status' => $status);
177 $r->headers_out->set('Location' => $redirect_url);
189 my $protocol = ($self->cgi->https) ? 'https' : 'http';
195 Generates output (using C<collect_output>) and prints it.
202 print $r->collect_output;
207 Gathers headers and output together into a string and returns it.
209 Splitting this code out of C<send_output> supports L<Maypole::HTTPD::Frontend>.
217 # Collect HTTP headers
219 -type => $r->content_type,
220 -charset => $r->document_encoding,
221 -content_length => do { use bytes; length $r->output },
223 foreach ($r->headers_out->field_names) {
224 next if /^Content-(Type|Length)/;
225 $headers{"-$_"} = $r->headers_out->get($_);
228 return $r->cgi->header(%headers) . $r->output;
231 =item get_template_root
235 sub get_template_root {
237 $r->cgi->document_root . "/" . $r->cgi->url( -relative => 1 );
251 Dave Ranney C<dave@sialia.com>
253 Simon Cozens C<simon@cpan.org>