Wiki/Confluence.pm

filter: Statementstmt 100% 53 / 53 Branchbran 91.6% 11 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 98.6% 75 / 76 CC 7 SCAR 8.1
CC
7
Cov
98%
_indent_item
4.0
_end_L
3.0
_start_Para
2.0
CRAP 2.3
« Wiki/Markdown.pm ↑ Summary Wiki/Textile.pm »
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 ▶use Pod::Simple::Wiki;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19  
20 4 @ISA = qw(Pod::Simple::Wiki);
21 4 $VERSION = '0.20';
22  
23 ###############################################################################
24 #
25 # The tag to wiki mappings.
26 #
27 4 my $tags = {
28 '<b>' => '*',
29 '</b>' => '*',
30 '<i>' => '_',
31 '</i>' => '_',
32 '<tt>' => '{{',
33 '</tt>' => '}}',
34 '<pre>' => "{noformat}\n",
35 '</pre>' => "\n{noformat}\n",
36  
37 '<h1>' => 'h1. ',
38 '</h1>' => "\n\n",
39 '<h2>' => 'h2. ',
40 '</h2>' => "\n\n",
41 '<h3>' => 'h3. ',
42 '</h3>' => "\n\n",
43 '<h4>' => 'h4. ',
44 '</h4>' => "\n\n",
45 };
46  
47 ###############################################################################
48 #
49 # new()
50 #
51 # Simple constructor inheriting from Pod::Simple::Wiki.
52 #
53 27 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
54  
55 27 my $class = shift;
56 27 my $self = Pod::Simple::Wiki->new( 'wiki', @_ );
57 27 $self->{_tags} = $tags;
58  
59 27 bless $self, $class;
60 27 return $self;
61 }
62  
63 ###############################################################################
64 #
65 # _indent_item()
66 #
67 # Indents an "over-item" to the correct level.
68 #
69 37 ▶sub _indent_item {
Subroutine _indent_item: called CC=4 SCAR=13.9
70  
71 37 my $self = shift;
72 37 my $item_type = $_[0];
73 37 my $item_param = $_[1];
74 37 my $indent_level = $self->{_item_indent};
75  
76 37 ▶ if ( $item_type eq 'bullet' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($item_type eq 'bullet') { } 12 25 37
elsif ($item_type eq 'number') { } 12 13 25
elsif ($item_type eq 'text') { } 13 0 13
77 12 $self->_append( '*' x $indent_level . ' ' );
78 }
79 elsif ( $item_type eq 'number' ) {
80 12 $self->_append( '#' x $indent_level . ' ' );
81 }
82  
83 # Confluence doesn't have the equivalent of a <dl> list so we use a
84 # bullet list with a bolded "item" as a workaround.
85 elsif ( $item_type eq 'text' ) {
86 13 $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 65 ▶sub _handle_text {
Subroutine _handle_text: called CC=1 SCAR=0.0
98  
99 65 my $self = shift;
100 65 my $text = $_[0];
101  
102 # Split the text into tokens but maintain the whitespace
103 65 my @tokens = split /(\s+)/, $text;
104  
105 # Escape any tokens here, if necessary.
106 65 @tokens = map { s/([[{*_-])/\\$1/g; $_ } @tokens;
107  
108 # Rejoin the tokens and whitespace.
109 65 $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 ▶sub _end_item_text { $_[0]->_output( '* ' ) }
Subroutine _end_item_text: called CC=1 SCAR=0.0
123  
124  
125 ###############################################################################
126 #
127 # _start_Para()
128 #
129 # Special handling for paragraphs that are part of an "over" block.
130 #
131 23 ▶sub _start_Para {
Subroutine _start_Para: called CC=2 SCAR=6.9
132  
133 23 my $self = shift;
134 23 my $indent_level = $self->{_item_indent};
135  
136 23 ▶ if ( $self->{_in_over_block} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_in_over_block"}) 1 22 23
137 1 $self->_append( 'bq. ' );
138 }
139 }
140  
141  
142 ###############################################################################
143 #
144 # _start_L()
145 #
146 # Handle the start of a link element.
147 #
148 4 ▶sub _start_L {
Subroutine _start_L: called CC=1 SCAR=0.0
149  
150 4 my $self = shift;
151 4 my $link_attrs = shift;
152  
153 4 $self->{_link_attrs} = $link_attrs;
154  
155 # Ouput start of Confluence link and flush the _wiki_text buffer.
156 4 $self->_output( '[' );
157 }
158  
159  
160 ###############################################################################
161 #
162 # _end_L()
163 #
164 # Handle the end of a link element.
165 #
166 4 ▶sub _end_L {
Subroutine _end_L: called CC=3 SCAR=11.0
167  
168 4 my $self = shift;
169 4 my $link_attrs = $self->{_link_attrs};
170 4 my $link_target = $link_attrs->{to};
171 4 my $link_section = $link_attrs->{section};
172  
173 # Handle links that are parsed as Pod links.
174 4 ▶ if ( defined $link_section ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $link_section) 1 3 4
175 1 $link_target = $link_section;
176  
177 # Remove quotes around link name.
178 1 $self->{_wiki_text} =~ s/^"//;
179 1 $self->{_wiki_text} =~ s/"$//;
180 }
181  
182 # Only write [text|link] if text and link are different.
183 4 ▶ if ( $self->{_wiki_text} ne $link_target ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_wiki_text'} ne $link_target) { } 1 3 4
184 1 $self->_append( "|$link_target]" );
185 }
186 else {
187 3 $self->_append( "]" );
188 }
189 }
190  
191  
192 4 1;
193  
194  
195 __END__
« Wiki/Markdown.pm ↑ Summary Wiki/Textile.pm »