X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=doc%2FRequest.pod;h=80e4037cd9bd216f3bf707880efa213327ff456f;hb=81302aff5cf7e25674ca3af7ba79c5b3fa5f4e20;hp=6af82784ba5263dc2e78a07a681251bf63e1bbd2;hpb=a1512e21084779f9b123d7d36c7dba2291a0fb5a;p=maypole.git diff --git a/doc/Request.pod b/doc/Request.pod index 6af8278..80e4037 100644 --- a/doc/Request.pod +++ b/doc/Request.pod @@ -1,43 +1,89 @@ =head1 Maypole Request Hacking Cookbook +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 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 C module to go directly from a URL to +standard output, bypassing Apache and the network altogether. + +C 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. + =head3 Changing how params are parsed =head3 REST -=head2 Authentication hacks +=head2 Content display hacks -=head2 Creating and editing hacks +These hacks deal primarily with the presentation of data to the user, +modifying the C template or changing the way that the results of +particular actions are displayed. -=head3 Getting data from external sources +=head3 Template Switcheroo -You want to supplement the data received from a form with additional -data from another source. +An action doesn't have any data of its own to display, but needs to display +B. -B: Munge the contents of C< $r-Eparams > before jumping -to the original C routine. For instance, in this method, -we use a C object to fill in some fields of a database row based -on an ISBN: +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