3 use base qw(Apache::MVC::Base Maypole);
5 use Apache::RequestRec;
6 use Apache::RequestUtil;
15 my ( $self, $r ) = @_;
16 $self->{ar} = Apache::Request->new($r);
21 $self->{params} = { $self->_mod_perl_args( $self->{ar} ) };
22 $self->{query} = { $self->_mod_perl_args( $self->{ar} ) };
26 my ( $self, $apr ) = @_;
28 foreach my $key ( $apr->param ) {
29 my @values = $apr->param($key);
30 $args{$key} = @values == 1 ? $values[0] : \@values;
39 Apache2::MVC - Apache2 front-end to Maypole
44 use base 'Apache::MVC';
45 BeerDB->setup("dbi:mysql:beerdb");
46 BeerDB->config->{uri_base} = "http://your.site/";
47 BeerDB->config->{display_tables} = [qw[beer brewery pub style]];
48 # Now set up your database:
56 Maypole is a Perl web application framework to Java's struts. It is
57 essentially completely abstracted, and so doesn't know anything about
58 how to talk to the outside world. C<Apache2::MVC> is a mod_perl2 based
61 To use it, you need to create a package which represents your entire
62 application. In our example above, this is the C<BeerDB> package.
64 This needs to first inherit from C<Apache2::MVC>, and then call setup.
65 This will give your package an Apache-compatible C<handler> subroutine,
66 and then pass any parameters onto the C<setup_database> method of the
67 model class. The default model class for Maypole uses L<Class::DBI> to
68 map a database to classes, but this can be changed by messing with the
69 configuration. (B<Before> calling setup.)
71 Next, you should configure your application through the C<config>
72 method. Configuration parameters at present are:
78 You B<must> specify this; it is the base URI of the application, which
79 will be used to construct links.
83 If you do not want all of the tables in the database to be accessible,
84 then set this to a list of only the ones you want to display
88 List output is paged if you set this to a positive number of rows.
92 You should also set up relationships between your classes, such that,
93 for instance, calling C<brewery> on a C<BeerDB::Beer> object returns an
94 object representing its associated brewery.
96 For a full example, see the included "beer database" application.
100 Create a driver module like the one above.
102 Put the following in your Apache config:
105 SetHandler perl-script
109 Copy the templates found in F<templates/factory> into the
110 F<beer/factory> directory off the web root. When the designers get
111 back to you with custom templates, they are to go in
112 F<beer/custom>. If you need to do override templates on a
113 database-table-by-table basis, put the new template in
116 This will automatically give you C<add>, C<edit>, C<list>, C<view> and
117 C<delete> commands; for instance, a list of breweries, go to
119 http://your.site/beer/brewery/list
121 For more information about how the system works and how to extend it,
126 Simon Cozens, C<simon@cpan.org>
127 Marcus Ramberg, C<marcus@thefeed.no>
128 Screwed up by Sebastian Riedel, C<sri@oook.de>
132 You may distribute this code under the same terms as Perl itself.