| MojoMojo documentation | Contained in the MojoMojo distribution. |
MojoMojo::Controller::Comment - MojoMojo Comment controller
See MojoMojo
Controller for Page comments.
display comments for embedding in a page
Inline login for comments.
Remove comments, provided user can edit the page the comment is on.
Marcus Ramberg <mramberg@cpan.org>
This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
| MojoMojo documentation | Contained in the MojoMojo distribution. |
package MojoMojo::Controller::Comment; use strict; use parent 'Catalyst::Controller::HTML::FormFu';
sub comment : Global FormConfig { my ( $self, $c ) = @_; my $form=$c->stash->{form}; $c->stash->{template} = 'comment.tt'; if ( $c->stash->{user} && $form->submitted_and_valid) { $c->model("DBIC::Comment")->create( { page => $c->stash->{page}->id, poster => $c->stash->{user}->id, posted => DateTime->now(), body => $c->req->param('body'), } ); } $c->stash->{comments} = $c->model("DBIC::Comment") ->search( { page => $c->stash->{page}->id }, { order_by => 'posted' } ); }
sub login : Local { my ( $self, $c ) = @_; $c->stash->{template} = 'comment/post.tt'; $c->forward('/user/login'); if ( $c->stash->{fail} ) { $c->stash->{template} = 'comment/login.tt'; } }
sub remove : Local { my ( $self, $c, $comment ) = @_; if ( $comment = $c->model("DBIC::Comment")->find($comment) ) { if ( $comment->page->id == $c->stash->{page}->id && $c->stash->{user}->can_edit( $comment->page->path ) ) { $comment->delete(); } } $c->forward('/page/view'); }
1;