11 __PACKAGE__->mk_accessors( qw( ar ) );
15 eval 'use mod_perl2; $version = $mod_perl2::VERSION; ';
17 warn "no mod_perl 2.x using mod_perl 1.x\n";
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 my ( $self, $r ) = @_;
36 $self->{ar} = (APACHE2) ? Apache2::Request->new($r) : Apache::Request->new($r);
42 # Reconstruct the request headers
43 $self->headers_in(Maypole::Headers->new);
45 if (APACHE2) { %headers = %{$self->{ar}->headers_in};
46 } else { %headers = $self->{ar}->headers_in; }
48 $self->headers_in->set($_, $headers{$_});
51 $self->{path} = $self->{ar}->uri;
52 my $loc = $self->{ar}->location;
53 no warnings 'uninitialized';
54 $self->{path} .= '/' if $self->{path} eq $loc;
55 $self->{path} =~ s/^($loc)?\///;
62 $self->{params} = { $self->_mod_perl_args( $self->{ar} ) };
63 $self->{query} = { $self->_mod_perl_args( $self->{ar} ) };
68 $r->{ar}->content_type(
69 $r->{content_type} =~ m/^text/
70 ? $r->{content_type} . "; charset=" . $r->{document_encoding}
73 $r->{ar}->headers_out->set(
74 "Content-Length" => do { use bytes; length $r->{output} }
77 foreach ($r->headers_out->field_names) {
78 next if /^Content-(Type|Length)/;
79 $r->{ar}->headers_out->set($_ => $r->headers_out->get($_));
82 APACHE2 || $r->{ar}->send_http_header;
83 $r->{ar}->print( $r->{output} );
86 sub get_template_root {
88 $r->{ar}->document_root . "/" . $r->{ar}->location;
92 my ( $self, $apr ) = @_;
94 foreach my $key ( $apr->param ) {
95 my @values = $apr->param($key);
96 $args{$key} = @values == 1 ? $values[0] : \@values;
105 Apache::MVC - Apache front-end to Maypole
110 use base 'Apache::MVC';
111 BeerDB->setup("dbi:mysql:beerdb");
112 BeerDB->config->uri_base("http://your.site/");
113 BeerDB->config->display_tables([qw[beer brewery pub style]]);
114 # Now set up your database:
115 # has-a relationships
122 A mod_perl platform driver for Maypole. Your application can inherit from
123 Apache::MVC directly, but it is recommended that you use
124 L<Maypole::Application>.
128 Create a driver module like the one above.
130 Put the following in your Apache config:
133 SetHandler perl-script
137 Copy the templates found in F<templates/factory> into the
138 F<beer/factory> directory off the web root. When the designers get
139 back to you with custom templates, they are to go in
140 F<beer/custom>. If you need to do override templates on a
141 database-table-by-table basis, put the new template in
144 This will automatically give you C<add>, C<edit>, C<list>, C<view> and
145 C<delete> commands; for instance, a list of breweries, go to
147 http://your.site/beer/brewery/list
149 For more information about how the system works and how to extend it,
152 =head1 Implementation
154 This class overrides a set of methods in the base Maypole class to provide it's
155 functionality. See L<Maypole> for these:
161 =item get_template_root
173 Simon Cozens, C<simon@cpan.org>
174 Marcus Ramberg, C<marcus@thefeed.no>
175 Screwed up by Sebastian Riedel, C<sri@oook.de>
179 You may distribute this code under the same terms as Perl itself.