File Coverage

lib/Pod/PseudoPod/Text.pm
Criterion Covered Total %
statement 95 97 97.9
branch 5 8 62.5
condition 3 4 75.0
subroutine 44 46 95.6
pod 1 41 2.4
total 148 196 75.5


line stmt bran cond sub pod time code
1              
2             require 5;
3             package Pod::PseudoPod::Text;
4 1     1   616 use strict;
  1         2  
  1         35  
5 1     1   5 use Carp ();
  1         2  
  1         29  
6 1     1   6 use vars qw( $VERSION $FREAKYMODE );
  1         2  
  1         71  
7             $VERSION = '0.19';
8 1     1   6 use base qw( Pod::PseudoPod );
  1         1  
  1         304  
9              
10 1     1   545 use Text::Wrap 98.112902 ();
  1         2667  
  1         1379  
11             $Text::Wrap::wrap = 'overflow';
12             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13              
14             sub new {
15 26     26 1 14704 my $self = shift;
16 26         80 my $new = $self->SUPER::new(@_);
17 26   50     144 $new->{'output_fh'} ||= *STDOUT{IO};
18 26         76 $new->accept_target_as_text(qw( text plaintext plain ));
19 26         619 $new->accept_targets_as_text( qw(author blockquote comment caution
20             editor epigraph example figure important listing note production
21             programlisting screen sidebar table tip warning) );
22              
23 26         1861 $new->nix_X_codes(1);
24 26         174 $new->nix_Z_codes(1);
25 26         52 $new->nbsp_for_S(1);
26 26         146 $new->codes_in_verbatim(1);
27 26         137 $new->{'scratch'} = '';
28 26         62 $new->{'Indent'} = 0;
29 26         87 $new->{'Indentstring'} = ' ';
30 26         241 return $new;
31             }
32              
33             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34              
35 47     47 0 114 sub handle_text { $_[0]{'scratch'} .= $_[1] }
36              
37 16     16 0 34 sub start_Para { $_[0]{'scratch'} = '' }
38 16     16 0 32 sub end_Para { $_[0]->emit(0) }
39 1     1 0 3 sub start_Verbatim { $_[0]{'scratch'} = '' }
40              
41 1     1 0 4 sub start_head0 { $_[0]{'scratch'} = '' }
42 1     1 0 10 sub end_head0 { $_[0]->emit(-4) }
43 1     1 0 3 sub start_head1 { $_[0]{'scratch'} = '' }
44 1     1 0 4 sub end_head1 { $_[0]->emit(-3) }
45 2     2 0 6 sub start_head2 { $_[0]{'scratch'} = '' }
46 2     2 0 5 sub end_head2 { $_[0]->emit(-2) }
47 1     1 0 3 sub start_head3 { $_[0]{'scratch'} = '' }
48 1     1 0 4 sub end_head3 { $_[0]->emit(-1) }
49 1     1 0 3 sub start_head4 { $_[0]{'scratch'} = '' }
50 1     1 0 4 sub end_head4 { $_[0]->emit(0) }
51              
52 2 50   2 0 7 sub start_item_bullet { $_[0]{'scratch'} = $FREAKYMODE ? '' : '* ' }
53 2     2 0 6 sub end_item_bullet { $_[0]->emit( 0) }
54 2 50   2 0 9 sub start_item_number { $_[0]{'scratch'} = $FREAKYMODE ? '' : "$_[1]{'number'}. " }
55 2     2 0 4 sub end_item_number { $_[0]->emit( 0) }
56 2     2 0 5 sub start_item_text { $_[0]{'scratch'} = '' }
57 2     2 0 8 sub end_item_text { $_[0]->emit(-2) }
58              
59 1     1 0 2 sub start_over_bullet { ++$_[0]{'Indent'} }
60 1     1 0 7 sub end_over_bullet { --$_[0]{'Indent'} }
61 1     1 0 3 sub start_over_number { ++$_[0]{'Indent'} }
62 1     1 0 6 sub end_over_number { --$_[0]{'Indent'} }
63 1     1 0 3 sub start_over_text { ++$_[0]{'Indent'} }
64 1     1 0 7 sub end_over_text { --$_[0]{'Indent'} }
65 0     0 0 0 sub start_over_block { ++$_[0]{'Indent'} }
66 0     0 0 0 sub end_over_block { --$_[0]{'Indent'} }
67              
68 3     3 0 7 sub start_for { ++$_[0]{'Indent'} }
69 3     3 0 9 sub end_for { $_[0]->emit(); --$_[0]{'Indent'} }
  3         7  
70              
71             sub start_sidebar {
72 1     1 0 2 my ($self, $flags) = @_;
73 1         3 $self->{'scratch'} = '';
74 1 50       12 if ($flags->{'title'}) {
75 1         6 $self->{'scratch'} .= "Sidebar: " . $flags->{'title'} . "\n";
76             }
77 1         2 ++$self->{'Indent'};
78 1         4 $self->emit();
79             }
80 1     1 0 4 sub end_sidebar { $_[0]->emit(); --$_[0]{'Indent'} }
  1         3  
81              
82             sub start_table {
83 4     4 0 6 my ($self, $flags) = @_;
84 4         9 $self->{'scratch'} = '';
85 4 100       9 if ($flags->{'title'}) {
86 1         3 $self->{'scratch'} .= "Table: " . $flags->{'title'} . "\n";
87             }
88 4         7 ++$self->{'Indent'};
89             }
90 4     4 0 9 sub end_table { --$_[0]{'Indent'} }
91              
92 10     10 0 20 sub end_cell { $_[0]{'scratch'} .= " | "; }
93 5     5 0 12 sub end_row { $_[0]->emit() }
94              
95 1     1 0 3 sub start_N { $_[0]{'scratch'} .= ' [footnote: '; }
96 1     1 0 2 sub end_N { $_[0]{'scratch'} .= ']'; }
97              
98             sub emit {
99 38     38 0 64 my($self, $tweak_indent) = splice(@_,0,2);
100 38   100     146 my $indent = ' ' x ( 2 * $self->{'Indent'} + 4 + ($tweak_indent||0) );
101             # Yes, 'STRING' x NEGATIVE gives '', same as 'STRING' x 0
102              
103 38         64 $self->{'scratch'} =~ tr{\xAD}{}d if Pod::Simple::ASCII;
104 38         70 my $out = $self->{'scratch'} . "\n";
105 38         86 $out = Text::Wrap::wrap($indent, $indent, $out);
106 38         7561 $out =~ tr{\xA0}{ } if Pod::Simple::ASCII;
107 38         43 print {$self->{'output_fh'}} $out, "\n";
  38         151  
108 38         347 $self->{'scratch'} = '';
109            
110 38         86 return;
111             }
112              
113             # . . . . . . . . . . And then off by its lonesome:
114              
115             sub end_Verbatim {
116 1     1 0 2 my $self = shift;
117 1         16 if(Pod::Simple::ASCII) {
118 1         2 $self->{'scratch'} =~ tr{\xA0}{ };
119 1         2 $self->{'scratch'} =~ tr{\xAD}{}d;
120             }
121              
122 1         3 my $i = ' ' x ( 2 * $self->{'Indent'} + 4);
123             #my $i = ' ' x (4 + $self->{'Indent'});
124            
125 1         14 $self->{'scratch'} =~ s/^/$i/mg;
126            
127 1         5 print { $self->{'output_fh'} } '',
128 1         2 $self->{'scratch'},
129             "\n\n"
130             ;
131 1         11 $self->{'scratch'} = '';
132 1         3 return;
133             }
134              
135             #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
136             1;
137              
138              
139             __END__