1 package App::Commentry;
3 use aliased 'App::Commentry::CommentStore';
10 store_dir => $FindBin::Bin.'/../store/comments',
11 template_dir => $FindBin::Bin.'/../share/html',
15 has comment_store => (
16 is => 'lazy', handles => { 'comments_for' => 'get' }
19 sub _build_comment_store {
21 my $store_dir = $self->config->{store_dir};
22 die "Comment Store directory ${store_dir} does not exist"
24 CommentStore->new(base_dir => $self->config->{store_dir});
31 sub _build_template_dir {
33 my $template_dir = $self->config->{template_dir};
34 die "template_dir ${template_dir} does not exist"
35 unless -d $template_dir;
39 sub dispatch_request {
41 sub (/fragments/*/**) {
42 my ($self, $action, $path) = @_;
43 return unless $action eq 'show' or $action eq 'add';
44 return unless my $set = $self->comments_for({ path => $path });
45 $self->${\"_fragment_${action}"}($set);
50 my ($self, $set) = @_;
52 $self->_zoom_response(fragment_show => sub {
53 $_->select('.comment')
54 ->repeat($set->map(sub {
57 $_->select('.comment-title')->replace_content($comment->title)
58 ->select('.comment-body')->replace_content($comment->body)
66 my ($self, $template, $apply) = @_;
67 my $zfh = ($self->{zoom_cache}{$template} ||= do {
68 HTML::Zoom->from_file($self->template_dir.'/'.$template.'.html')
69 })->apply($apply)->to_fh;
70 [ 200, [ 'Content-type' => 'text/html' ], $zfh ];