File Coverage

blib/lib/Pod/Simple/Vim.pm
Criterion Covered Total %
statement 100 106 94.3
branch 15 30 50.0
condition n/a
subroutine 29 31 93.5
pod 0 27 0.0
total 144 194 74.2


line stmt bran cond sub pod time code
1             package Pod::Simple::Vim;
2            
3 2     2   56876 use strict;
  2         5  
  2         66  
4 2     2   9 use warnings;
  2         3  
  2         59  
5            
6 2     2   2960 use Text::Wrap;
  2         6462  
  2         150  
7            
8             our $VERSION = '0.02';
9            
10 2     2   17 use base 'Pod::Simple::Methody';
  2         5  
  2         2087  
11            
12             my $list_indent_level = 0;
13             my $text_indent_level = 0;
14             my $initial_tab;
15             my $text_bin;
16             my $wrap = 0;
17             my $wrap_text_item = 0;
18             my $first_item;
19            
20            
21             #---------------------------------------------------------------------------
22             # HANDLE VARIOUS TYPES OF TEXT
23             #---------------------------------------------------------------------------
24            
25             #GENERAL TEXT HANDLER
26             sub handle_text
27             {
28 13     13 0 135 my($self, $text) = @_;
29 13 100       25 if ($wrap)
30             {
31 6         22 $text_bin .= $text;
32             } else {
33 7         16 print OUTFH $text;
34             }
35             }
36            
37             #ORDINARY TEXT
38             sub start_Para
39             {
40 1     1 0 172 $wrap = 1;
41 1 50       4 print OUTFH "\n" unless $first_item;
42 1         9 undef $first_item;
43             }
44            
45             sub end_Para
46             {
47 1     1 0 9 $wrap = 0;
48 1 50       7 $initial_tab = "\040\040\040\040"x$list_indent_level if $list_indent_level;
49 1         3 local $Text::Wrap::unexpand = 0;
50             #local $Text::Wrap::columns = 78;
51 1         6 print OUTFH wrap($initial_tab, $initial_tab, $text_bin);
52 1         138 print OUTFH "\n";
53 1         8 undef $text_bin;
54             }
55            
56             #VERBATIM
57             sub start_Verbatim
58             {
59 1     1 0 361 my($self, $attrs) = @_;
60 1         3 print OUTFH ">\n";
61 1         8 $wrap = 1;
62             }
63            
64             sub end_Verbatim
65             {
66 1     1 0 10 my ($self, $attrs) = @_;
67 1         3 $initial_tab = "";
68 1 50       4 $initial_tab = "\040\040\040\040"x$list_indent_level if $list_indent_level;
69 1         4 my @lines = split /\n/, $text_bin;
70 1         5 print OUTFH $initial_tab, $_, "\n" for @lines;
71 1         24 undef $wrap;
72 1         2 undef $text_bin;
73 1         2 print OUTFH "<";
74             }
75            
76             #---------------------------------------------------------------------------
77             # HANDLE HEADINGS
78             #---------------------------------------------------------------------------
79            
80             #HEAD1
81             sub start_head1 {
82 1     1 0 168 my($self, $attrs) = @_;
83 1 50       5 print OUTFH "\n" unless $first_item;
84 1         4 undef $first_item;
85             }
86            
87             sub end_head1 {
88 1     1 0 26 my($self) = @_;
89 1         3 print OUTFH " ~\n";
90             }
91            
92             #HEAD2
93             sub start_head2 {
94 1     1 0 164 my($self, $attrs) = @_;
95 1 50       5 print OUTFH "\n" unless $first_item;
96 1         9 undef $first_item;
97             }
98            
99             sub end_head2 {
100 1     1 0 16 my($self) = @_;
101 1         3 print OUTFH " ~\n";
102             }
103            
104             #HEAD3
105             sub start_head3 {
106 3     3 0 457 my($self, $attrs) = @_;
107 3 50       28 print OUTFH "\n" unless $first_item;
108 3         24 print OUTFH " ";
109 3         21 undef $first_item;
110             }
111            
112             sub end_head3 {
113 3     3 0 47 my($self) = @_;
114 3         8 print OUTFH " ~\n";
115             }
116            
117             #HEAD4
118             sub start_head4 {
119 0     0 0 0 my($self, $attrs) = @_;
120 0 0       0 print OUTFH "\n" unless $first_item;
121 0         0 print OUTFH " ";
122 0         0 undef $first_item;
123             }
124            
125             sub end_head4 {
126 0     0 0 0 my($self) = @_;
127 0         0 print OUTFH " ~\n";
128             }
129            
130             #---------------------------------------------------------------------------
131             # HANDLE LISTS
132             #---------------------------------------------------------------------------
133            
134             #TEXT
135             sub start_over_text {
136 1     1 0 233 my($self, $attrs) = @_;
137 1         3 $list_indent_level++;
138             }
139            
140             sub end_over_text {
141 1     1 0 43 my($self) = @_;
142 1         4 $list_indent_level--;
143             }
144            
145             sub start_item_text {
146 2     2 0 378 my($self, $attrs) = @_;
147 2 50       8 print OUTFH "\n" unless $first_item;
148 2         13 undef $first_item;
149 2         7 print OUTFH "\t"x$list_indent_level;
150             }
151            
152             sub end_item_text {
153 2     2 0 29 my($self) = @_;
154 2         5 print OUTFH "\n";
155             }
156            
157             #BULLET
158             sub start_over_bullet {
159 1     1 0 196 my($self, $attrs) = @_;
160 1         5 $list_indent_level++;
161             }
162            
163             sub end_over_bullet {
164 1     1 0 176 my($self) = @_;
165 1         5 $list_indent_level--;
166             }
167            
168             sub start_item_bullet {
169 2     2 0 431 my($self, $attrs) = @_;
170 2 50       8 print OUTFH "\n" unless $first_item;
171 2         13 undef $first_item;
172 2 50       9 print OUTFH "\t"x($list_indent_level-1) if $list_indent_level;
173 2         14 print OUTFH " * ";
174             #$in_bullet++;
175 2         15 $wrap = 1;
176             }
177            
178             sub end_item_bullet {
179 2     2 0 18 my($self) = @_;
180 2 50       6 $initial_tab = "\040\040\040\040"x$list_indent_level if $list_indent_level;
181 2         3 local $Text::Wrap::unexpand = 0;
182 2         5 print OUTFH wrap("", $initial_tab, $text_bin);
183 2         165 print OUTFH "\n";
184 2         12 undef $text_bin;
185 2         6 undef $wrap;
186             }
187            
188             #NUMBER
189             sub start_over_number {
190 1     1 0 210 my($self, $attrs) = @_;
191 1         3 $list_indent_level++;
192             }
193            
194             sub end_over_number {
195 1     1 0 108 my($self) = @_;
196 1         5 $list_indent_level--;
197             }
198            
199             sub start_item_number {
200 2     2 0 474 my($self, $attrs) = @_;
201 2 50       9 print OUTFH "\n" unless $first_item;
202 2         14 undef $first_item;
203 2 50       9 print OUTFH "\t"x($list_indent_level-1) if $list_indent_level;
204 2         18 print OUTFH " " . $attrs->{'number'} . ". ";
205             #$in_bullet++;
206 2         17 $wrap = 1;
207             }
208            
209             sub end_item_number {
210 2     2 0 16 my($self) = @_;
211 2 50       7 $initial_tab = "\040\040\040\040"x$list_indent_level if $list_indent_level;
212 2         3 local $Text::Wrap::unexpand = 0;
213 2         5 print OUTFH wrap("", $initial_tab, $text_bin);
214 2         171 print OUTFH "\n";
215 2         14 undef $text_bin;
216 2         7 undef $wrap;
217             }
218            
219             #---------------------------------------------------------------------------
220             # VIM MODELINE
221             #---------------------------------------------------------------------------
222            
223             sub start_Document
224             {
225 1     1 0 3286 my $self = shift;
226 1         3 $first_item = 1;
227 1         8 *OUTFH = $self->output_fh();
228             }
229            
230             sub end_Document
231             {
232 1     1 0 50 print OUTFH "\n\nvim:nonu:ts=4:syn=perldoc:noet:lbr:bt=nofile:noma:bh=delete:noswf";
233             }
234            
235             1;
236            
237             __END__