8 use Maypole::Constants;
10 our $VERSION = '2.10';
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.
60 return $self->handler;
65 This class overrides a set of methods in the base Maypole class to provide it's
66 functionality. See L<Maypole> for these:
76 shift->cgi( CGI::Simple->new );
88 # Reconstruct the request headers (as far as this is possible)
89 $r->headers_in(Maypole::Headers->new);
90 for my $http_header ($cgi->http) {
91 (my $field_name = $http_header) =~ s/^HTTPS?_//;
92 $r->headers_in->set($field_name => $cgi->http($http_header));
95 my $path = $cgi->url( -absolute => 1, -path_info => 1 );
96 my $loc = $cgi->url( -absolute => 1 );
98 no warnings 'uninitialized';
99 $path .= '/' if $path eq $loc;
100 $path =~ s/^($loc)?\///;
115 my (%vars) = $r->cgi->Vars;
116 while ( my ( $key, $value ) = each %vars ) {
117 my @values = split "\0", $value;
118 $vars{$key} = @values <= 1 ? $values[0] : \@values;
120 $r->params( {%vars} );
121 $r->query( $r->params );
124 =item redirect_request
128 # FIXME: use headers_in to gather host and other information?
132 my $redirect_url = $_[0];
137 $redirect_url = $args{url};
139 my $path = $args{path} || $r->cgi->url(-absolute => 1, -query=>1);
140 my $host = $args{domain};
141 ($host = $r->cgi->url(-base => 1)) =~ s/^https?:\/\///i unless ($host);
142 my $protocol = $args{protocol} || $r->get_protocol;
143 $redirect_url = "${protocol}://${host}/${path}";
145 $status = $args{status} if ($args{status});
148 $r->headers_out->set('Status' => $status);
149 $r->headers_out->set('Location' => $redirect_url);
161 my $protocol = ($self->cgi->https) ? 'https' : 'http';
173 # Collect HTTP headers
175 -type => $r->content_type,
176 -charset => $r->document_encoding,
177 -content_length => do { use bytes; length $r->output },
179 foreach ($r->headers_out->field_names) {
180 next if /^Content-(Type|Length)/;
181 $headers{"-$_"} = $r->headers_out->get($_);
184 print $r->cgi->header(%headers), $r->output;
187 =item get_template_root
191 sub get_template_root {
193 $r->cgi->document_root . "/" . $r->cgi->url( -relative => 1 );
207 Dave Ranney C<dave@sialia.com>
209 Simon Cozens C<simon@cpan.org>