File Coverage

blib/lib/MojoMojo/Formatter/Comment.pm
Criterion Covered Total %
statement 12 12 100.0
branch 2 2 100.0
condition n/a
subroutine 4 4 100.0
pod 3 3 100.0
total 21 21 100.0


line stmt bran cond sub pod time code
1             package MojoMojo::Formatter::Comment;
2              
3 26     26   65321 use parent qw/MojoMojo::Formatter/;
  26         298  
  26         211  
4              
5             =head1 NAME
6              
7             MojoMojo::Formatter::Comment - Include comments on your page.
8              
9             =head1 DESCRIPTION
10              
11             This is a hook for the page comment functionality. It allows a
12             comment box to be placed anywhere on your page through the {{comments}}
13             tag.
14              
15             =head1 METHODS
16              
17             =head2 format_content_order
18              
19             Format order can be 1-99. The Comment formatter runs on 91.
20              
21             =cut
22              
23 868     868 1 3260 sub format_content_order { 91 }
24              
25             =head2 format_content
26              
27             Calls the formatter. Takes a ref to the content as well as the
28             context object.
29              
30             =cut
31              
32             sub format_content {
33 124     124 1 1109 my ( $class, $content, $c, $self ) = @_;
34 124         534 my $re=$class->gen_re('comments');
35 124 100       1145 if ( $$content =~ s|$re|show_comments($c,$c->stash->{page})|xme ) {
  1         6  
36             # We don't want to precompile a page with comments so turn it off
37 1         142 $c->stash->{precompile_off} = 1;
38             }
39             }
40              
41             =head2 show_comments
42              
43             Forwards to L<MojoMojo::Controller::Comment>.
44              
45             =cut
46              
47             sub show_comments {
48 1     1 1 87 my ( $c, $page ) = @_;
49 1         8 $c->forward('/comment/comment');
50 1         2051 return '<div id="comments">' . $c->view('TT')->render( $c, 'comment.tt' ) . '</div>';
51             }
52              
53             =head1 SEE ALSO
54              
55             L<MojoMojo>, L<Module::Pluggable::Ordered>
56              
57             =head1 AUTHORS
58              
59             Marcus Ramberg <mramberg@cpan.org>
60              
61             =head1 LICENSE
62              
63             This library is free software. You can redistribute it and/or modify
64             it under the same terms as Perl itself.
65              
66             =cut
67              
68             1;