11 use constant APACHE2 => $mod_perl::VERSION >= 1.99;
15 require Apache::RequestIO;
16 require Apache::RequestRec;
17 require Apache::RequestUtil;
20 else { require Apache }
21 require Apache::Request;
24 my ( $self, $r ) = @_;
25 $self->{ar} = Apache::Request->new($r);
30 $self->{path} = $self->{ar}->uri;
31 my $loc = $self->{ar}->location;
32 no warnings 'uninitialized';
33 $self->{path} .= '/' if $self->{path} eq $loc;
34 $self->{path} =~ s/^($loc)?\///;
41 $self->{params} = { $self->_mod_perl_args( $self->{ar} ) };
42 $self->{query} = { $self->_mod_perl_args( $self->{ar} ) };
47 $r->{ar}->content_type(
48 $r->{content_type} =~ m/^text/
49 ? $r->{content_type} . "; charset=" . $r->{document_encoding}
52 $r->{ar}->headers_out->set(
53 "Content-Length" => do { use bytes; length $r->{output} }
55 APACHE2 || $r->{ar}->send_http_header;
56 $r->{ar}->print( $r->{output} );
59 sub get_template_root {
61 $r->{ar}->document_root . "/" . $r->{ar}->location;
65 my ( $self, $apr ) = @_;
67 foreach my $key ( $apr->param ) {
68 my @values = $apr->param($key);
69 $args{$key} = @values == 1 ? $values[0] : \@values;
78 Apache::MVC - Apache front-end to Maypole
83 use base 'Apache::MVC';
84 BeerDB->setup("dbi:mysql:beerdb");
85 BeerDB->config->uri_base("http://your.site/");
86 BeerDB->config->display_tables([qw[beer brewery pub style]]);
87 # Now set up your database:
95 Maypole is a Perl web application framework to Java's struts. It is
96 essentially completely abstracted, and so doesn't know anything about
97 how to talk to the outside world. C<Apache::MVC> is a mod_perl based
100 To use it, you need to create a package which represents your entire
101 application. In our example above, this is the C<BeerDB> package.
103 This needs to first inherit from C<Apache::MVC>, and then call setup.
104 This will give your package an Apache-compatible C<handler> subroutine,
105 and then pass any parameters onto the C<setup_database> method of the
106 model class. The default model class for Maypole uses L<Class::DBI> to
107 map a database to classes, but this can be changed by messing with the
108 configuration. (B<Before> calling setup.)
110 Next, you should configure your application through the C<config>
111 method. Configuration parameters at present are:
117 You B<must> specify this; it is the base URI of the application, which
118 will be used to construct links.
122 If you do not want all of the tables in the database to be accessible,
123 then set this to a list of only the ones you want to display
127 List output is paged if you set this to a positive number of rows.
131 You should also set up relationships between your classes, such that,
132 for instance, calling C<brewery> on a C<BeerDB::Beer> object returns an
133 object representing its associated brewery.
135 For a full example, see the included "beer database" application.
139 Create a driver module like the one above.
141 Put the following in your Apache config:
144 SetHandler perl-script
148 Copy the templates found in F<templates/factory> into the
149 F<beer/factory> directory off the web root. When the designers get
150 back to you with custom templates, they are to go in
151 F<beer/custom>. If you need to do override templates on a
152 database-table-by-table basis, put the new template in
155 This will automatically give you C<add>, C<edit>, C<list>, C<view> and
156 C<delete> commands; for instance, a list of breweries, go to
158 http://your.site/beer/brewery/list
160 For more information about how the system works and how to extend it,
163 =head1 Implementation
165 This class overrides a set of methods in the base Maypole class to provide it's
166 functionality. See L<Maypole> for these:
172 =item get_template_root
184 Simon Cozens, C<simon@cpan.org>
185 Marcus Ramberg, C<marcus@thefeed.no>
186 Screwed up by Sebastian Riedel, C<sri@oook.de>
190 You may distribute this code under the same terms as Perl itself.