| 1 | package MojoMojo::Controller::Comment; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 35 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 35 | ▶ | use parent 'Catalyst::Controller::HTML::FormFu'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | MojoMojo::Controller::Comment - MojoMojo Comment controller | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | See L<MojoMojo> | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | Controller for Page comments. | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 METHODS | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head2 comment | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | display comments for embedding in a page | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =cut | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | sub comment : Global FormConfig { | ||||||||||||||||||||||||||
|
Subroutine
comment: called CC=3 SCAR=12.3
| |||||||||||||||||||||||||||||
| 26 | 2 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||
| 27 | 2 | my $form=$c->stash->{form}; | |||||||||||||||||||||||||||
| 28 | 2 | $c->stash->{template} = 'comment.tt'; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | if ( $c->stash->{user} && $form->submitted_and_valid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$c->stash->{"user"} and $form->submitted_and_valid
MC/DC0%0/2
$c->stash->{"user"} and $form->submitted_and_valid
$c->stash->{"user"}
$form->submitted_and_valid
Truth table33%1/3
A and B
A= $c->stash->{"user"}B= $form->submitted_and_valid
| |||||||||||||||||||||||||||||
| 31 | $c->model("DBIC::Comment")->create( | ||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||
| 33 | page => $c->stash->{page}->id, | ||||||||||||||||||||||||||||
| 34 | poster => $c->stash->{user}->id, | ||||||||||||||||||||||||||||
| 35 | 0 | posted => DateTime->now(), | |||||||||||||||||||||||||||
| 36 | body => scalar $c->req->param('body'), | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | $c->stash->{comments} = | ||||||||||||||||||||||||||||
| 41 | $c->model("DBIC::Comment") | ||||||||||||||||||||||||||||
| 42 | 2 | ->search( { page => $c->stash->{page}->id }, { order_by => 'posted' } ); | |||||||||||||||||||||||||||
| 43 | 35 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =head2 login ( .comment/login ) | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | Inline login for comments. | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | =cut | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | ▶ | sub login : Local { | ||||||||||||||||||||||||||
|
Subroutine
login: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 1 | my ( $self, $c ) = @_; | |||||||||||||||||||||||||||
| 53 | 1 | $c->stash->{template} = 'comment/post.tt'; | |||||||||||||||||||||||||||
| 54 | 1 | $c->forward('/user/login'); | |||||||||||||||||||||||||||
| 55 | 1 | ▶ | if ( $c->stash->{fail} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | $c->stash->{template} = 'comment/login.tt'; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 35 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head2 remove ( .comment/remove ) | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Remove comments, provided user can edit the page the comment is on. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub remove : Local { | ||||||||||||||||||||||||||
|
Subroutine
remove: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 0 | my ( $self, $c, $comment ) = @_; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ( $comment = $c->model("DBIC::Comment")->find($comment) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ( $comment->page->id == $c->stash->{page}->id | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$comment->page->id == $c->stash->{"page"}->id and $c->stash->{"user"}->can_edit($comment->page->path)
MC/DC0%0/2
$comment->page->id == $c->stash->{"page"}->id and $c->stash->{"user"}->can_edit($comment->page->path)
$comment->page->id == $c->stash->{"page"}->id
$c->stash->{"user"}->can_edit($comment->page->path)
Truth table0%0/3
A and B
A= $comment->page->id == $c->stash->{"page"}->idB= $c->stash->{"user"}->can_edit($comment->page->path)
| |||||||||||||||||||||||||||||
| 70 | && $c->stash->{user}->can_edit( $comment->page->path ) ) | ||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||
| 72 | 0 | $comment->delete(); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 0 | $c->forward('/page/view'); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 35 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | Marcus Ramberg <mramberg@cpan.org> | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | This library is free software. You can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 86 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =cut | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 35 | 1; | |||||||||||||||||||||||||||