blib/lib/Pod/Simple/Wiki/Googlecode.pm

filter: Statementstmt 86.4% 51 / 59 Branchbran 57.6% 15 / 26 Conditioncond 16.6% 3 / 18 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 64.5% 80 / 124 CC 21 SCAR 29.1
CC
21
Cov
67%
_start_Para
50.5
_skip_headings
9.7
_handle_text
5.0
CRAP 18.4
↑ Summary
1 package Pod::Simple::Wiki::Googlecode;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 @ISA = qw(Pod::Simple::Wiki);
8 4 $VERSION = '0.03';
9  
10 ###############################################################################
11 #
12 # The tag to wiki mappings.
13 #
14 4 my $tags = {
15 '<b>' => '*',
16 '</b>' => '*',
17 '<i>' => '_',
18 '</i>' => '_',
19 '<tt>' => '`',
20 '</tt>' => '`',
21 '<pre>' => "{{{\n",
22 '</pre>' => "\n}}}\n\n",
23  
24 '<h1>' => "\n----\n= ",
25 '</h1>' => " =\n\n",
26 '<h2>' => "\n== ",
27 '</h2>' => " ==\n\n",
28 '<h3>' => "\n=== ",
29 '</h3>' => " ===\n\n",
30 '<h4>' => "==== ",
31 '</h4>' => "\n\n",
32 };
33  
34  
35 ###############################################################################
36 #
37 # new()
38 #
39 # Simple constructor inheriting from Pod::Simple::Wiki.
40 #
41 20 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
42  
43 20 my $class = shift;
44 20 my $self = Pod::Simple::Wiki->new('wiki', @_);
45 20 $self->{_tags} = $tags;
46  
47 20 bless $self, $class;
48 20 return $self;
49 }
50  
51  
52 ###############################################################################
53 #
54 # _indent_item()
55 #
56 # Indents an "over-item" to the correct level.
57 #
58 36 ▶sub _indent_item {
Subroutine _indent_item: called CC=4 SCAR=13.9
59  
60 36 my $self = shift;
61 36 my $item_type = $_[0];
62 36 my $item_param = $_[1];
63 36 my $indent_level = $self->{_item_indent};
64  
65 36 ▶ if ($item_type eq 'bullet') {
Branch: 3 branches
BranchTrueFalseTotal
if ($item_type eq 'bullet') { } 12 24 36
elsif ($item_type eq 'number') { } 12 12 24
elsif ($item_type eq 'text') { } 12 0 12
66 12 $self->_append(' ' x $indent_level . '* ');
67 }
68 elsif ($item_type eq 'number') {
69 12 $self->_append(' ' x $indent_level . '# ');
70 }
71 elsif ($item_type eq 'text') {
72 12 $self->_append('==' . '=' x $indent_level . ' ');
73 12 $self->{_googlecode_list} = 1;
74 12 $self->{_googlecode_num} = $indent_level + 2;
75 }
76 }
77  
78  
79 ###############################################################################
80 #
81 # _skip_headings()
82 #
83 # Formatting in headings doesn't look great or is ignored in some formats.
84 #
85 16 ▶sub _skip_headings {
Subroutine _skip_headings: called CC=5 SCAR=22.7
86  
87 16 my $self = shift;
88  
89 16 ▶ if ($self->{_in_head1} or
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_in_head1"} or $self->{"_in_head2"} or $self->{"_in_head3"} or $self->{"_in_head4"}) 0 16 16
Condition33%3/9
$self->{"_in_head1"} or $self->{"_in_head2"} or $self->{"_in_head3"} or $self->{"_in_head4"}
l!l&&r!l&&!r
0016
$self->{"_in_head1"} or $self->{"_in_head2"} or $self->{"_in_head3"}
l!l&&r!l&&!r
0016
$self->{"_in_head1"} or $self->{"_in_head2"}
l!l&&r!l&&!r
0016
MC/DC0%0/4
$self->{"_in_head1"} or $self->{"_in_head2"} or $self->{"_in_head3"} or $self->{"_in_head4"}
$self->{"_in_head1"} $self->{"_in_head2"} $self->{"_in_head3"} $self->{"_in_head4"}
Truth table20%1/5
A or B or C or D
A= $self->{"_in_head1"}B= $self->{"_in_head2"}C= $self->{"_in_head3"}D= $self->{"_in_head4"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
90 $self->{_in_head2} or
91 $self->{_in_head3} or
92 $self->{_in_head4})
93 {
94 0 return 1;
95 }
96 }
97  
98 ###############################################################################
99 #
100 # _handle_text()
101 #
102 # Perform any necessary transforms on the text. This is mainly used to escape
103 # inadvertent CamelCase words.
104 #
105 58 ▶sub _handle_text {
Subroutine _handle_text: called CC=5 SCAR=16.1
106  
107 58 my $self = shift;
108 58 my $text = $_[0];
109  
110 # Only escape CamelCase in GoogleCode Wiki paragraphs
111 58 ▶ if (not $self->{_in_Para}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_in_Para"}) 40 18 58
112 40 $self->{_wiki_text} .= $text;
113 40 return;
114 }
115  
116 # Split the text into tokens but maintain the whitespace
117 18 my @tokens = split /(\s+)/, $text;
118  
119 18 for (@tokens) {
120 64 ▶ next unless /\S/; # Ignore the whitespace
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ 23 41 64
121 41 ▶ next if m[^(ht|f)tp://]; # Ignore URLs
Branch: 1 branch
BranchTrueFalseTotal
if m[^(ht|f)tp://] 0 41 41
122 41 s/([A-Z][a-z]+[A-Z]\w+)/!$1/g; # Escape with !
123 }
124  
125 # Rejoin the tokens and whitespace.
126 18 $self->{_wiki_text} .= join '', @tokens;
127 }
128  
129  
130 ###############################################################################
131 #
132 # Functions to deal with =over ... =back regions for
133 #
134 # Bulleted lists
135 # Numbered lists
136 # Text lists
137 # Block lists
138 #
139 12 ▶sub _end_item_text {
Subroutine _end_item_text: called CC=1 SCAR=0.0
140 12 $_[0]->_output(' ' . '=' x $_[0]->{_googlecode_num} . "\n");
141 12 $_[0]->{_googlecode_list} = 0;
142 }
143  
144  
145 ###############################################################################
146 #
147 # _start_Para()
148 #
149 # Special handling for paragraphs that are part of an "over" block.
150 #
151 18 ▶sub _start_Para {
Subroutine _start_Para: called CC=9 SCAR=39.2
152  
153 18 my $self = shift;
154 18 my $indent_level = $self->{_item_indent};
155  
156 18 ▶ if ($self->{_in_over_block}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_in_over_block"}) 0 18 18
157 # Do something here is necessary
158 }
159
160 18 ▶ if ($self->{_googlecode_list}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_googlecode_list"}) 0 18 18
161 0 ▶ if (not $self->{_in_over_text} and $self->{_googlecode_list} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"_in_over_text"} and $self->{"_googlecode_list"} == 1) 0 0 0
Condition0%0/3
not $self->{"_in_over_text"} and $self->{"_googlecode_list"} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->{"_in_over_text"} and $self->{"_googlecode_list"} == 1
not $self->{"_in_over_text"} $self->{"_googlecode_list"} == 1
Truth table0%0/3
not(A) and B
A= not $self->{"_in_over_text"}B= $self->{"_googlecode_list"} == 1
ABresult
0X0
100
111
162 0 $self->_append("\n");
163 }
164  
165 0 ▶ if ($self->{_in_over_text} and $self->{_googlecode_list} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_in_over_text"} and $self->{"_googlecode_list"} == 2) 0 0 0
Condition0%0/3
$self->{"_in_over_text"} and $self->{"_googlecode_list"} == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_in_over_text"} and $self->{"_googlecode_list"} == 2
$self->{"_in_over_text"} $self->{"_googlecode_list"} == 2
Truth table0%0/3
A and B
A= $self->{"_in_over_text"}B= $self->{"_googlecode_list"} == 2
ABresult
0X0
100
111
166 0 $self->_append("\n");
167 }
168  
169 0 ▶ if (not ($self->{_in_over_text} and $self->{_googlecode_list} == 1)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_in_over_text"} and $self->{"_googlecode_list"} == 1) 0 0 0
Condition0%0/3
$self->{"_in_over_text"} and $self->{"_googlecode_list"} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_in_over_text"} and $self->{"_googlecode_list"} == 1
$self->{"_in_over_text"} $self->{"_googlecode_list"} == 1
Truth table0%0/3
A and B
A= $self->{"_in_over_text"}B= $self->{"_googlecode_list"} == 1
ABresult
0X0
100
111
170 0 $self->_append(' ' x $indent_level);
171 }
172  
173 0 $self->{_googlecode_list}++;
174 }
175 }
176  
177  
178 ###############################################################################
179 #
180 # _end_Para()
181 #
182 # Special handling for paragraphs that are part of an "over_text" block.
183 # This is mainly required be Kwiki.
184 #
185 18 ▶sub _end_Para {
Subroutine _end_Para: called CC=2 SCAR=6.9
186  
187 18 my $self = shift;
188  
189 # Only add a newline if the paragraph isn't part of a text.
190 18 ▶ if ($self->{_in_over_text}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_in_over_text'}) { } 12 6 18
191 # Workaround for the fact that Kwiki doesn't have a definition block.
192 #$self->_output("\n");
193 }
194 else {
195 6 $self->_output("\n");
196 }
197  
198 18 $self->_output("\n")
199 }
200  
201 4 1;
202 __END__
↑ Summary