File Coverage

blib/lib/Pod/Simple/Text.pm
Criterion Covered Total %
statement 67 77 87.0
branch 8 12 66.6
condition 3 4 75.0
subroutine 28 38 73.6
pod 1 31 3.2
total 107 162 66.0


line stmt bran cond sub pod time code
1             package Pod::Simple::Text;
2 6     6   174827 use strict;
  6         9  
  6         196  
3 6     6   35 use warnings;
  6         10  
  6         267  
4 6     6   27 use Carp ();
  6         9  
  6         66  
5 6     6   1411 use Pod::Simple::Methody ();
  6         13  
  6         94  
6 6     6   24 use Pod::Simple ();
  6         10  
  6         469  
7             our $VERSION = '3.48';
8             our @ISA = ('Pod::Simple::Methody');
9             BEGIN { *DEBUG = defined(&Pod::Simple::DEBUG)
10             ? \&Pod::Simple::DEBUG
11             : sub() {0}
12 6 50   6   239 }
13              
14             our $FREAKYMODE;
15              
16 6     6   1962 use Text::Wrap 98.112902 ();
  6         11781  
  6         5760  
17              
18             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19              
20             sub new {
21 33     33 1 284599 my $self = shift;
22 33         153 my $new = $self->SUPER::new(@_);
23 33   50     174 $new->{'output_fh'} ||= *STDOUT{IO};
24 33         99 $new->accept_target_as_text(qw( text plaintext plain ));
25 33         110 $new->nix_X_codes(1);
26 33         166 $new->nbsp_for_S(1);
27 33         68 $new->{'Thispara'} = '';
28 33         121 $new->{'Indent'} = 0;
29 33         52 $new->{'Indentstring'} = ' ';
30 33         125 return $new;
31             }
32              
33             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34              
35 3588     3588 0 7907 sub handle_text { $_[0]{'Thispara'} .= $_[1] }
36              
37 807     807 0 1607 sub start_Para { $_[0]{'Thispara'} = '' }
38 45     45 0 96 sub start_head1 { $_[0]{'Thispara'} = '' }
39 98     98 0 221 sub start_head2 { $_[0]{'Thispara'} = '' }
40 0     0 0 0 sub start_head3 { $_[0]{'Thispara'} = '' }
41 0     0 0 0 sub start_head4 { $_[0]{'Thispara'} = '' }
42              
43 146     146 0 289 sub start_Verbatim { $_[0]{'Thispara'} = '' }
44 58 50   58 0 144 sub start_item_bullet { $_[0]{'Thispara'} = $FREAKYMODE ? '' : '* ' }
45 0 0   0 0 0 sub start_item_number { $_[0]{'Thispara'} = $FREAKYMODE ? '' : "$_[1]{'number'}. " }
46 365     365 0 739 sub start_item_text { $_[0]{'Thispara'} = '' }
47              
48 12     12 0 25 sub start_over_bullet { ++$_[0]{'Indent'} }
49 0     0 0 0 sub start_over_number { ++$_[0]{'Indent'} }
50 27     27 0 56 sub start_over_text { ++$_[0]{'Indent'} }
51 0     0 0 0 sub start_over_block { ++$_[0]{'Indent'} }
52              
53 12     12 0 73 sub end_over_bullet { --$_[0]{'Indent'} }
54 0     0 0 0 sub end_over_number { --$_[0]{'Indent'} }
55 27     27 0 170 sub end_over_text { --$_[0]{'Indent'} }
56 0     0 0 0 sub end_over_block { --$_[0]{'Indent'} }
57              
58              
59             # . . . . . Now the actual formatters:
60              
61 45     45 0 140 sub end_head1 { $_[0]->emit_par(-4) }
62 98     98 0 180 sub end_head2 { $_[0]->emit_par(-3) }
63 0     0 0 0 sub end_head3 { $_[0]->emit_par(-2) }
64 0     0 0 0 sub end_head4 { $_[0]->emit_par(-1) }
65 807     807 0 1316 sub end_Para { $_[0]->emit_par( 0) }
66 58     58 0 106 sub end_item_bullet { $_[0]->emit_par( 0) }
67 0     0 0 0 sub end_item_number { $_[0]->emit_par( 0) }
68 365     365 0 662 sub end_item_text { $_[0]->emit_par(-2) }
69 124 100   124 0 326 sub start_L { $_[0]{'Link'} = $_[1] if $_[1]->{type} eq 'url' }
70             sub end_L {
71 124 100   124 0 292 if (my $link = delete $_[0]{'Link'}) {
72             # Append the URL to the output unless it's already present.
73             $_[0]{'Thispara'} .= " <$link->{to}>"
74 9 100       18 unless $_[0]{'Thispara'} =~ /\b\Q$link->{to}/;
75             }
76             }
77              
78             sub emit_par {
79 1373     1373 0 2456 my($self, $tweak_indent) = splice(@_,0,2);
80 1373   100     3963 my $indent = ' ' x ( 2 * $self->{'Indent'} + 4 + ($tweak_indent||0) );
81             # Yes, 'STRING' x NEGATIVE gives '', same as 'STRING' x 0
82              
83 1373         4171 $self->{'Thispara'} =~ s/$Pod::Simple::shy//g;
84 1373         1899 local $Text::Wrap::huge = 'overflow';
85 1373         3089 my $out = Text::Wrap::wrap($indent, $indent, $self->{'Thispara'} .= "\n");
86 1373         580805 $out =~ s/$Pod::Simple::nbsp/ /g;
87 1373         1762 print {$self->{'output_fh'}} $out, "\n";
  1373         5741  
88 1373         2073 $self->{'Thispara'} = '';
89              
90 1373         3772 return;
91             }
92              
93             # . . . . . . . . . . And then off by its lonesome:
94              
95             sub end_Verbatim {
96 146     146 0 172 my $self = shift;
97 146         399 $self->{'Thispara'} =~ s/$Pod::Simple::nbsp/ /g;
98 146         335 $self->{'Thispara'} =~ s/$Pod::Simple::shy//g;
99              
100 146         311 my $i = ' ' x ( 2 * $self->{'Indent'} + 4);
101             #my $i = ' ' x (4 + $self->{'Indent'});
102              
103 146         846 $self->{'Thispara'} =~ s/^/$i/mg;
104              
105 146         495 print { $self->{'output_fh'} } '',
106 146         191 $self->{'Thispara'},
107             "\n\n"
108             ;
109 146         224 $self->{'Thispara'} = '';
110 146         264 return;
111             }
112              
113             #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
114             1;
115              
116              
117             __END__