X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=examples%2Fbloggery%2Fbloggery.cgi;h=8e1988671b080615e759f0d7bfbd609d514709c4;hb=d57f3db440f7140beaebc64a77e34cbab14427e6;hp=6e12e794dd84eb2d66522441dee39d7e481c4c2b;hpb=5c33dda5c048a8351784cfea7d6e04a24f110bb0;p=catagits%2FWeb-Simple.git diff --git a/examples/bloggery/bloggery.cgi b/examples/bloggery/bloggery.cgi index 6e12e79..8e19886 100755 --- a/examples/bloggery/bloggery.cgi +++ b/examples/bloggery/bloggery.cgi @@ -28,6 +28,11 @@ sub post { return Bloggery::Post->from_file($file); } +sub map { + my ($self, $code) = @_; + map $code->($_), $self->all; +} + package Bloggery::Post; sub from_file { @@ -61,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 { @@ -79,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 + /) { - $self->redispatch('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' ] ] @@ -98,7 +107,7 @@ dispatch [ sub { [ 405, [ 'Content-type', 'text/plain' ], [ 'Method not allowed' ] ] }, -]; +}; sub render_html { my ($self, $data) = @_; @@ -140,13 +149,13 @@ sub main_html_for { $data->html } elsif ($data->isa('Bloggery::PostList')) { ; } else {

, "Don't know how to render $data",

;