File Coverage

blib/lib/Pod/Simple/Wiki/Tiddlywiki.pm
Criterion Covered Total %
statement 36 36 100.0
branch 12 14 85.7
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 57 59 96.6


line stmt bran cond sub pod time code
1             package Pod::Simple::Wiki::Tiddlywiki;
2              
3             ###############################################################################
4             #
5             # Pod::Simple::Wiki::Tiddlywiki - A class for creating Pod to Tiddlywiki filters.
6             #
7             #
8             # Copyright 2007, Ron Savage, ron@savage.net.au
9             #
10             # Documentation after __END__
11             #
12              
13             # perltidy with the following options: -mbl=2 -pt=0 -nola
14              
15 4     4   20 use Pod::Simple::Wiki;
  4         8  
  4         122  
16 4     4   18 use strict;
  4         7  
  4         97  
17 4     4   19 use vars qw(@ISA $VERSION);
  4         5  
  4         2369  
18              
19              
20             @ISA = qw(Pod::Simple::Wiki);
21             $VERSION = '0.19';
22              
23             ###############################################################################
24             #
25             # The tag to wiki mappings.
26             #
27             my $tags = {
28             '' => q(''),
29             '' => q(''),
30             '' => '//',
31             '' => '//',
32             '' => '{{{',
33             '' => '}}}',
34             '
'  => "{{{\n", 
35             '' => "\n}}}\n\n",
36              
37             '

' => '!',

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

' => '!!',

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

' => '!!!',

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

' => '!!!!',

44             '' => "\n",
45             };
46              
47             ###############################################################################
48             #
49             # new()
50             #
51             # Simple constructor inheriting from Pod::Simple::Wiki.
52             #
53             sub new {
54              
55 46     46 1 66 my $class = shift;
56 46         147 my $self = Pod::Simple::Wiki->new( 'wiki', @_ );
57 46         87 $self->{_tags} = $tags;
58              
59 46         76 bless $self, $class;
60 46         138 return $self;
61             }
62              
63             # How Pod "=over" blocks are converted to Tiddlywiki wiki lists.
64              
65             ###############################################################################
66             #
67             # _indent_item()
68             #
69             # Indents an "over-item" to the correct level.
70             #
71             sub _indent_item {
72              
73 37     37   49 my $self = shift;
74 37         47 my $item_type = $_[0];
75 37         53 my $item_param = $_[1];
76 37         49 my $indent_level = $self->{_item_indent};
77              
78 37 100       108 if ( $item_type eq 'bullet' ) {
    100          
    50          
79 12         77 $self->_append( '*' x $indent_level . ' ' );
80             }
81             elsif ( $item_type eq 'number' ) {
82 12         41 $self->_append( '#' x $indent_level . ' ' );
83             }
84              
85             # TiddlyWiki doesn't have the equivalent of a
list so we use a
86             # bullet list as a workaround.
87             elsif ( $item_type eq 'text' ) {
88 13         47 $self->_append( '*' x $indent_level . ' ' );
89             }
90             }
91              
92             ###############################################################################
93             #
94             # _handle_text()
95             #
96             # Perform any necessary transforms on the text. This is mainly used to escape
97             # inadvertent CamelCase words.
98             #
99             sub _handle_text {
100              
101 86     86   657 my $self = shift;
102 86         117 my $text = $_[0];
103              
104             # Split the text into tokens but maintain the whitespace
105 86         376 my @tokens = split /(\s+)/, $text;
106              
107              
108             # Escape any tokens here, if necessary.
109 86         164 for ( @tokens ) {
110 276 100       778 next unless /\S/; # Ignore the whitespace
111              
112             # Escape WikiWords with ~, unless in varbatim section.
113 181 50       362 next if $self->{_in_Verbatim};
114 181 100       328 next if $self->{_in_C};
115              
116             # Escape WikiWords RT#60650
117 179         382 s/(?
118              
119             # Escape TiddlyWiki formating sequences RT#60304
120 179         421 s[(([-/'_^~@<>])\2+)][{{{$1}}}]g;
121             }
122              
123             # Rejoin the tokens and whitespace.
124 86         369 $self->{_wiki_text} .= join '', @tokens;
125             }
126              
127             ###############################################################################
128             #
129             # Functions to deal with =over ... =back regions for
130             #
131             # Bulleted lists
132             # Numbered lists
133             # Text lists
134             # Block lists
135             #
136              
137             # TiddlyWiki doesn't have the equivalent of a
list so we use a
138             # bullet list as a workaround.
139 13     13   34 sub _end_item_text { $_[0]->_output( ' ' ) }
140              
141              
142             ###############################################################################
143             #
144             # _start_Para()
145             #
146             # Special handling for paragraphs that are part of an "over" block.
147             #
148             sub _start_Para {
149              
150 43     43   87 my $self = shift;
151 43         70 my $indent_level = $self->{_item_indent};
152              
153 43 100       151 if ( $self->{_in_over_block} ) {
154              
155             # Do something here if necessary
156             }
157             }
158              
159              
160             1;
161              
162              
163             __END__