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   284915 use strict;
  6         13  
  6         261  
3 6     6   45 use warnings;
  6         10  
  6         324  
4 6     6   37 use Carp ();
  6         12  
  6         113  
5 6     6   2379 use Pod::Simple::Methody ();
  6         18  
  6         143  
6 6     6   35 use Pod::Simple ();
  6         13  
  6         578  
7             our $VERSION = '3.47';
8             our @ISA = ('Pod::Simple::Methody');
9             BEGIN { *DEBUG = defined(&Pod::Simple::DEBUG)
10             ? \&Pod::Simple::DEBUG
11             : sub() {0}
12 6 50   6   282 }
13              
14             our $FREAKYMODE;
15              
16 6     6   2870 use Text::Wrap 98.112902 ();
  6         18155  
  6         8045  
17              
18             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19              
20             sub new {
21 33     33 1 418499 my $self = shift;
22 33         168 my $new = $self->SUPER::new(@_);
23 33   50     190 $new->{'output_fh'} ||= *STDOUT{IO};
24 33         124 $new->accept_target_as_text(qw( text plaintext plain ));
25 33         119 $new->nix_X_codes(1);
26 33         99 $new->nbsp_for_S(1);
27 33         66 $new->{'Thispara'} = '';
28 33         57 $new->{'Indent'} = 0;
29 33         60 $new->{'Indentstring'} = ' ';
30 33         242 return $new;
31             }
32              
33             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34              
35 3588     3588 0 12086 sub handle_text { $_[0]{'Thispara'} .= $_[1] }
36              
37 807     807 0 2370 sub start_Para { $_[0]{'Thispara'} = '' }
38 45     45 0 154 sub start_head1 { $_[0]{'Thispara'} = '' }
39 98     98 0 298 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 440 sub start_Verbatim { $_[0]{'Thispara'} = '' }
44 58 50   58 0 230 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 1123 sub start_item_text { $_[0]{'Thispara'} = '' }
47              
48 12     12 0 39 sub start_over_bullet { ++$_[0]{'Indent'} }
49 0     0 0 0 sub start_over_number { ++$_[0]{'Indent'} }
50 27     27 0 88 sub start_over_text { ++$_[0]{'Indent'} }
51 0     0 0 0 sub start_over_block { ++$_[0]{'Indent'} }
52              
53 12     12 0 110 sub end_over_bullet { --$_[0]{'Indent'} }
54 0     0 0 0 sub end_over_number { --$_[0]{'Indent'} }
55 27     27 0 237 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 129 sub end_head1 { $_[0]->emit_par(-4) }
62 98     98 0 250 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 1781 sub end_Para { $_[0]->emit_par( 0) }
66 58     58 0 154 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 887 sub end_item_text { $_[0]->emit_par(-2) }
69 124 100   124 0 459 sub start_L { $_[0]{'Link'} = $_[1] if $_[1]->{type} eq 'url' }
70             sub end_L {
71 124 100   124 0 480 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 3166 my($self, $tweak_indent) = splice(@_,0,2);
80 1373   100     5696 my $indent = ' ' x ( 2 * $self->{'Indent'} + 4 + ($tweak_indent||0) );
81             # Yes, 'STRING' x NEGATIVE gives '', same as 'STRING' x 0
82              
83 1373         6125 $self->{'Thispara'} =~ s/$Pod::Simple::shy//g;
84 1373         2763 local $Text::Wrap::huge = 'overflow';
85 1373         4527 my $out = Text::Wrap::wrap($indent, $indent, $self->{'Thispara'} .= "\n");
86 1373         887787 $out =~ s/$Pod::Simple::nbsp/ /g;
87 1373         2363 print {$self->{'output_fh'}} $out, "\n";
  1373         8742  
88 1373         3199 $self->{'Thispara'} = '';
89              
90 1373         5931 return;
91             }
92              
93             # . . . . . . . . . . And then off by its lonesome:
94              
95             sub end_Verbatim {
96 146     146 0 253 my $self = shift;
97 146         673 $self->{'Thispara'} =~ s/$Pod::Simple::nbsp/ /g;
98 146         406 $self->{'Thispara'} =~ s/$Pod::Simple::shy//g;
99              
100 146         474 my $i = ' ' x ( 2 * $self->{'Indent'} + 4);
101             #my $i = ' ' x (4 + $self->{'Indent'});
102              
103 146         1153 $self->{'Thispara'} =~ s/^/$i/mg;
104              
105 146         749 print { $self->{'output_fh'} } '',
106 146         278 $self->{'Thispara'},
107             "\n\n"
108             ;
109 146         278 $self->{'Thispara'} = '';
110 146         391 return;
111             }
112              
113             #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
114             1;
115              
116              
117             __END__