From 1b05e3ca38fdb958cf9ced4d89e1478dc1e21257 Mon Sep 17 00:00:00 2001 From: David Baird Date: Sun, 30 Oct 2005 16:02:35 +0000 Subject: [PATCH] Added Maypole::Manual::Inheritance and Maypole::Manual::Terminology. Renamed Maypole::Manual::Request to Maypole::Manual::Cookbook. Minor updates elsewhere to reflect name changes and new docs. Started a docs roadmap section in Maypole.pm, needs more work. git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@402 48953598-375a-da11-a14b-00016c27c3ee --- lib/Maypole.pm | 27 +- lib/Maypole/Manual.pod | 11 +- lib/Maypole/Manual/About.pod | 42 - .../Manual/{Request.pod => Cookbook.pod} | 1679 ++++++++--------- lib/Maypole/Manual/Inheritance.pod | 264 +++ lib/Maypole/Manual/Install.pod | 47 + lib/Maypole/Manual/Plugins.pod | 155 +- lib/Maypole/Manual/Terminology.pod | 173 ++ 8 files changed, 1448 insertions(+), 950 deletions(-) rename lib/Maypole/Manual/{Request.pod => Cookbook.pod} (97%) create mode 100644 lib/Maypole/Manual/Inheritance.pod create mode 100644 lib/Maypole/Manual/Install.pod create mode 100644 lib/Maypole/Manual/Terminology.pod diff --git a/lib/Maypole.pm b/lib/Maypole.pm index cae420f..53732c4 100644 --- a/lib/Maypole.pm +++ b/lib/Maypole.pm @@ -488,16 +488,39 @@ Maypole is a Perl web application framework similar to Java's struts. It is essentially completely abstracted, and so doesn't know anything about how to talk to the outside world. -To use it, you need to create a package which represents your entire +To use it, you need to create a driver package which represents your entire application. In our example above, this is the C package. This needs to first use L which will make your package inherit from the appropriate platform driver such as C or -C, and then call setup. This sets up the model classes and +C. Then, the driver calls C. This sets up the model classes and configures your application. The default model class for Maypole uses L to map a database to classes, but this can be changed by altering configuration. (B calling setup.) + +=head1 DOCUMENTATION ROADMAP + +The primary documentation is the Maypole manual. This lives in the +C pod documents included with the distribution. + + +=head1 DEMOS + +A couple of demos are available, usually with source code and configs. + +=over4 + +=item beerdb.riverside-cms.co.uk + +Looks to be down at the moment. + +=item beerfb.riverside-cms.co.uk + +A demo of L. This site is running on the set of Mason +templates included in the L distribution. See the +synopsis of L for an example driver + =head2 CLASS METHODS =head3 config diff --git a/lib/Maypole/Manual.pod b/lib/Maypole/Manual.pod index dc60222..d556ae9 100644 --- a/lib/Maypole/Manual.pod +++ b/lib/Maypole/Manual.pod @@ -71,6 +71,15 @@ This document also introduces the theory behind Maypole's actions and templates, showing you how to write your own so that you can have a highly customized application. +=item L - writing Maypole plugins + +Useful information for plugin authors. + +=item L - pinning down usage + +As well as defining common terms used in Maypole discussions, this document +briefly discusses the MVC-ness of Maypole. + =item L - Description of the Request Workflow This is a technical document that describes the progress of a @@ -83,7 +92,7 @@ and not to most of those who are using it. This document gives a close look at the Beer database that was introduced in L. -=item L - The Request Cookbook +=item L - The Maypole Cookbook This extensive document is Maypole's main "How do I do X?" FAQ. It provides a wide variety of cookbook-like techniques that diff --git a/lib/Maypole/Manual/About.pod b/lib/Maypole/Manual/About.pod index d78be34..6f48663 100644 --- a/lib/Maypole/Manual/About.pod +++ b/lib/Maypole/Manual/About.pod @@ -74,48 +74,6 @@ logic of your application. This is one of the reasons why Maypole lets you develop so rapidly: because most of the time, you don't need to do any development at all. -=head2 Installing Maypole - -The first thing you're going to need to do to get Maypole running is to -install it. Maypole needs an absolute shedload of Perl modules from CPAN -to do its job. I am unrepentant about this. Maypole does a lot of work, -so that you don't have to. This is called code re-use, and if we're -serious about code re-use, then Maypole should be re-using as much code -as possible in terms of Perl modules. In another sense, this gives the -impression that Maypole doesn't actually do all that much itself, -because all it's doing is gluing together already-existing code. Well, -welcome to code re-use. - -The downside of code re-use is, of course, that you then have to install -a shedload of Perl modules from CPAN. If you're using OpenBSD or -FreeBSD, the wonderful ports system will be your friend. There's a -Maypole port in C. Just type C. - -Debian users, hang in there. There's a package coming. - -For other Unices, the L or C modules will help with -this. If you don't have C installed, my recommendation is to -use C to install it and then throw -C away. In any case, one of these two should get all that -Maypole needs: - - % perl -MCPANPLUS -e 'install Maypole' - % perl -MCPAN -e 'install Maypole' - -I don't know if Maypole works on Windows. I'm not sure I care. - -You're also going to need a database server and a web server. For -databases, I recommend SQLite (if you install the C module, -you get the SQLite library for free) for prototyping and mysql for -production; heavier duty users should use Postgresql or Oracle - Maypole -should be happy with them all. Maypole is happiest when running under -Apache C, with the C module installed, but as -I said, it is a blank slate, and everything is customizable. There is a -C frontend available to run as a standalone CGI script. - -As well as the documentation embedded in the Perl modules the distribution -also includes the manual, of which this is a part. You can access it using the -perldoc command, the man command, or by browsing CPAN. =head2 The Beer Database example diff --git a/lib/Maypole/Manual/Request.pod b/lib/Maypole/Manual/Cookbook.pod similarity index 97% rename from lib/Maypole/Manual/Request.pod rename to lib/Maypole/Manual/Cookbook.pod index 64ee38b..1d2395c 100644 --- a/lib/Maypole/Manual/Request.pod +++ b/lib/Maypole/Manual/Cookbook.pod @@ -1,840 +1,839 @@ -=head1 NAME - -Maypole::Manual::Request - Maypole Request Hacking Cookbook - -=head1 DESCRIPTION - -Hacks; design patterns; recipes: call it what you like, this chapter is a -developing collection of techniques which can be slotted in to Maypole -applications to solve common problems or make the development process easier. - -As Maypole developers, we don't necessarily know the "best practice" for -developing Maypole applications ourselves, in the same way that Larry Wall -didn't know all about the best Perl programming style as soon as he wrote -Perl. These techniques are what we're using at the moment, but they may -be refined, modularized, or rendered irrelevant over time. But they've -certainly saved us a bunch of hours work. - -=head2 Frontend hacks - -These hacks deal with changing the way Maypole relates to the outside world; -alternate front-ends to the Apache and CGI interfaces, or subclassing chunks -of the front-end modules to alter Maypole's behaviour in particular ways. - -=head3 Separate model class modules - -You want to put all the C routines in a separate module, -so you say: - - package BeerDB::Beer; - BeerDB::Beer->has_a(brewery => "BeerDB::Brewery"); - sub foo :Exported {} - -And in F, you put: - - use BeerDB::Beer; - -It doesn't work. - -B: It doesn't work because of the timing of the module loading. -C will try to set up the C relationships -at compile time, when the database tables haven't even been set up, -since they're set up by - - BeerDB->setup("...") - -which does its stuff at runtime. There are two ways around this; you can -either move the C call to compile time, like so: - - BEGIN { BeerDB->setup("...") } - -or move the module loading to run-time (my preferred solution): - - BeerDB->setup("..."); - BeerDB::Beer->require; - -=head3 Redirecting to SSL for sensitive information - -You have a website with forms that people will be entering sensitive information into, -such as credit cards or login details. You want to make sure that they aren't sent -in plain text but over SSL instead. - -B - -The solution is a bit tricky for 2 reasons : - -Firstly -- Many browsers and web clients will change a redirected -POST request into a GET request (which displays all that sensitive information in the -browser, or access logs and possibly elsewhere) and/or drops the values on the floor. - -Secondly -- If somebody has sent that sensitive information in plain text already, then -sending it again over SSL won't solve the problem. - -Redirecting a request is actually rather simple : - -$r->redirect_request('https://www.example.com/path'); # perldoc Maypole for API - -.. as is checking the protocol : - -$r->get_protocol(); # returns 'http' or 'https' - -You should check that the action that generates the form that people will enter -the sensitive information into is https and redirect if not. - -You should also check that no information is lost when redirecting, possibly by -storing it in a session and retrieving it later - see Maypole::Plugin::Session - -=head3 Debugging with the command line - -You're seeing bizarre problems with Maypole output, and you want to test it in -some place outside of the whole Apache/mod_perl/HTTP/Internet/browser circus. - -B: Use the L module to go directly from a URL to -standard output, bypassing Apache and the network altogether. - -L is not a standalone front-end, but to allow you to debug your -applications without having to change the front-end they use, it temporarily -"borgs" an application. If you run it from the command line, you're expected -to use it like so: - - perl -MMaypole::CLI=Application -e1 'http://your.server/path/table/action' - -For example: - - perl -MMaypole::CLI=BeerDB -e1 'http://localhost/beerdb/beer/view/1?o2=desc' - -You can also use the C module programatically to create -test suites for your application. See the Maypole tests themselves or -the documentation to C for examples of this. - -Don't forget also to turn on debugging output in your application: - - package BeerDB; - use strict; - use warnings; - use Maypole::Application qw(-Debug); - -=head3 Changing how URLs are parsed - -You don't like the way Maypole URLs look, and want something that either -fits in with the rest of your site or hides the internal workings of the -system. - -B: So far we've been using the C form -of a URL as though it was "the Maypole way"; well, there is no Maypole -way. Maypole is just a framework and absolutely everything about it is -overridable. - -If we want to provide our own URL handling, the method to override in -the driver class is C. This is responsible for taking -C<$r-Epath> and filling the C, C and C slots -of the request object. Normally it does this just by splitting the path -on 'C' characters, but you can do it any way you want, including -getting the information from C form parameters or session variables. - -For instance, suppose we want our URLs to be of the form -C, we could provide a C method -like so: - - sub parse_path { - my $r = shift; - $r->path("ProductList.html") unless $r->path; - ($r->path =~ /^(.*?)([A-Z]\w+)\.html/); - $r->table(lc $1); - $r->action(lc $2); - my %query = $r->ar->args; - $self->args([ $query{id} ]); - } - -This takes the path, which already has the query parameters stripped off -and parsed, and finds the table and action portions of the filename, -lower-cases them, and then grabs the C from the query. Later methods -will confirm whether or not these tables and actions exist. - -See the L for another -example of custom URL processing. - -=head3 Maypole for mobile devices - -You want Maypole to use different templates to display on particular -browsers. - -B: There are several ways to do this, but here's the neatest -we've found. Maypole chooses where to get its templates either by -looking at the C config parameter or, if this is not -given, calling the C method to ask the front-end to -try to work it out. We can give the front-end a little bit of help, by -putting this method in our driver class: - - sub get_template_root { - my $r = shift; - my $browser = $r->headers_in->get('User-Agent'); - if ($browser =~ /mobile|palm|nokia/i) { - "/home/myapp/templates/mobile"; - } else { - "/home/myapp/templates/desktop"; - } - } - -(Maybe there's a better way to detect a mobile browser, but you get the -idea.) - -=head2 Content display hacks - -These hacks deal primarily with the presentation of data to the user, -modifying the F template or changing the way that the results of -particular actions are displayed. - -=head3 Null Action - -You need an "action" which doesn't really do anything, but just formats -up a template. - -B: There are two ways to do this, depending on what precisely -you need. If you just need to display a template, C -style, with no Maypole objects in it, then you don't need to write any -code; just create your template, and it will be available in the usual -way. - -If, on the other hand, you want to display some data, and what you're -essentially doing is a variant of the C action, then you need to -ensure that you have an exported action, as described in the -L and C"> -chapter: - - sub my_view :Exported { } - -=head3 Template Switcheroo - -An action doesn't have any data of its own to display, but needs to display -B. - -B: This is an B common hack. You've just issued an -action like C, which updates the database. You don't want -to display a page that says "Record updated" or similar. Lesser -application servers would issue a redirect to have the browser request -C> instead, but we can actually modify the Maypole -request on the fly and, after doing the update, pretend that we were -going to C> all along. We do this by setting the -objects in the C slot and changing the C