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