Wiki/Textile.pm

filter: Statementstmt 100% 38 / 38 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 98.2% 56 / 57 CC 6 SCAR 8.0
CC
6
Cov
98%
_indent_item
4.0
_handle_text
2.0
_start_Para
2.0
CRAP 2.2
« Wiki/Confluence.pm ↑ Summary Wiki/Muse.pm »
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 ▶use Pod::Simple::Wiki;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19  
20 3 @ISA = qw(Pod::Simple::Wiki);
21 3 $VERSION = '0.20';
22  
23 ###############################################################################
24 #
25 # The tag to wiki mappings.
26 #
27 3 my $tags = {
28 '<b>' => '*',
29 '</b>' => '*',
30 '<i>' => '_',
31 '</i>' => '_',
32 '<tt>' => '@',
33 '</tt>' => '@',
34 '<pre>' => "<pre>\n",
35 '</pre>' => "\n</pre>\n\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 #
50 # new()
51 #
52 # Simple constructor inheriting from Pod::Simple::Wiki.
53 #
54 22 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
55  
56 22 my $class = shift;
57 22 my $self = Pod::Simple::Wiki->new( 'wiki', @_ );
58 22 $self->{_tags} = $tags;
59  
60 22 bless $self, $class;
61 22 return $self;
62 }
63  
64  
65 ###############################################################################
66 #
67 # _indent_item()
68 #
69 # Indents an "over-item" to the correct level.
70 #
71 37 ▶sub _indent_item {
Subroutine _indent_item: called CC=4 SCAR=13.9
72  
73 37 my $self = shift;
74 37 my $item_type = $_[0];
75 37 my $item_param = $_[1];
76 37 my $indent_level = $self->{_item_indent};
77  
78 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
79 12 $self->_append( '*' x $indent_level . ' ' );
80 }
81 elsif ( $item_type eq 'number' ) {
82 12 $self->_append( '#' x $indent_level . ' ' );
83 }
84 elsif ( $item_type eq 'text' ) {
85 13 $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 60 ▶sub _handle_text {
Subroutine _handle_text: called CC=2 SCAR=6.9
98  
99 60 my $self = shift;
100 60 my $text = $_[0];
101  
102 # Only escape words in paragraphs
103 60 ▶ if ( not $self->{_in_Para} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_in_Para"}) 41 19 60
104 41 $self->{_wiki_text} .= $text;
105 41 return;
106 }
107  
108 # Split the text into tokens but maintain the whitespace
109 19 my @tokens = split /(\s+)/, $text;
110  
111 # Escape any tokens here, if necessary.
112  
113 # Rejoin the tokens and whitespace.
114 19 $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 ▶sub _end_item_text { $_[0]->_output( ' := ' ) }
Subroutine _end_item_text: called CC=1 SCAR=0.0
128  
129  
130 ###############################################################################
131 #
132 # _start_Para()
133 #
134 # Special handling for paragraphs that are part of an "over" block.
135 #
136 19 ▶sub _start_Para {
Subroutine _start_Para: called CC=2 SCAR=6.9
137  
138 19 my $self = shift;
139 19 my $indent_level = $self->{_item_indent};
140  
141 19 ▶ if ( $self->{_in_over_block} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_in_over_block"}) 1 18 19
142 1 $self->_append( 'bq.. ' );
143 }
144 }
145  
146  
147 3 1;
148  
149  
150 __END__
« Wiki/Confluence.pm ↑ Summary Wiki/Muse.pm »