X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=doc%2FBeer.pod;h=033d9ce1acb8e10dc9f2d52a49c257b71757bc7b;hb=8237e83ed726d86f1ef754e51077eb2aff0cd4ed;hp=4c4093fa3c31e93f0e367672a63e4f3754c08e7e;hpb=2c2a72adcc01c1260b410103fa6bab06623f04be;p=maypole.git diff --git a/doc/Beer.pod b/doc/Beer.pod index 4c4093f..033d9ce 100644 --- a/doc/Beer.pod +++ b/doc/Beer.pod @@ -181,7 +181,50 @@ Maypole's default templates will use this information to display, for instance, a list of a brewery's beers on the brewery view page. This is the complete beer database application; Maypole's default templates -and the actions in the view class do the rest. But what if we want to a +and the actions in the view class do the rest. But what if we want to do a little more. How would we begin to extend this application? =head2 The hard way + +Maypole was written because I don't like writing more Perl code than is +necessary. I also don't like writing HTML. In fact, I don't really get +on this whole computer thing, to be honest. But we'll start by ways that +we can customize the beer application simply by adding methods or +changing properties of the Perl driver code. + +The first thing we ought to look into is the names of the columns; most +of them are fine, but that "Abv" column stands out. I'd rather that was +"A.B.V.". Maypole uses the C method to map between the +names of the columns in the database to the names it displays in the +default templates. This is provided by C, and +normally, it does a pretty good job; it turns C into +"Model Number", for instance, but there was no way it could guess that +C was an abbreviation. Since it returns a hash, the easiest way +to correct it is to construct a hash consisting of the bits it got +right, and then override the bits it got wrong: + + package BeerDB::Beer; + sub column_names { + (shift->SUPER::column_names(), abv => "A.B.V.") + } + +Similarly, the order of columns is a bit wonky. We can fix this by +overriding the C method; this is also a good way to +hide away any columns we don't want to have displayed, in the same way +as declaring the C configuration parameter let us hide +away tables we weren't using: + + sub display_columns { + ("name", "brewery", "style", "price", "score", "abv", "notes") + } + +Hey, have you noticed that we haven't done anything with the +beers/handpumps/pubs thing yet? Good, I was hoping that you hadn't. +Ayway, this is because Maypole can't tell easily that a C +object can call C to get a list of pubs. Not yet, at least; we're +working on it. In the interim, we can explicitly tell Maypole which +accessors are related to the C class like so: + + sub related { "pubs" } + +Now when we view a beer, we'll have a list of the pubs that it's on at.