File Coverage

blib/lib/Pod/Simple/Wiki/Confluence.pm
Criterion Covered Total %
statement 49 49 100.0
branch 11 12 91.6
condition n/a
subroutine 10 10 100.0
pod 1 1 100.0
total 71 72 98.6


line stmt bran cond sub pod time code
1             package Pod::Simple::Wiki::Confluence;
2              
3             ###############################################################################
4             #
5             # Pod::Simple::Wiki::Confluence - A class for creating Pod to Confluence 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 4     4   20 use Pod::Simple::Wiki;
  4         5  
  4         128  
16 4     4   17 use strict;
  4         5  
  4         143  
17 4     4   17 use vars qw(@ISA $VERSION);
  4         4  
  4         2606  
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             '
'  => "{noformat}\n", 
35             '' => "\n{noformat}\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             # new()
50             #
51             # Simple constructor inheriting from Pod::Simple::Wiki.
52             #
53             sub new {
54              
55 27     27 1 38 my $class = shift;
56 27         78 my $self = Pod::Simple::Wiki->new( 'wiki', @_ );
57 27         51 $self->{_tags} = $tags;
58              
59 27         40 bless $self, $class;
60 27         68 return $self;
61             }
62              
63             ###############################################################################
64             #
65             # _indent_item()
66             #
67             # Indents an "over-item" to the correct level.
68             #
69             sub _indent_item {
70              
71 37     37   30 my $self = shift;
72 37         31 my $item_type = $_[0];
73 37         30 my $item_param = $_[1];
74 37         34 my $indent_level = $self->{_item_indent};
75              
76 37 100       77 if ( $item_type eq 'bullet' ) {
    100          
    50          
77 12         32 $self->_append( '*' x $indent_level . ' ' );
78             }
79             elsif ( $item_type eq 'number' ) {
80 12         34 $self->_append( '#' x $indent_level . ' ' );
81             }
82              
83             # Confluence doesn't have the equivalent of a
list so we use a
84             # bullet list with a bolded "item" as a workaround.
85             elsif ( $item_type eq 'text' ) {
86 13         31 $self->_append( '*' x $indent_level . ' *' );
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 65     65   344 my $self = shift;
100 65         64 my $text = $_[0];
101              
102             # Split the text into tokens but maintain the whitespace
103 65         270 my @tokens = split /(\s+)/, $text;
104              
105             # Escape any tokens here, if necessary.
106 65         81 @tokens = map { s/([[{*_-])/\\$1/g; $_ } @tokens;
  265         220  
  265         357  
107              
108             # Rejoin the tokens and whitespace.
109 65         208 $self->{_wiki_text} .= join '', @tokens;
110             }
111              
112              
113             ###############################################################################
114             #
115             # Functions to deal with =over ... =back regions for
116             #
117             # Bulleted lists
118             # Numbered lists
119             # Text lists
120             # Block lists
121             #
122 13     13   26 sub _end_item_text { $_[0]->_output( '* ' ) }
123              
124              
125             ###############################################################################
126             #
127             # _start_Para()
128             #
129             # Special handling for paragraphs that are part of an "over" block.
130             #
131             sub _start_Para {
132              
133 23     23   39 my $self = shift;
134 23         28 my $indent_level = $self->{_item_indent};
135              
136 23 100       68 if ( $self->{_in_over_block} ) {
137 1         3 $self->_append( 'bq. ' );
138             }
139             }
140              
141              
142             ###############################################################################
143             #
144             # _start_L()
145             #
146             # Handle the start of a link element.
147             #
148             sub _start_L {
149              
150 4     4   6 my $self = shift;
151 4         4 my $link_attrs = shift;
152              
153 4         8 $self->{_link_attrs} = $link_attrs;
154              
155             # Ouput start of Confluence link and flush the _wiki_text buffer.
156 4         18 $self->_output( '[' );
157             }
158              
159              
160             ###############################################################################
161             #
162             # _end_L()
163             #
164             # Handle the end of a link element.
165             #
166             sub _end_L {
167              
168 4     4   5 my $self = shift;
169 4         6 my $link_attrs = $self->{_link_attrs};
170 4         6 my $link_target = $link_attrs->{to};
171 4         7 my $link_section = $link_attrs->{section};
172              
173             # Handle links that are parsed as Pod links.
174 4 100       10 if ( defined $link_section ) {
175 1         3 $link_target = $link_section;
176              
177             # Remove quotes around link name.
178 1         6 $self->{_wiki_text} =~ s/^"//;
179 1         5 $self->{_wiki_text} =~ s/"$//;
180             }
181              
182             # Only write [text|link] if text and link are different.
183 4 100       17 if ( $self->{_wiki_text} ne $link_target ) {
184 1         18 $self->_append( "|$link_target]" );
185             }
186             else {
187 3         62 $self->_append( "]" );
188             }
189             }
190              
191              
192             1;
193              
194              
195             __END__