X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole%2FManual%2FRequest.pod;h=d3d66f299c66d6116d27c2ba1dba747b23226471;hb=628ecd5d9d294e601c79c7509140d02dcd7a1d40;hp=bc2b303555fedc51257a4e446fefc499def7aba8;hpb=616082000cbe7305fbfc84d33bb2f9d53cc86f3c;p=maypole.git diff --git a/lib/Maypole/Manual/Request.pod b/lib/Maypole/Manual/Request.pod index bc2b303..d3d66f2 100644 --- a/lib/Maypole/Manual/Request.pod +++ b/lib/Maypole/Manual/Request.pod @@ -32,8 +32,8 @@ And in F, you put: 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 +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 @@ -54,10 +54,10 @@ or move the module loading to run-time (my preferred solution): 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 +B: Use the L 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 +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: @@ -72,23 +72,30 @@ 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. -C: So far we've been using the C form +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-E{path}> and filling the C, C and C slots +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 Cs, but you can do it any way you want, including getting the -information from C form parameters or session variables. +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 @@ -96,13 +103,12 @@ like so: sub parse_path { my $r = shift; - $r->{path} ||= "ProductList.html"; - ($r->{table}, $r->{action}) = - ($r->{path} =~ /^(.*?)([A-Z]\w+)\.html/); - $r->{table} = lc $r->{table}; - $r->{action} = lc $r->{action}; - my %query = $r->{ar}->args; - $self->{args} = [ $query{id} ]; + $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 @@ -110,7 +116,8 @@ 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 L for another example of custom URL processing. +See the L for another +example of custom URL processing. =head3 Maypole for mobile devices @@ -126,7 +133,7 @@ putting this method in our driver class: sub get_template_root { my $r = shift; - my $browser = $r->{ar}->headers_in->get('User-Agent'); + my $browser = $r->headers_in->get('User-Agent'); if ($browser =~ /mobile|palm|nokia/i) { "/home/myapp/templates/mobile"; } else { @@ -140,7 +147,7 @@ idea.) =head2 Content display 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 +modifying the F template or changing the way that the results of particular actions are displayed. =head3 Null Action @@ -156,8 +163,9 @@ 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 -L: +ensure that you have an exported action, as described in the +L and C"> +chapter: sub my_view :Exported { } @@ -176,17 +184,17 @@ going to C> all along. We do this by setting the objects in the C slot and changing the C