File Coverage

blib/lib/Pod/Simple/Text.pm
Criterion Covered Total %
statement 66 76 86.8
branch 8 12 66.6
condition 3 4 75.0
subroutine 28 38 73.6
pod 1 31 3.2
total 106 161 65.8


line stmt bran cond sub pod time code
1              
2             require 5;
3             package Pod::Simple::Text;
4 6     6   16008 use strict;
  6         22  
  6         162  
5 6     6   48 use Carp ();
  6         12  
  6         122  
6 6     6   1620 use Pod::Simple::Methody ();
  6         14  
  6         127  
7 6     6   31 use Pod::Simple ();
  6         10  
  6         132  
8 6     6   30 use vars qw( @ISA $VERSION $FREAKYMODE);
  6         11  
  6         585  
9             $VERSION = '3.43';
10             @ISA = ('Pod::Simple::Methody');
11             BEGIN { *DEBUG = defined(&Pod::Simple::DEBUG)
12             ? \&Pod::Simple::DEBUG
13             : sub() {0}
14 6 50   6   167 }
15              
16 6     6   2588 use Text::Wrap 98.112902 ();
  6         12729  
  6         6499  
17             $Text::Wrap::huge = 'overflow';
18              
19             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20              
21             sub new {
22 33     33 1 1422 my $self = shift;
23 33         140 my $new = $self->SUPER::new(@_);
24 33   50     169 $new->{'output_fh'} ||= *STDOUT{IO};
25 33         127 $new->accept_target_as_text(qw( text plaintext plain ));
26 33         96 $new->nix_X_codes(1);
27 33         96 $new->nbsp_for_S(1);
28 33         85 $new->{'Thispara'} = '';
29 33         54 $new->{'Indent'} = 0;
30 33         54 $new->{'Indentstring'} = ' ';
31 33         78 return $new;
32             }
33              
34             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35              
36 3588     3588 0 9710 sub handle_text { $_[0]{'Thispara'} .= $_[1] }
37              
38 807     807 0 2062 sub start_Para { $_[0]{'Thispara'} = '' }
39 45     45 0 141 sub start_head1 { $_[0]{'Thispara'} = '' }
40 98     98 0 296 sub start_head2 { $_[0]{'Thispara'} = '' }
41 0     0 0 0 sub start_head3 { $_[0]{'Thispara'} = '' }
42 0     0 0 0 sub start_head4 { $_[0]{'Thispara'} = '' }
43              
44 146     146 0 421 sub start_Verbatim { $_[0]{'Thispara'} = '' }
45 58 50   58 0 213 sub start_item_bullet { $_[0]{'Thispara'} = $FREAKYMODE ? '' : '* ' }
46 0 0   0 0 0 sub start_item_number { $_[0]{'Thispara'} = $FREAKYMODE ? '' : "$_[1]{'number'}. " }
47 365     365 0 967 sub start_item_text { $_[0]{'Thispara'} = '' }
48              
49 12     12 0 31 sub start_over_bullet { ++$_[0]{'Indent'} }
50 0     0 0 0 sub start_over_number { ++$_[0]{'Indent'} }
51 27     27 0 132 sub start_over_text { ++$_[0]{'Indent'} }
52 0     0 0 0 sub start_over_block { ++$_[0]{'Indent'} }
53              
54 12     12 0 125 sub end_over_bullet { --$_[0]{'Indent'} }
55 0     0 0 0 sub end_over_number { --$_[0]{'Indent'} }
56 27     27 0 207 sub end_over_text { --$_[0]{'Indent'} }
57 0     0 0 0 sub end_over_block { --$_[0]{'Indent'} }
58              
59              
60             # . . . . . Now the actual formatters:
61              
62 45     45 0 142 sub end_head1 { $_[0]->emit_par(-4) }
63 98     98 0 297 sub end_head2 { $_[0]->emit_par(-3) }
64 0     0 0 0 sub end_head3 { $_[0]->emit_par(-2) }
65 0     0 0 0 sub end_head4 { $_[0]->emit_par(-1) }
66 807     807 0 2313 sub end_Para { $_[0]->emit_par( 0) }
67 58     58 0 172 sub end_item_bullet { $_[0]->emit_par( 0) }
68 0     0 0 0 sub end_item_number { $_[0]->emit_par( 0) }
69 365     365 0 911 sub end_item_text { $_[0]->emit_par(-2) }
70 124 100   124 0 460 sub start_L { $_[0]{'Link'} = $_[1] if $_[1]->{type} eq 'url' }
71             sub end_L {
72 124 100   124 0 441 if (my $link = delete $_[0]{'Link'}) {
73             # Append the URL to the output unless it's already present.
74             $_[0]{'Thispara'} .= " <$link->{to}>"
75 9 100       23 unless $_[0]{'Thispara'} =~ /\b\Q$link->{to}/;
76             }
77             }
78              
79             sub emit_par {
80 1373     1373 0 2710 my($self, $tweak_indent) = splice(@_,0,2);
81 1373   100     5688 my $indent = ' ' x ( 2 * $self->{'Indent'} + 4 + ($tweak_indent||0) );
82             # Yes, 'STRING' x NEGATIVE gives '', same as 'STRING' x 0
83              
84 1373         4536 $self->{'Thispara'} =~ s/$Pod::Simple::shy//g;
85 1373         4111 my $out = Text::Wrap::wrap($indent, $indent, $self->{'Thispara'} .= "\n");
86 1373         491501 $out =~ s/$Pod::Simple::nbsp/ /g;
87 1373         2116 print {$self->{'output_fh'}} $out, "\n";
  1373         7061  
88 1373         2609 $self->{'Thispara'} = '';
89            
90 1373         3095 return;
91             }
92              
93             # . . . . . . . . . . And then off by its lonesome:
94              
95             sub end_Verbatim {
96 146     146 0 258 my $self = shift;
97 146         488 $self->{'Thispara'} =~ s/$Pod::Simple::nbsp/ /g;
98 146         412 $self->{'Thispara'} =~ s/$Pod::Simple::shy//g;
99              
100 146         471 my $i = ' ' x ( 2 * $self->{'Indent'} + 4);
101             #my $i = ' ' x (4 + $self->{'Indent'});
102            
103 146         1169 $self->{'Thispara'} =~ s/^/$i/mg;
104            
105 146         661 print { $self->{'output_fh'} } '',
106 146         280 $self->{'Thispara'},
107             "\n\n"
108             ;
109 146         487 $self->{'Thispara'} = '';
110 146         307 return;
111             }
112              
113             #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
114             1;
115              
116              
117             __END__