X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=examples%2Fbloggery%2Fbloggery.cgi;h=8e1988671b080615e759f0d7bfbd609d514709c4;hb=87ec704e35894b8a77348cce18918dace31e269b;hp=047b3ed27564b99f34735f0c28f0b594e5cc8c1e;hpb=391190822264aefefa6755d410141688a7155dee;p=catagits%2FWeb-Simple.git diff --git a/examples/bloggery/bloggery.cgi b/examples/bloggery/bloggery.cgi index 047b3ed..8e19886 100755 --- a/examples/bloggery/bloggery.cgi +++ b/examples/bloggery/bloggery.cgi @@ -1,3 +1,5 @@ +#!/usr/bin/perl + use FindBin; use lib $FindBin::Bin.'/code'; use Web::Simple 'Bloggery'; @@ -64,17 +66,20 @@ sub summary_html { package Bloggery; -default_config( - title => 'Bloggery', - posts_dir => $FindBin::Bin.'/posts', -); +has post_list => (is => 'lazy'); + +sub default_config { + ( + title => 'Bloggery', + posts_dir => $FindBin::Bin.'/posts', + ); +} -sub post_list { +sub _build_post_list { my ($self) = @_; - $self->{post_list} - ||= Bloggery::PostList->from_dir( - $self->config->{posts_dir} - ); + Bloggery::PostList->from_dir( + $self->config->{posts_dir} + ); } sub post { @@ -82,18 +87,19 @@ sub post { $self->post_list->post($post); } -dispatch [ - sub (.html) { - filter_response { $self->render_html($_[1]) }, - }, +sub dispatch_request { + my $self = shift; sub (GET + /) { - redispatch_to '/index.html'; + redispatch_to '/index.html' + }, + sub (.html) { + response_filter { $self->render_html(@_) } }, sub (GET + /index) { $self->post_list }, sub (GET + /*) { - $self->post($_[1]); + $self->post($_[1]) }, sub (GET) { [ 404, [ 'Content-type', 'text/plain' ], [ 'Not found' ] ] @@ -101,7 +107,7 @@ dispatch [ sub { [ 405, [ 'Content-type', 'text/plain' ], [ 'Method not allowed' ] ] }, -]; +}; sub render_html { my ($self, $data) = @_; @@ -144,7 +150,7 @@ sub main_html_for { } elsif ($data->isa('Bloggery::PostList')) {