8 use Maypole::Constants;
10 our $VERSION = '2.10';
14 return $self->handler();
18 shift->{cgi} = CGI::Simple->new();
23 my $protocol = ($self->{cgi}->https()) ? 'https' : 'http';
29 my $cgi = $self->{cgi};
31 # Reconstruct the request headers (as far as this is possible)
32 $self->headers_in(Maypole::Headers->new);
33 for my $http_header ($cgi->http) {
34 (my $field_name = $http_header) =~ s/^HTTPS?_//;
35 $self->headers_in->set($field_name => $cgi->http($http_header));
38 $self->{path} = $cgi->url( -absolute => 1, -path_info => 1 );
39 my $loc = $cgi->url( -absolute => 1 );
40 no warnings 'uninitialized';
41 $self->{path} .= '/' if $self->{path} eq $loc;
42 $self->{path} =~ s/^($loc)?\///;
49 my (%vars) = $self->{cgi}->Vars;
50 while ( my ( $key, $value ) = each %vars ) {
51 my @values = split "\0", $value;
52 $vars{$key} = @values <= 1 ? $values[0] : \@values;
54 $self->{params} = {%vars};
55 $self->{query} = {%vars};
58 # FIXME: use headers_in to gather host and other information?
59 sub redirect_request {
61 my $redirect_url = $_[0];
66 $redirect_url = $args{url};
68 my $path = $args{path} || $self->{cgi}->url(-absolute => 1, -query=>1);
69 my $host = $args{domain};
70 ($host = $self->{cgi}->url(-base => 1)) =~ s/^https?:\/\///i unless ($host);
71 my $protocol = $args{protocol} || ($self->{cgi}->https()) ? 'https' : 'http';
72 $redirect_url = "${protocol}://${host}/${path}";
74 $status = $args{status} if ($args{status});
77 $self->headers_out->set('Status' => $status);
78 $self->headers_out->set('Location' => $redirect_url);
87 # Collect HTTP headers
89 -type => $r->{content_type},
90 -charset => $r->{document_encoding},
91 -content_length => do { use bytes; length $r->{output} },
93 foreach ($r->headers_out->field_names) {
94 next if /^Content-(Type|Length)/;
95 $headers{"-$_"} = $r->headers_out->get($_);
98 print $r->{cgi}->header(%headers), $r->{output};
101 sub get_template_root {
103 $r->{cgi}->document_root . "/" . $r->{cgi}->url( -relative => 1 );
110 CGI::Maypole - CGI-based front-end to Maypole
115 use base 'CGI::Maypole';
116 BeerDB->setup("dbi:mysql:beerdb");
117 BeerDB->config->uri_base("http://your.site/cgi-bin/beer.cgi/");
118 BeerDB->config->display_tables([qw[beer brewery pub style]]);
119 BeerDB->config->template_root("/var/www/beerdb/");
120 # Now set up your database:
121 # has-a relationships
133 Now to access the beer database, type this URL into your browser:
134 http://your.site/cgi-bin/beer.cgi/frontpage
136 NOTE: this Maypole frontend requires additional modules that won't be installed or included with Maypole. Please see below.
140 This is a CGI platform driver for Maypole. Your application can inherit from
141 CGI::Maypole directly, but it is recommended that you use
142 L<Maypole::Application>.
144 This module requires CGI::Simple which you will have to install yourself via CPAN or manually.
152 Call this from your CGI script to start the Maypole application.
156 =head1 Implementation
158 This class overrides a set of methods in the base Maypole class to provide it's
159 functionality. See L<Maypole> for these:
165 =item get_template_root
175 =item redirect_request
186 Dave Ranney C<dave@sialia.com>
188 Simon Cozens C<simon@cpan.org>