9 use constant APACHE2 => $mod_perl::VERSION >= 1.99;
13 require Apache::RequestRec;
14 require Apache::RequestUtil;
17 else { require Apache }
18 require Apache::Request;
23 my ( $self, $r ) = @_;
24 $self->{ar} = Apache::Request->new($r);
29 $self->{path} = $self->{ar}->uri;
30 my $loc = $self->{ar}->location;
31 no warnings 'uninitialized';
32 $self->{path} =~ s/^($loc)?\///;
40 $self->{params} = { $self->_mod_perl_args( $self->{ar} ) };
41 $self->{query} = { $self->_mod_perl_args( $self->{ar} ) };
46 $r->{ar}->content_type(
47 $r->{content_type} . "; encoding=" . $r->{document_encoding} );
48 $r->{ar}->headers_out->set( "Content-Length" => length $r->{output} );
49 APACHE2 || $r->{ar}->send_http_header;
50 $r->{ar}->print( $r->{output} );
53 sub get_template_root {
55 $r->{ar}->document_root . "/" . $r->{ar}->location;
59 my ( $self, $apr ) = @_;
61 foreach my $key ( $apr->param ) {
62 my @values = $apr->param($key);
63 $args{$key} = @values == 1 ? $values[0] : \@values;
72 Apache::MVC - Apache front-end to Maypole
77 use base 'Apache::MVC';
78 BeerDB->setup("dbi:mysql:beerdb");
79 BeerDB->config->uri_base("http://your.site/");
80 BeerDB->config->display_tables([qw[beer brewery pub style]]);
81 # Now set up your database:
89 Maypole is a Perl web application framework to Java's struts. It is
90 essentially completely abstracted, and so doesn't know anything about
91 how to talk to the outside world. C<Apache::MVC> is a mod_perl based
94 To use it, you need to create a package which represents your entire
95 application. In our example above, this is the C<BeerDB> package.
97 This needs to first inherit from C<Apache::MVC>, and then call setup.
98 This will give your package an Apache-compatible C<handler> subroutine,
99 and then pass any parameters onto the C<setup_database> method of the
100 model class. The default model class for Maypole uses L<Class::DBI> to
101 map a database to classes, but this can be changed by messing with the
102 configuration. (B<Before> calling setup.)
104 Next, you should configure your application through the C<config>
105 method. Configuration parameters at present are:
111 You B<must> specify this; it is the base URI of the application, which
112 will be used to construct links.
116 If you do not want all of the tables in the database to be accessible,
117 then set this to a list of only the ones you want to display
121 List output is paged if you set this to a positive number of rows.
125 You should also set up relationships between your classes, such that,
126 for instance, calling C<brewery> on a C<BeerDB::Beer> object returns an
127 object representing its associated brewery.
129 For a full example, see the included "beer database" application.
133 Create a driver module like the one above.
135 Put the following in your Apache config:
138 SetHandler perl-script
142 Copy the templates found in F<templates/factory> into the
143 F<beer/factory> directory off the web root. When the designers get
144 back to you with custom templates, they are to go in
145 F<beer/custom>. If you need to do override templates on a
146 database-table-by-table basis, put the new template in
149 This will automatically give you C<add>, C<edit>, C<list>, C<view> and
150 C<delete> commands; for instance, a list of breweries, go to
152 http://your.site/beer/brewery/list
154 For more information about how the system works and how to extend it,
159 Simon Cozens, C<simon@cpan.org>
160 Marcus Ramberg, C<marcus@thefeed.no>
161 Screwed up by Sebastian Riedel, C<sri@oook.de>
165 You may distribute this code under the same terms as Perl itself.