Wiki/Muse.pm

filter: Statementstmt 100% 52 / 52 Branchbran 92.8% 13 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 98.7% 77 / 78 CC 8 SCAR 8.0
CC
8
Cov
98%
_indent_item
4.0
_start_L
3.0
_handle_text
2.0
CRAP 2.2
« Wiki/Textile.pm ↑ Summary Wiki/Twiki.pm »
1 package Pod::Simple::Wiki::Muse;
2  
3 ###############################################################################
4 #
5 # Pod::Simple::Wiki::Muse - A class for creating Pod to Muse filters.
6 #
7 #
8 # Copyright 2015, Marco Pessotto melmothx@gmail.com
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 warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 4 @ISA = qw(Pod::Simple::Wiki);
22 4 $VERSION = '0.20';
23  
24 ###############################################################################
25 #
26 # The tag to wiki mappings.
27 #
28 4 my $tags = {
29 '<b>' => '**',
30 '</b>' => '**',
31 '<i>' => '*',
32 '</i>' => '*',
33 '<tt>' => '<code>',
34 '</tt>' => '</code>',
35 '<pre>' => "\n<example>\n",
36 '</pre>' => "\n</example>\n",
37  
38 '<h1>' => "** ",
39 '</h1>' => "\n\n",
40 '<h2>' => "*** ",
41 '</h2>' => "\n\n",
42 '<h3>' => "**** ",
43 '</h3>' => "\n\n",
44 '<h4>' => "***** ",
45 '</h4>' => "\n\n",
46 };
47  
48 ###############################################################################
49 #
50 # new()
51 #
52 # Simple constructor inheriting from Pod::Simple::Wiki.
53 #
54 31 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
55  
56 31 my $class = shift;
57 31 my $self = Pod::Simple::Wiki->new( 'wiki', @_ );
58 31 $self->{_tags} = $tags;
59  
60 31 bless $self, $class;
61 31 return $self;
62 }
63  
64 ###############################################################################
65 #
66 # _indent_item()
67 #
68 # Indents an "over-item" to the correct level.
69 #
70 45 ▶sub _indent_item {
Subroutine _indent_item: called CC=4 SCAR=13.9
71 45 my ($self, $item_type, $param) = @_;
72 # print "Indent level is $self->{_item_indent}\n";
73 45 my $indent_level = $self->{_item_indent} - 1;
74 45 ▶ if ( $item_type eq 'bullet' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($item_type eq 'bullet') { } 14 31 45
elsif ($item_type eq 'number') { } 14 17 31
elsif ($item_type eq 'text') { } 17 0 17
75 14 $self->_append( "\n" . ' ' x $indent_level . ' - ' );
76 }
77 elsif ( $item_type eq 'number' ) {
78 14 $self->_append( "\n" . ' ' x $indent_level . ' 1. ' );
79 }
80 elsif ( $item_type eq 'text' ) {
81 17 $self->_append( "\n" . ' ' x $indent_level . ' ' );
82 }
83 }
84  
85  
86 ###############################################################################
87 #
88 # _handle_text()
89 #
90 # Perform any necessary transforms on the text. This is mainly used to escape
91 # inadvertent CamelCase words.
92 #
93 80 ▶sub _handle_text {
Subroutine _handle_text: called CC=2 SCAR=6.9
94  
95 80 my $self = shift;
96 80 my $text = $_[0];
97  
98 # Only escape words in paragraphs
99 80 ▶ if ( not $self->{_in_Para} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_in_Para"}) 49 31 80
100 49 $self->{_wiki_text} .= $text;
101 49 return;
102 }
103  
104 # Split the text into tokens but maintain the whitespace
105 31 my @tokens = split /(\s+)/, $text;
106  
107 # Portme:
108 # Escape any tokens here, if necessary.
109  
110 # Rejoin the tokens and whitespace.
111 31 $self->{_wiki_text} .= join '', @tokens;
112 }
113  
114  
115 ###############################################################################
116 #
117 # Functions to deal with =over ... =back regions for
118 #
119 # Bulleted lists
120 # Numbered lists
121 # Text lists
122 # Block lists
123 #
124 17 ▶sub _end_item_text {
Subroutine _end_item_text: called CC=1 SCAR=0.0
125 17 my $self = shift;
126 17 my $indent_level = $self->{_item_indent} - 1;
127 17 $self->_output( " :: ");
128 }
129  
130  
131  
132 ###############################################################################
133 #
134 # _start_Para()
135 #
136 # Special handling for paragraphs that are part of an "over" block.
137 #
138 28 ▶sub _start_Para {
Subroutine _start_Para: called CC=2 SCAR=6.9
139  
140 28 my $self = shift;
141 28 my $indent_level = $self->{_item_indent} - 1;
142 28 ▶ if ( $self->{_in_over_block} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_in_over_block"}) 1 27 28
143 1 $self->_append( "\n" . ' ' x $indent_level . ' ' );
144 }
145 }
146  
147 6 ▶sub _start_L {
Subroutine _start_L: called CC=3 SCAR=11.0
148 6 my ($self, $link_attrs) = @_;
149 # print Dumper($link_attrs);
150 # reset the buffer
151 6 $self->_output('');
152 6 $self->{_link_attr} = $link_attrs;
153 6 my $link_target = $link_attrs->{to};
154 6 my $link_section = $link_attrs->{section};
155 6 ▶ $link_target = '' if( !defined($link_target));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $link_target 1 5 6
156  
157 # Handle links that are parsed as Pod links.
158 6 ▶ if ( defined $link_section ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $link_section) 2 4 6
159 2 $link_target = "$link_target#$link_section";
160 }
161 6 $self->_append( "[[$link_target][" );
162 }
163  
164 6 ▶sub _end_L {
Subroutine _end_L: called CC=1 SCAR=0.0
165 6 my $self = shift;
166 6 $self->_output(']]');
167 }
168  
169 4 1;
170  
171  
172 __END__
« Wiki/Textile.pm ↑ Summary Wiki/Twiki.pm »