File Coverage

blib/lib/MojoMojo/Formatter.pm
Criterion Covered Total %
statement 4 4 100.0
branch n/a
condition 1 2 50.0
subroutine 2 2 100.0
pod 2 2 100.0
total 9 10 90.0


line stmt bran cond sub pod time code
1             package MojoMojo::Formatter;
2              
3             =head1 NAME
4              
5             MojoMojo::Formatter - Base class for all formatters
6              
7             =head1 SYNOPSIS
8              
9             package MojoMojo::Formatter::Simple;
10              
11             use parent qw/MojoMojo::Formatter/;
12              
13             sub format_content_order { 14 }
14             # so that it runs after inclusion of obscene web sites
15             # (MojoMojo::Formatter::Include runs at 6)
16              
17             sub format_content {
18             my ($class, $content, $c) = @_;
19             $$content =~ s/fuck/f**k/g;
20             return $content;
21             }
22              
23              
24             =head1 DESCRIPTION
25              
26             This is the class to inherit from if you want to write your own formatter.
27              
28              
29             =head1 WRITING YOUR OWN FORMATTER
30              
31             See the synopsis for a really simple formatter example. MojoMojo uses
32             L<Module::Pluggable::Ordered> to process all the formatter plugins. Just
33             specify when you want to trigger your formatter by providing a format_content_order
34             method which returns a number to specify when you want to run. The plugin order
35             for the default plugins is currently as follows:
36              
37             =over 4
38              
39             =item 1 - L<MojoMojo::Formatter::Redirect> - handles {{redirect /path}}
40              
41             =item 5 - L<MojoMojo::Formatter::Include> - handles {{include <url>}} before
42             all other plugins, so that transcluded sections from the same wiki get parsed
43             for markup
44              
45             =item 10 - L<MojoMojo::Formatter::CPANHyperlink> - handles {{cpan My::Module}}
46              
47             =item 10 - L<MojoMojo::Formatter::YouTube> - handles {{youtube <url>}}
48              
49             =item 10 - L<MojoMojo::Formatter::Wiki> - handles [[wikilinks]]
50              
51             =item 10 - L<MojoMojo::Formatter::Pod> - handles {{pod}} ... {{end}} blocks
52              
53             =item 14 - L<MojoMojo::Formater::IRCLog> - handles {{irc}} ... {{end}} blocks
54              
55             =item 14 - L<MojoMojo::Formatter::SyntaxHighlight> - Performs syntax highlighting
56             on code blocks
57              
58             =item 15 - Main formatter (L<MojoMojo::Formatter::Markdown> or
59             L<MojoMojo::Formatter::Textile>)
60              
61             =item 16 - L<MojoMojo::Formatter::Defang> - removes harmful HTML and XSS
62              
63             =item 91 - L<MojoMojo::Formatter::Comment> - handles {{comments}}, inserts a comment box
64              
65             =item 95 - L<MojoMojo::Formatter::TOC> - replaces {{toc}} with a table of contents
66              
67             =back
68              
69             Note that if your formatter expects HTML text, it should run after the
70             main formatter.
71              
72              
73             =head1 METHODS
74              
75             =head2 format_content
76              
77             If you want your formatter to do something, you also need to override
78             C<format_content>. It gets passed its classname, a scalar ref to the content,
79             and the context object. It should return the scalar ref.
80              
81             =head2 main_format_content
82              
83             Override this method if your formatter is a primary one (equivalent to Markdown or
84             Textile). It gets passed the same arguments as L</format_content>. Also make sure
85             to update "Site settings" (/.admin).
86              
87             Note that the main formatter runs at 15.
88              
89             =head2 module_loaded
90              
91             Return true if a formatter module is loaded.
92              
93             =cut
94              
95 135     135 1 63925 sub module_loaded { 1; }
96              
97             =head2 gen_re
98              
99             gen_re(qr/irc/)
100              
101             Returns a regular expression for the given tag between matching double braces.
102              
103             =cut
104              
105             sub gen_re {
106 2154     2154 1 4637 my ($self, $tag, $args)=@_;
107 2154   50     9510 $args ||= '';
108 2154         31579 return qr[\{\{\s*$tag\s*$args\s*}}];
109             }
110              
111              
112             =head1 SEE ALSO
113              
114             L<MojoMojo>, L<MojoMojo::Formatter::Textile>, L<MojoMojo::Formatter::Markdown>
115              
116             =head1 AUTHORS
117              
118             Marcus Ramberg <mramberg@cpan.org>
119              
120             =head1 LICENSE
121              
122             This library is free software. You can redistribute it and/or modify
123             it under the same terms as Perl itself.
124              
125             =cut
126              
127             1;