| 1 | package Template::Plugin::WikiFormat; | ||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 6 | our $VERSION = '0.07'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | #---------------------------------------------------------------------------- | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | Template::Plugin::WikiFormat - TT wrapper for Text::WikiFormat | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | [% USE WikiFormat %] | ||||||||||||||||||||
| 16 | [% FILTER $WikiFormat %] | ||||||||||||||||||||
| 17 | ... | ||||||||||||||||||||
| 18 | [% END %] | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | This is a plugin used for wiki rendering inside Template Toolkit. | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | Parameters may be passed in through the USE directive, e.g. | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | [% USE WikiFormat prefix = "http://www.mysite.com/?page=" %] | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | This provides the 4 options supported by L<Text::WikiFormat>, i.e. | ||||||||||||||||||||
| 29 | C<prefix, extended, implicit_links, absolute_links>, and the special option | ||||||||||||||||||||
| 30 | global_replace, which takes an array of arrays of from and to strings. The | ||||||||||||||||||||
| 31 | output from Text::WikiFormat is post processed by replacing each from regexp | ||||||||||||||||||||
| 32 | with the to regexp. Anything else passed in is interpreted as a tag (see the | ||||||||||||||||||||
| 33 | Gory Details section). | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | =head2 filter | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | Accepts the wiki text to be rendered, and context. The tags and options are | ||||||||||||||||||||
| 38 | passed in through the context. See L<Template::Plugin::Filter>. | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | #---------------------------------------------------------------------------- | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | ############################################################################# | ||||||||||||||||||||
| 45 | #Library Modules # | ||||||||||||||||||||
| 46 | ############################################################################# | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 6 | ▶ | use base 'Template::Plugin::Filter'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 49 | 6 | ▶ | use Text::WikiFormat; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | #---------------------------------------------------------------------------- | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | ############################################################################# | ||||||||||||||||||||
| 54 | #Interface Methods # | ||||||||||||||||||||
| 55 | ############################################################################# | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | sub filter { | ||||||||||||||||||||
| 58 | 5 | ▶ | my ( $self, $text ) = @_; | ||||||||||||||||||
|
Subroutine
filter: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 5 | my $conf = $self->{_CONFIG}; | |||||||||||||||||||
| 61 | 5 | ▶ | $conf ||= {}; | ||||||||||||||||||
|
Condition50%1/2
$conf ||= {}
MC/DC0%0/1
$conf ||= {}
$conf
Truth table50%1/2
A
A= $conf
| |||||||||||||||||||||
| 62 | 5 | my %tags = %$conf; | |||||||||||||||||||
| 63 | 5 | my %opts; | |||||||||||||||||||
| 64 | 5 | my %default = ( | |||||||||||||||||||
| 65 | prefix => '', | ||||||||||||||||||||
| 66 | extended => 0, | ||||||||||||||||||||
| 67 | implicit_links => 1, | ||||||||||||||||||||
| 68 | absolute_links => 0, | ||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||
| 70 | 5 | for ( keys %default ) { | |||||||||||||||||||
| 71 | 20 | ▶ | $opts{$_} = $tags{$_} || $default{$_}; | ||||||||||||||||||
|
Condition100%3/3
$tags{$_} || $default{$_}
MC/DC100%2/2
$tags{$_} || $default{$_}
$tags{$_}
$default{$_}
Truth table100%3/3
A || B
A= $tags{$_}B= $default{$_}
| |||||||||||||||||||||
| 72 | 20 | delete $tags{$_}; | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 5 | my $replace; | |||||||||||||||||||
| 75 | 5 | ▶ | if ( exists $tags{global_replace} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 1 | $replace = $tags{global_replace}; | |||||||||||||||||||
| 77 | 1 | delete $tags{global_replace}; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 5 | my $output = Text::WikiFormat::format( $text, \%tags, \%opts ); | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 5 | for my $rep (@$replace) { | |||||||||||||||||||
| 83 | 1 | my ( $from, $to ) = @$rep; | |||||||||||||||||||
| 84 | 1 | eval("\$output =~ s($from)($to)sg"); | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | 5 | return $output; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 6 | 1; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | __END__ | ||||||||||||||||||||