13 eval 'use mod_perl2; $version = $mod_perl2::VERSION; ';
15 warn "no mod_perl 2.x using mod_perl 1.x\n";
19 require Apache::Request;
21 require Apache2::RequestIO;
22 require Apache2::RequestRec;
23 require Apache2::RequestUtil;
25 require Apache2::Request;
28 use constant APACHE2 => $version;
33 my ( $self, $r ) = @_;
34 $self->{ar} = (APACHE2) ? Apache2::Request->new($r) : Apache::Request->new($r);
40 # Reconstruct the request headers
41 $self->headers_in(Maypole::Headers->new);
43 if (APACHE2) { %headers = %{$self->{ar}->headers_in};
44 } else { %headers = $self->{ar}->headers_in; }
46 $self->headers_in->set($_, $headers{$_});
49 $self->{path} = $self->{ar}->uri;
50 my $loc = $self->{ar}->location;
51 no warnings 'uninitialized';
52 $self->{path} .= '/' if $self->{path} eq $loc;
53 $self->{path} =~ s/^($loc)?\///;
60 $self->{params} = { $self->_mod_perl_args( $self->{ar} ) };
61 $self->{query} = { $self->_mod_perl_args( $self->{ar} ) };
66 $r->{ar}->content_type(
67 $r->{content_type} =~ m/^text/
68 ? $r->{content_type} . "; charset=" . $r->{document_encoding}
71 $r->{ar}->headers_out->set(
72 "Content-Length" => do { use bytes; length $r->{output} }
75 foreach ($r->headers_out->field_names) {
76 next if /^Content-(Type|Length)/;
77 $r->{ar}->headers_out->set($_ => $r->headers_out->get($_));
80 APACHE2 || $r->{ar}->send_http_header;
81 $r->{ar}->print( $r->{output} );
84 sub get_template_root {
86 $r->{ar}->document_root . "/" . $r->{ar}->location;
90 my ( $self, $apr ) = @_;
92 foreach my $key ( $apr->param ) {
93 my @values = $apr->param($key);
94 $args{$key} = @values == 1 ? $values[0] : \@values;
103 Apache::MVC - Apache front-end to Maypole
108 use base 'Apache::MVC';
109 BeerDB->setup("dbi:mysql:beerdb");
110 BeerDB->config->uri_base("http://your.site/");
111 BeerDB->config->display_tables([qw[beer brewery pub style]]);
112 # Now set up your database:
113 # has-a relationships
120 A mod_perl platform driver for Maypole. Your application can inherit from
121 Apache::MVC directly, but it is recommended that you use
122 L<Maypole::Application>.
126 Create a driver module like the one above.
128 Put the following in your Apache config:
131 SetHandler perl-script
135 Copy the templates found in F<templates/factory> into the
136 F<beer/factory> directory off the web root. When the designers get
137 back to you with custom templates, they are to go in
138 F<beer/custom>. If you need to do override templates on a
139 database-table-by-table basis, put the new template in
142 This will automatically give you C<add>, C<edit>, C<list>, C<view> and
143 C<delete> commands; for instance, a list of breweries, go to
145 http://your.site/beer/brewery/list
147 For more information about how the system works and how to extend it,
150 =head1 Implementation
152 This class overrides a set of methods in the base Maypole class to provide it's
153 functionality. See L<Maypole> for these:
159 =item get_template_root
171 Simon Cozens, C<simon@cpan.org>
172 Marcus Ramberg, C<marcus@thefeed.no>
173 Screwed up by Sebastian Riedel, C<sri@oook.de>
177 You may distribute this code under the same terms as Perl itself.