File Coverage

blib/lib/Pod/Simple/Wiki/Kwiki.pm
Criterion Covered Total %
statement 43 44 97.7
branch 15 18 83.3
condition 3 9 33.3
subroutine 10 10 100.0
pod 1 1 100.0
total 72 82 87.8


line stmt bran cond sub pod time code
1             package Pod::Simple::Wiki::Kwiki;
2              
3             ###############################################################################
4             #
5             # Pod::Simple::Wiki::Kwiki - A class for creating Pod to Kwiki 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 3     3   16 use Pod::Simple::Wiki;
  3         6  
  3         96  
16 3     3   15 use strict;
  3         4  
  3         73  
17 3     3   14 use vars qw(@ISA $VERSION);
  3         4  
  3         2181  
18              
19              
20             @ISA = qw(Pod::Simple::Wiki);
21             $VERSION = '0.19';
22              
23              
24             ###############################################################################
25             #
26             # The tag to wiki mappings.
27             #
28             my $tags = {
29             '' => '*',
30             '' => '*',
31             '' => '/',
32             '' => '/',
33             '' => '[=',
34             '' => ']',
35             '
'  => '', 
36             '' => "\n\n",
37              
38             '

' => "\n----\n= ",

39             '' => " =\n\n",
40             '

' => "\n== ",

41             '' => " ==\n\n",
42             '

' => "\n=== ",

43             '' => " ===\n\n",
44             '

' => "==== ",

45             '' => "\n\n",
46             };
47              
48              
49             ###############################################################################
50             #
51             # new()
52             #
53             # Simple constructor inheriting from Pod::Simple::Wiki.
54             #
55             sub new {
56              
57 22     22 1 33 my $class = shift;
58 22         73 my $self = Pod::Simple::Wiki->new( 'wiki', @_ );
59 22         49 $self->{_tags} = $tags;
60              
61 22         34 bless $self, $class;
62 22         63 return $self;
63             }
64              
65              
66             ###############################################################################
67             #
68             # _indent_item()
69             #
70             # Indents an "over-item" to the correct level.
71             #
72             sub _indent_item {
73              
74 37     37   110 my $self = shift;
75 37         55 my $item_type = $_[0];
76 37         45 my $item_param = $_[1];
77 37         54 my $indent_level = $self->{_item_indent};
78              
79 37 100       115 if ( $item_type eq 'bullet' ) {
    100          
    50          
80 12         47 $self->_append( '*' x $indent_level . ' ' );
81             }
82             elsif ( $item_type eq 'number' ) {
83 12         40 $self->_append( '0' x $indent_level . ' ' );
84             }
85             elsif ( $item_type eq 'text' ) {
86 13         54 $self->_append( ';' x $indent_level . ' ' );
87             }
88             }
89              
90              
91             ###############################################################################
92             #
93             # _skip_headings()
94             #
95             # Formatting in headings doesn't look great or is ignored in some formats.
96             #
97             sub _skip_headings {
98              
99 16     16   21 my $self = shift;
100              
101 16 50 33     167 if ( $self->{_in_head1}
      33        
      33        
102             or $self->{_in_head2}
103             or $self->{_in_head3}
104             or $self->{_in_head4} )
105             {
106 0         0 return 1;
107             }
108             }
109              
110             ###############################################################################
111             #
112             # _handle_text()
113             #
114             # Perform any necessary transforms on the text. This is mainly used to escape
115             # inadvertent CamelCase words.
116             #
117             sub _handle_text {
118              
119 60     60   436 my $self = shift;
120 60         83 my $text = $_[0];
121              
122             # Only escape CamelCase in Kwiki paragraphs
123 60 100       134 if ( not $self->{_in_Para} ) {
124 41         70 $self->{_wiki_text} .= $text;
125 41         94 return;
126             }
127              
128             # Split the text into tokens but maintain the whitespace
129 19         97 my @tokens = split /(\s+)/, $text;
130              
131 19         39 for ( @tokens ) {
132 87 100       224 next unless /\S/; # Ignore the whitespace
133 53 50       105 next if m[^(ht|f)tp://]; # Ignore URLs
134 53         102 s/([A-Z][a-z]+[A-Z]\w+)/!$1/g; # Escape with !
135             }
136              
137             # Rejoin the tokens and whitespace.
138 19         79 $self->{_wiki_text} .= join '', @tokens;
139             }
140              
141              
142             ###############################################################################
143             #
144             # Functions to deal with =over ... =back regions for
145             #
146             # Bulleted lists
147             # Numbered lists
148             # Text lists
149             # Block lists
150             #
151 13     13   38 sub _end_item_text { $_[0]->_output( ' ; ' ) }
152              
153              
154             ###############################################################################
155             #
156             # _start_Para()
157             #
158             # Special handling for paragraphs that are part of an "over" block.
159             #
160             sub _start_Para {
161              
162 19     19   63 my $self = shift;
163 19         34 my $indent_level = $self->{_item_indent};
164              
165 19 100       71 if ( $self->{_in_over_block} ) {
166              
167             # Do something here is necessary
168             }
169             }
170              
171              
172             ###############################################################################
173             #
174             # _end_Para()
175             #
176             # Special handling for paragraphs that are part of an "over_text" block.
177             # This is mainly required be Kwiki.
178             #
179             sub _end_Para {
180              
181 19     19   28 my $self = shift;
182              
183             # Only add a newline if the paragraph isn't part of a text.
184 19 100       45 if ( $self->{_in_over_text} ) {
185              
186             # Workaround for the fact that Kwiki doesn't have a definition block.
187             #$self->_output("\n");
188             }
189             else {
190 7         20 $self->_output( "\n" );
191             }
192              
193 19         52 $self->_output( "\n" );
194             }
195              
196              
197             1;
198              
199              
200             __END__