]> git.decadent.org.uk Git - maypole.git/blob - lib/Apache/MVC.pm
Apache2::MVC, Maypole::Application, parse_args() and much more...
[maypole.git] / lib / Apache / MVC.pm
1 package Apache::MVC;
2
3 use base qw(Apache::MVC::Base Maypole);
4 use Apache;
5 use Apache::Request;
6 use strict;
7 use warnings;
8
9 our $VERSION = "0.3";
10
11 sub get_request {
12     shift->{ar} = Apache::Request->new( Apache->request );
13 }
14
15 sub parse_args {
16     my $self = shift;
17     $self->{params} = { $self->{ar}->content };
18     while ( my ( $key, $value ) = each %{ $self->{params} } ) {
19         $self->{params}{$key} = '' unless defined $value;
20     }
21     $self->{query} = { $self->{ar}->args };
22 }
23
24 1;
25
26 =head1 NAME
27
28 Apache::MVC - Apache front-end to Maypole
29
30 =head1 SYNOPSIS
31
32     package BeerDB;
33     use base 'Apache::MVC';
34     BeerDB->setup("dbi:mysql:beerdb");
35     BeerDB->config->{uri_base} = "http://your.site/";
36     BeerDB->config->{display_tables} = [qw[beer brewery pub style]];
37     # Now set up your database:
38     # has-a relationships
39     # untaint columns
40
41     1;
42
43 =head1 DESCRIPTION
44
45 Maypole is a Perl web application framework to Java's struts. It is 
46 essentially completely abstracted, and so doesn't know anything about
47 how to talk to the outside world. C<Apache::MVC> is a mod_perl based
48 subclass of Maypole.
49
50 To use it, you need to create a package which represents your entire
51 application. In our example above, this is the C<BeerDB> package.
52
53 This needs to first inherit from C<Apache::MVC>, and then call setup.
54 This will give your package an Apache-compatible C<handler> subroutine,
55 and then pass any parameters onto the C<setup_database> method of the
56 model class. The default model class for Maypole uses L<Class::DBI> to 
57 map a database to classes, but this can be changed by messing with the
58 configuration. (B<Before> calling setup.)
59
60 Next, you should configure your application through the C<config>
61 method. Configuration parameters at present are:
62
63 =over
64
65 =item uri_base
66
67 You B<must> specify this; it is the base URI of the application, which
68 will be used to construct links.
69
70 =item display_tables
71
72 If you do not want all of the tables in the database to be accessible,
73 then set this to a list of only the ones you want to display
74
75 =item rows_per_page
76
77 List output is paged if you set this to a positive number of rows.
78
79 =back
80
81 You should also set up relationships between your classes, such that,
82 for instance, calling C<brewery> on a C<BeerDB::Beer> object returns an
83 object representing its associated brewery.
84
85 For a full example, see the included "beer database" application.
86
87 =head1 INSTALLATION
88
89 Create a driver module like the one above.
90
91 Put the following in your Apache config:
92
93     <Location /beer>
94         SetHandler perl-script
95         PerlHandler BeerDB
96     </Location>
97
98 Copy the templates found in F<templates/factory> into the
99 F<beer/factory> directory off the web root. When the designers get
100 back to you with custom templates, they are to go in
101 F<beer/custom>. If you need to do override templates on a
102 database-table-by-table basis, put the new template in
103 F<beer/I<table>>. 
104
105 This will automatically give you C<add>, C<edit>, C<list>, C<view> and
106 C<delete> commands; for instance, a list of breweries, go to 
107
108     http://your.site/beer/brewery/list
109
110 For more information about how the system works and how to extend it,
111 see L<Maypole>.
112
113 =head1 AUTHOR
114
115 Simon Cozens, C<simon@cpan.org>
116 Screwed up by Sebastian Riedel, C<sri@oook.de>
117
118 =head1 LICENSE
119
120 You may distribute this code under the same terms as Perl itself.