File: Comment.pm

package info (click to toggle)
libmojomojo-perl 1.01%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,272 kB
  • ctags: 879
  • sloc: perl: 14,055; sh: 145; xml: 120; ruby: 6; makefile: 2
file content (90 lines) | stat: -rw-r--r-- 1,875 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package MojoMojo::Controller::Comment;

use strict;

use parent 'Catalyst::Controller::HTML::FormFu';

=head1 NAME

MojoMojo::Controller::Comment - MojoMojo Comment controller

See L<MojoMojo>

=head1 DESCRIPTION

Controller for Page comments.

=head1 METHODS

=head2 comment

display comments for embedding in a page

=cut

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' } );
}

=head2 login ( .comment/login )

Inline login for comments.

=cut

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';
    }
}

=head2 remove ( .comment/remove )

Remove comments, provided user can edit the page the comment is on.

=cut

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');

}

=head1 AUTHOR

Marcus Ramberg <mramberg@cpan.org>

=head1 LICENSE

This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;