From 0f0ccfbbe2488b34841e5af2ecedd9f256c8489f Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Tue, 6 Apr 2004 10:39:10 +0000 Subject: [PATCH] Add constants; refactor View classes and tests to use them; refactor out handler_guts to allow subcomponent stuff. git-svn-id: http://svn.maypole.perl.org/Maypole/trunk@117 48953598-375a-da11-a14b-00016c27c3ee --- MANIFEST | 3 +++ doc/Beer.pod | 3 +++ doc/StandardTemplates.pod | 1 + lib/Maypole.pm | 22 +++++++++++++--------- lib/Maypole/Constants.pm | 7 +++++++ t/1.t | 5 +++-- 6 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 lib/Maypole/Constants.pm diff --git a/MANIFEST b/MANIFEST index 08000a6..f4cf27a 100644 --- a/MANIFEST +++ b/MANIFEST @@ -11,8 +11,11 @@ doc/View.pod doc/makedoc.pl ex/BeerDB.pm lib/Maypole/CLI.pm +lib/Maypole/Constants.pm lib/Maypole/Model/Base.pm lib/Maypole/Model/CDBI.pm +lib/Maypole/View/Base.pm +lib/Maypole/View/Mason.pm lib/Maypole/View/TT.pm lib/Maypole/Workflow.pod lib/Maypole.pm diff --git a/doc/Beer.pod b/doc/Beer.pod index 33baddf..fa8fe84 100644 --- a/doc/Beer.pod +++ b/doc/Beer.pod @@ -1,5 +1,8 @@ =head1 The Beer Database, Twice +We briefly introduced the "beer database" example in the L +material; + =head2 The big beer problem =head2 The easy way diff --git a/doc/StandardTemplates.pod b/doc/StandardTemplates.pod index 88727fd..e5eb9f0 100644 --- a/doc/StandardTemplates.pod +++ b/doc/StandardTemplates.pod @@ -285,3 +285,4 @@ The C template argument is used to distinguish between the two cases:

Listing of all [% classmetadata.plural %]

[% END %] +=head1 Customizing Generic CRUD Applications diff --git a/lib/Maypole.pm b/lib/Maypole.pm index fedd3e5..46fb7d4 100644 --- a/lib/Maypole.pm +++ b/lib/Maypole.pm @@ -10,10 +10,7 @@ __PACKAGE__->mk_accessors ( qw( ar params query objects model_class args action template )); __PACKAGE__->config({}); __PACKAGE__->init_done(0); - -# Ape Apache::Constants interface -use constant OK => 0; -use constant DECLINED => -1; +use Maypole::Constants; sub debug { 0 } @@ -57,7 +54,17 @@ sub handler { my $r = bless { config => $class->config }, $class; $r->get_request(); $r->parse_location(); + my $status = $r->handler_guts(); + if ($status != OK) { + warn "NOT OK!"; + return $status; + } + $r->send_output; + return $status; +} +sub handler_guts { + my $r = shift; $r->model_class($r->config->{model}->class_of($r, $r->{table})); my $status = $r->is_applicable; if ($status == OK) { @@ -77,12 +84,9 @@ sub handler { $r->{path} =~ s{/}{}; # De-absolutify $r->template($r->{path}); } - $status = OK; if (!$r->{output}) { # You might want to do it yourself - $status = $r->view_object->process($r); - } - $r->send_output; - return $status; + return $r->view_object->process($r); + } else { return OK; } } sub is_applicable { diff --git a/lib/Maypole/Constants.pm b/lib/Maypole/Constants.pm new file mode 100644 index 0000000..7bddbac --- /dev/null +++ b/lib/Maypole/Constants.pm @@ -0,0 +1,7 @@ +package Maypole::Constants; +use base 'Exporter'; +use constant OK => 0; +use constant DECLINED => -1; +use constant ERROR => -1; +our @EXPORT = qw(OK DECLINED ERROR); +1; diff --git a/t/1.t b/t/1.t index 77c1f9f..be5e6bd 100644 --- a/t/1.t +++ b/t/1.t @@ -1,14 +1,15 @@ # vim:ft=perl use Test::More tests => 5; use Maypole::CLI qw(BeerDB); +use Maypole::Constants; $ENV{MAYPOLE_TEMPLATES} = "t/templates"; isa_ok( (bless {},"BeerDB") , "Maypole"); @ARGV = ("http://localhost/beerdb/"); -is(BeerDB->handler, 200, "OK"); +is(BeerDB->handler, OK, "OK"); like($Maypole::CLI::buffer, qr/frontpage/, "Got the front page"); @ARGV = ("http://localhost/beerdb/beer/list"); -is(BeerDB->handler, 200, "OK"); +is(BeerDB->handler, OK, "OK"); like($Maypole::CLI::buffer, qr/Organic Best/, "Found a beer in the list"); -- 2.39.2