10 use Maypole::Constants;
12 __PACKAGE__->mk_accessors( qw( ar ) );
16 eval 'use mod_perl2; $version = $mod_perl2::VERSION; ';
21 require Apache::Request;
23 require Apache2::RequestIO;
24 require Apache2::RequestRec;
25 require Apache2::RequestUtil;
27 require Apache2::Request;
30 use constant APACHE2 => $version;
35 Apache::MVC - Apache front-end to Maypole
40 use Maypole::Application;
44 A mod_perl platform driver for Maypole. Your application can inherit from
45 Apache::MVC directly, but it is recommended that you use
46 L<Maypole::Application>.
50 Create a driver module like the one illustrated in L<Maypole::Application>.
52 Put the following in your Apache config:
55 SetHandler perl-script
59 Copy the templates found in F<templates/factory> into the F<beer/factory>
60 directory off the web root. When the designers get back to you with custom
61 templates, they are to go in F<beer/custom>. If you need to override templates
62 on a database-table-by-table basis, put the new template in F<beer/I<table>>.
64 This will automatically give you C<add>, C<edit>, C<list>, C<view> and C<delete>
65 commands; for instance, to see a list of breweries, go to
67 http://your.site/beer/brewery/list
69 For more information about how the system works and how to extend it,
74 This class overrides a set of methods in the base Maypole class to provide its
75 functionality. See L<Maypole> for these:
85 my $ar = (APACHE2) ? Apache2::Request->new($r) : Apache::Request->instance($r);
96 # Reconstruct the request headers
97 $self->headers_in(Maypole::Headers->new);
99 if (APACHE2) { %headers = %{$self->ar->headers_in};
100 } else { %headers = $self->ar->headers_in; }
101 for (keys %headers) {
102 $self->headers_in->set($_, $headers{$_});
104 my $path = $self->ar->uri;
105 my $loc = $self->ar->location;
107 no warnings 'uninitialized';
108 $path .= '/' if $path eq $loc;
109 $path =~ s/^($loc)?\///;
123 $self->params( { $self->_mod_perl_args( $self->ar ) } );
124 $self->query( $self->params );
127 =item redirect_request
131 # FIXME: use headers_in to gather host and other information?
135 my $redirect_url = $_[0];
140 $redirect_url = $args{url};
142 my $path = $args{path} || $r->path;
143 my $host = $args{domain} || $r->ar->hostname;
144 my $protocol = $args{protocol} || $r->get_protocol;
145 $redirect_url = "${protocol}://${host}/${path}";
147 $status = $args{status} if ($args{status});
150 $r->headers_out->set('Status' => $status);
151 $r->headers_out->set('Location' => $redirect_url);
161 my $protocol = ( $self->ar->protocol =~ m/https/i ) ? 'https' : 'http' ;
171 $r->ar->content_type(
172 $r->content_type =~ m/^text/
173 ? $r->content_type . "; charset=" . $r->document_encoding
176 $r->ar->headers_out->set(
177 "Content-Length" => do { use bytes; length $r->output }
180 foreach ($r->headers_out->field_names) {
181 next if /^Content-(Type|Length)/;
182 $r->ar->headers_out->set($_ => $r->headers_out->get($_));
185 APACHE2 || $r->ar->send_http_header;
186 $r->ar->print( $r->output );
189 =item get_template_root
193 sub get_template_root {
195 $r->ar->document_root . "/" . $r->ar->location;
199 my ( $self, $apr ) = @_;
201 foreach my $key ( $apr->param ) {
202 my @values = $apr->param($key);
203 $args{$key} = @values == 1 ? $values[0] : \@values;
214 Simon Cozens, C<simon@cpan.org>
215 Marcus Ramberg, C<marcus@thefeed.no>
216 Sebastian Riedel, C<sri@oook.de>
220 You may distribute this code under the same terms as Perl itself.