| 1 | package Pod::Simple::Wiki::Moinmoin; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | ############################################################################### | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # Pod::Simple::Wiki::Moinmoin - A class for creating Pod to Moinmoin filters. | ||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # Copyright 2003-2012, John McNamara, jmcnamara@cpan.org | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # Documentation after __END__ | ||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # perltidy with the following options: -mbl=2 -pt=0 -nola | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Pod::Simple::Wiki; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use vars qw(@ISA $VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | @ISA = qw(Pod::Simple::Wiki); | |||||||||||||||||||||||||||
| 21 | 2 | $VERSION = '0.20'; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | ############################################################################### | ||||||||||||||||||||||||||||
| 25 | # | ||||||||||||||||||||||||||||
| 26 | # The tag to wiki mappings. | ||||||||||||||||||||||||||||
| 27 | # | ||||||||||||||||||||||||||||
| 28 | 2 | my $tags = { | |||||||||||||||||||||||||||
| 29 | '<b>' => "'''", | ||||||||||||||||||||||||||||
| 30 | '</b>' => "'''", | ||||||||||||||||||||||||||||
| 31 | '<i>' => "''", | ||||||||||||||||||||||||||||
| 32 | '</i>' => "''", | ||||||||||||||||||||||||||||
| 33 | '<tt>' => '`', | ||||||||||||||||||||||||||||
| 34 | '</tt>' => '`', | ||||||||||||||||||||||||||||
| 35 | '<pre>' => "\n{{{\n", | ||||||||||||||||||||||||||||
| 36 | '</pre>' => "\n}}}\n", | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | '<h1>' => "\n== ", | ||||||||||||||||||||||||||||
| 39 | '</h1>' => " ==\n\n", | ||||||||||||||||||||||||||||
| 40 | '<h2>' => "\n=== ", | ||||||||||||||||||||||||||||
| 41 | '</h2>' => " ===\n\n", | ||||||||||||||||||||||||||||
| 42 | '<h3>' => "\n==== ", | ||||||||||||||||||||||||||||
| 43 | '</h3>' => " ====\n\n", | ||||||||||||||||||||||||||||
| 44 | '<h4>' => "\n===== ", | ||||||||||||||||||||||||||||
| 45 | '</h4>' => " =====\n\n", | ||||||||||||||||||||||||||||
| 46 | }; | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | ############################################################################### | ||||||||||||||||||||||||||||
| 50 | # | ||||||||||||||||||||||||||||
| 51 | # new() | ||||||||||||||||||||||||||||
| 52 | # | ||||||||||||||||||||||||||||
| 53 | # Simple constructor inheriting from Pod::Simple::Wiki. | ||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||
| 55 | 21 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 21 | my $class = shift; | |||||||||||||||||||||||||||
| 58 | 21 | my $self = Pod::Simple::Wiki->new( 'wiki', @_ ); | |||||||||||||||||||||||||||
| 59 | 21 | $self->{_tags} = $tags; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 21 | bless $self, $class; | |||||||||||||||||||||||||||
| 62 | 21 | return $self; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | ############################################################################### | ||||||||||||||||||||||||||||
| 67 | # | ||||||||||||||||||||||||||||
| 68 | # _indent_item() | ||||||||||||||||||||||||||||
| 69 | # | ||||||||||||||||||||||||||||
| 70 | # Indents an "over-item" to the correct level. | ||||||||||||||||||||||||||||
| 71 | # | ||||||||||||||||||||||||||||
| 72 | 40 | ▶ | sub _indent_item { | ||||||||||||||||||||||||||
|
Subroutine
_indent_item: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 40 | my $self = shift; | |||||||||||||||||||||||||||
| 75 | 40 | my $item_type = $_[0]; | |||||||||||||||||||||||||||
| 76 | 40 | my $item_param = $_[1]; | |||||||||||||||||||||||||||
| 77 | 40 | my $indent_level = $self->{_item_indent}; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 40 | ▶ | if ( $item_type eq 'bullet' ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 80 | 13 | $self->_append( ' ' x $indent_level . "* " ); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | elsif ( $item_type eq 'number' ) { | ||||||||||||||||||||||||||||
| 83 | 13 | $self->_append( ' ' x $indent_level . "1. " ); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | elsif ( $item_type eq 'text' ) { | ||||||||||||||||||||||||||||
| 86 | 14 | $self->_append( ' ' x $indent_level ); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 40 | $self->{_moinmoin_list} = 1; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | ############################################################################### | ||||||||||||||||||||||||||||
| 94 | # | ||||||||||||||||||||||||||||
| 95 | # _handle_text() | ||||||||||||||||||||||||||||
| 96 | # | ||||||||||||||||||||||||||||
| 97 | # Perform any necessary transforms on the text. This is mainly used to escape | ||||||||||||||||||||||||||||
| 98 | # inadvertent CamelCase words. | ||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||
| 100 | 66 | ▶ | sub _handle_text { | ||||||||||||||||||||||||||
|
Subroutine
_handle_text: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 66 | my $self = shift; | |||||||||||||||||||||||||||
| 103 | 66 | my $text = $_[0]; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # Split the text into tokens but maintain the whitespace | ||||||||||||||||||||||||||||
| 106 | 66 | my @tokens = split /(\s+)/, $text; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # Escape any tokens here. | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | # Rejoin the tokens and whitespace. | ||||||||||||||||||||||||||||
| 111 | 66 | $self->{_wiki_text} .= join '', @tokens; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | ############################################################################### | ||||||||||||||||||||||||||||
| 116 | # | ||||||||||||||||||||||||||||
| 117 | # Functions to deal with =over ... =back regions for | ||||||||||||||||||||||||||||
| 118 | # | ||||||||||||||||||||||||||||
| 119 | # Bulleted lists | ||||||||||||||||||||||||||||
| 120 | # Numbered lists | ||||||||||||||||||||||||||||
| 121 | # Text lists | ||||||||||||||||||||||||||||
| 122 | # Block lists | ||||||||||||||||||||||||||||
| 123 | # | ||||||||||||||||||||||||||||
| 124 | 14 | ▶ | sub _end_item_text { | ||||||||||||||||||||||||||
|
Subroutine
_end_item_text: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 125 | 14 | $_[0]->_output( ":: " ); | |||||||||||||||||||||||||||
| 126 | 14 | $_[0]->{_moinmoin_list} = 0; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | ############################################################################### | ||||||||||||||||||||||||||||
| 130 | # | ||||||||||||||||||||||||||||
| 131 | # _start_Para() | ||||||||||||||||||||||||||||
| 132 | # | ||||||||||||||||||||||||||||
| 133 | # Special handling for paragraphs that are part of an "over" block. | ||||||||||||||||||||||||||||
| 134 | # | ||||||||||||||||||||||||||||
| 135 | 26 | ▶ | sub _start_Para { | ||||||||||||||||||||||||||
|
Subroutine
_start_Para: called CC=9 SCAR=23.4
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 26 | my $self = shift; | |||||||||||||||||||||||||||
| 138 | 26 | my $indent_level = $self->{_item_indent}; | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 26 | ▶ | if ( $self->{_in_over_block} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 1 | $self->_append( ' ' x $indent_level ); | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 26 | ▶ | if ( $self->{_moinmoin_list} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 4 | ▶ | if ( not $self->{_in_over_text} and $self->{_moinmoin_list} == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $self->{"_in_over_text"} and $self->{"_moinmoin_list"} == 1
MC/DC50%1/2
not $self->{"_in_over_text"} and $self->{"_moinmoin_list"} == 1
not $self->{"_in_over_text"}
$self->{"_moinmoin_list"} == 1
Truth table66%2/3
not(A) and B
A= not $self->{"_in_over_text"}B= $self->{"_moinmoin_list"} == 1
| |||||||||||||||||||||||||||||
| 146 | 2 | $self->_append( "\n" ); | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 4 | ▶ | if ( $self->{_in_over_text} and $self->{_moinmoin_list} == 2 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"_in_over_text"} and $self->{"_moinmoin_list"} == 2
MC/DC0%0/2
$self->{"_in_over_text"} and $self->{"_moinmoin_list"} == 2
$self->{"_in_over_text"}
$self->{"_moinmoin_list"} == 2
Truth table33%1/3
A and B
A= $self->{"_in_over_text"}B= $self->{"_moinmoin_list"} == 2
| |||||||||||||||||||||||||||||
| 150 | 0 | $self->_append( "\n" ); | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 4 | ▶ | if ( not( $self->{_in_over_text} and $self->{_moinmoin_list} == 1 ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"_in_over_text"} and $self->{"_moinmoin_list"} == 1
MC/DC0%0/2
$self->{"_in_over_text"} and $self->{"_moinmoin_list"} == 1
$self->{"_in_over_text"}
$self->{"_moinmoin_list"} == 1
Truth table33%1/3
A and B
A= $self->{"_in_over_text"}B= $self->{"_moinmoin_list"} == 1
| |||||||||||||||||||||||||||||
| 154 | 4 | $self->_append( ' ' x $indent_level ); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 4 | $self->{_moinmoin_list}++; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 2 | 1; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | __END__ | ||||||||||||||||||||||||||||