10 shift->{ar} = Apache::Request->new(Apache->request);
15 $self->{path} = $self->{ar}->uri;
16 my $loc = $self->{ar}->location;
17 no warnings 'uninitialized';
18 $self->{path} =~ s/^$loc?\///;
19 $self->{path} ||= "frontpage";
20 my @pi = split /\//, $self->{path};
21 shift @pi while @pi and !$pi[0];
22 $self->{table} = shift @pi;
23 $self->{action} = shift @pi;
26 $self->{params} = { $self->{ar}->content };
27 $self->{query} = { $self->{ar}->args };
34 Apache::MVC - Apache front-end to Maypole
39 use base 'Apache::MVC';
40 BeerDB->setup("dbi:mysql:beerdb");
41 BeerDB->config->{uri_base} = "http://your.site/";
42 BeerDB->config->{display_tables} = [qw[beer brewery pub style]];
43 # Now set up your database:
51 Maypole is a Perl web application framework to Java's struts. It is
52 essentially completely abstracted, and so doesn't know anything about
53 how to talk to the outside world. C<Apache::MVC> is a mod_perl based
56 To use it, you need to create a package which represents your entire
57 application. In our example above, this is the C<BeerDB> package.
59 This needs to first inherit from C<Apache::MVC>, and then call setup.
60 This will give your package an Apache-compatible C<handler> subroutine,
61 and then pass any parameters onto the C<setup_database> method of the
62 model class. The default model class for Maypole uses L<Class::DBI> to
63 map a database to classes, but this can be changed by messing with the
64 configuration. (B<Before> calling setup.)
66 Next, you should configure your application through the C<config>
67 method. Configuration parameters at present are:
73 You B<must> specify this; it is the base URI of the application, which
74 will be used to construct links.
78 If you do not want all of the tables in the database to be accessible,
79 then set this to a list of only the ones you want to display
83 List output is paged if you set this to a positive number of rows.
87 You should also set up relationships between your classes, such that,
88 for instance, calling C<brewery> on a C<BeerDB::Beer> object returns an
89 object representing its associated brewery.
91 For a full example, see the included "beer database" application.
95 Create a driver module like the one above.
97 Put the following in your Apache config:
100 SetHandler perl-script
104 Copy the templates found in F<templates/factory> into the
105 F<beer/factory> directory off the web root. When the designers get
106 back to you with custom templates, they are to go in
107 F<beer/custom>. If you need to do override templates on a
108 database-table-by-table basis, put the new template in
111 This will automatically give you C<add>, C<edit>, C<list>, C<view> and
112 C<delete> commands; for instance, a list of breweries, go to
114 http://your.site/beer/brewery/list
116 For more information about how the system works and how to extend it,
121 Simon Cozens, C<simon@cpan.org>
125 You may distribute this code under the same terms as Perl itself.