File Coverage

blib/lib/Pod/Simple/Wiki/Textile.pm
Criterion Covered Total %
statement 34 34 100.0
branch 9 10 90.0
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 52 53 98.1


line stmt bran cond sub pod time code
1             package Pod::Simple::Wiki::Textile;
2              
3             ###############################################################################
4             #
5             # Pod::Simple::Wiki::Textile - A class for creating Pod to Textile 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   12 use Pod::Simple::Wiki;
  3         3  
  3         83  
16 3     3   9 use strict;
  3         4  
  3         80  
17 3     3   10 use vars qw(@ISA $VERSION);
  3         3  
  3         1183  
18              
19              
20             @ISA = qw(Pod::Simple::Wiki);
21             $VERSION = '0.18';
22              
23             ###############################################################################
24             #
25             # The tag to wiki mappings.
26             #
27             my $tags = {
28             '' => '*',
29             '' => '*',
30             '' => '_',
31             '' => '_',
32             '' => '@',
33             '' => '@',
34             '
'  => "
\n", 
35             '' => "\n\n\n",
36              
37             '

' => 'h1. ',

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

' => 'h2. ',

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

' => 'h3. ',

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

' => 'h4. ',

44             '' => "\n\n",
45             };
46              
47              
48             ###############################################################################
49             #
50             # new()
51             #
52             # Simple constructor inheriting from Pod::Simple::Wiki.
53             #
54             sub new {
55              
56 22     22 1 24 my $class = shift;
57 22         57 my $self = Pod::Simple::Wiki->new( 'wiki', @_ );
58 22         40 $self->{_tags} = $tags;
59              
60 22         31 bless $self, $class;
61 22         50 return $self;
62             }
63              
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   32 my $self = shift;
74 37         30 my $item_type = $_[0];
75 37         29 my $item_param = $_[1];
76 37         35 my $indent_level = $self->{_item_indent};
77              
78 37 100       80 if ( $item_type eq 'bullet' ) {
    100          
    50          
79 12         38 $self->_append( '*' x $indent_level . ' ' );
80             }
81             elsif ( $item_type eq 'number' ) {
82 12         35 $self->_append( '#' x $indent_level . ' ' );
83             }
84             elsif ( $item_type eq 'text' ) {
85 13         25 $self->_append( '- ' );
86             }
87             }
88              
89              
90             ###############################################################################
91             #
92             # _handle_text()
93             #
94             # Perform any necessary transforms on the text. This is mainly used to escape
95             # inadvertent CamelCase words.
96             #
97             sub _handle_text {
98              
99 60     60   310 my $self = shift;
100 60         45 my $text = $_[0];
101              
102             # Only escape words in paragraphs
103 60 100       104 if ( not $self->{_in_Para} ) {
104 41         41 $self->{_wiki_text} .= $text;
105 41         63 return;
106             }
107              
108             # Split the text into tokens but maintain the whitespace
109 19         81 my @tokens = split /(\s+)/, $text;
110              
111             # Escape any tokens here, if necessary.
112              
113             # Rejoin the tokens and whitespace.
114 19         67 $self->{_wiki_text} .= join '', @tokens;
115             }
116              
117              
118             ###############################################################################
119             #
120             # Functions to deal with =over ... =back regions for
121             #
122             # Bulleted lists
123             # Numbered lists
124             # Text lists
125             # Block lists
126             #
127 13     13   24 sub _end_item_text { $_[0]->_output( ' := ' ) }
128              
129              
130             ###############################################################################
131             #
132             # _start_Para()
133             #
134             # Special handling for paragraphs that are part of an "over" block.
135             #
136             sub _start_Para {
137              
138 19     19   33 my $self = shift;
139 19         22 my $indent_level = $self->{_item_indent};
140              
141 19 100       45 if ( $self->{_in_over_block} ) {
142 1         3 $self->_append( 'bq.. ' );
143             }
144             }
145              
146              
147             1;
148              
149              
150             __END__