File Coverage

lib/Pod/PseudoPod/Checker.pm
Criterion Covered Total %
statement 52 84 61.9
branch 11 18 61.1
condition 3 4 75.0
subroutine 18 37 48.6
pod 2 31 6.4
total 86 174 49.4


line stmt bran cond sub pod time code
1              
2             # A quite dimwitted pod2plaintext that need only know how to format whatever
3             # text comes out of Pod::BlackBox's _gen_errata
4              
5             package Pod::PseudoPod::Checker;
6 1     1   600 use strict;
  1         2  
  1         48  
7 1     1   6 use vars qw( $VERSION );
  1         2  
  1         95  
8             $VERSION = '0.19';
9 1     1   7 use Carp ();
  1         2  
  1         27  
10 1     1   5 use base qw( Pod::PseudoPod );
  1         2  
  1         295  
11             BEGIN { *DEBUG = defined(&Pod::PseudoPod::DEBUG)
12             ? \&Pod::PseudoPod::DEBUG
13             : sub() {0}
14 1 50   1   30 }
15              
16 1     1   624 use Text::Wrap 98.112902 (); # was 2001.0131, but I don't think we need that
  1         2657  
  1         1144  
17             $Text::Wrap::wrap = 'overflow';
18             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19              
20             sub any_errata_seen { # read-only accessor
21 0     0 1 0 return $_[1]->{'Errata_seen'};
22             }
23              
24             sub new {
25 2     2 1 1004 my $self = shift;
26 2         13 my $new = $self->SUPER::new(@_);
27 2   50     21 $new->{'output_fh'} ||= *STDOUT{IO};
28 2         10 $new->accept_targets_as_text( qw(author blockquote comment caution
29             editor epigraph example figure important note production
30             programlisting screen sidebar table tip warning) );
31 2         154 $new->nix_X_codes(1);
32 2         16 $new->nbsp_for_S(1);
33 2         10 $new->{'scratch'} = '';
34 2         4 $new->{'Indent'} = 0;
35 2         4 $new->{'Indentstring'} = ' ';
36 2         2 $new->{'Errata_seen'} = 0;
37 2         14 return $new;
38             }
39              
40             #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41              
42 6 100   6 0 20 sub handle_text { $_[0]{'Errata_seen'} and $_[0]{'scratch'} .= $_[1] }
43              
44 3     3 0 8 sub start_Para { $_[0]{'scratch'} = '' }
45              
46             sub start_head1 {
47 1 50   1 0 3 if($_[0]{'Errata_seen'}) {
48 0         0 $_[0]{'scratch'} = '';
49             } else {
50 1 50       3 if($_[1]{'errata'}) { # start of errata!
51 1         2 $_[0]{'Errata_seen'} = 1;
52 1 50       5 $_[0]{'scratch'} = $_[0]{'source_filename'} ?
53             "$_[0]{'source_filename'} -- " : ''
54             }
55             }
56             }
57 0     0 0 0 sub start_head2 { $_[0]{'scratch'} = '' }
58 0     0 0 0 sub start_head3 { $_[0]{'scratch'} = '' }
59 0     0 0 0 sub start_head4 { $_[0]{'scratch'} = '' }
60              
61 0     0 0 0 sub start_Verbatim { $_[0]{'scratch'} = '' }
62 0     0 0 0 sub start_item_bullet { $_[0]{'scratch'} = '* ' }
63 0     0 0 0 sub start_item_number { $_[0]{'scratch'} = "$_[1]{'number'}. " }
64 1     1 0 4 sub start_item_text { $_[0]{'scratch'} = '' }
65              
66 0     0 0 0 sub start_over_bullet { ++$_[0]{'Indent'} }
67 0     0 0 0 sub start_over_number { ++$_[0]{'Indent'} }
68 1     1 0 2 sub start_over_text { ++$_[0]{'Indent'} }
69 0     0 0 0 sub start_over_block { ++$_[0]{'Indent'} }
70              
71 0     0 0 0 sub end_over_bullet { --$_[0]{'Indent'} }
72 0     0 0 0 sub end_over_number { --$_[0]{'Indent'} }
73 1     1 0 7 sub end_over_text { --$_[0]{'Indent'} }
74 0     0 0 0 sub end_over_block { --$_[0]{'Indent'} }
75              
76              
77             # . . . . . Now the actual formatters:
78              
79 1     1 0 3 sub end_head1 { $_[0]->emit(-4) }
80 0     0 0 0 sub end_head2 { $_[0]->emit(-3) }
81 0     0 0 0 sub end_head3 { $_[0]->emit(-2) }
82 0     0 0 0 sub end_head4 { $_[0]->emit(-1) }
83 3     3 0 7 sub end_Para { $_[0]->emit( 0) }
84 0     0 0 0 sub end_item_bullet { $_[0]->emit( 0) }
85 0     0 0 0 sub end_item_number { $_[0]->emit( 0) }
86 1     1 0 3 sub end_item_text { $_[0]->emit(-2) }
87              
88             sub emit {
89 5 100   5 0 18 return unless $_[0]{'Errata_seen'};
90 4         7 my($self, $tweak_indent) = splice(@_,0,2);
91 4   100     23 my $indent_length = ( 2 * $self->{'Indent'} + ($tweak_indent||0) );
92              
93             # Yes, 'STRING' x NEGATIVE gives '', same as 'STRING' x 0
94 4 100       10 my $indent = $indent_length > 0 ? ' ' x $indent_length : '';
95              
96 4         8 $self->{'scratch'} =~ tr{\xAD}{}d if Pod::Simple::ASCII;
97 4         11 my $out = Text::Wrap::wrap($indent, $indent, $self->{'scratch'} .= "\n");
98 4         838 $out =~ tr{\xA0}{ } if Pod::Simple::ASCII;
99 4         7 print {$self->{'output_fh'}} $out,
  4         68  
100             ;
101 4         45 $self->{'scratch'} = '';
102              
103 4         11 return;
104             }
105              
106             # . . . . . . . . . . And then off by its lonesome:
107              
108             sub end_Verbatim {
109 0 0   0 0 0 return unless $_[0]{'Errata_seen'};
110 0         0 my $self = shift;
111 0         0 if(Pod::Simple::ASCII) {
112 0         0 $self->{'scratch'} =~ tr{\xA0}{ };
113 0         0 $self->{'scratch'} =~ tr{\xAD}{}d;
114             }
115              
116 0         0 my $i = ' ' x ( 2 * $self->{'Indent'} + 4);
117            
118 0         0 $self->{'scratch'} =~ s/^/$i/mg;
119            
120 0         0 print { $self->{'output_fh'} } '',
121 0         0 $self->{'scratch'},
122             "\n\n"
123             ;
124 0         0 $self->{'scratch'} = '';
125 0         0 return;
126             }
127              
128             sub end_Document {
129 1     1 0 2 my ($self) = @_;
130 1 50       4 return if $self->{'Errata_seen'};
131 0           print { $self->{'output_fh'} } "\tNo errors seen!\n";
  0            
132             }
133              
134             #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
135             1;
136              
137             __END__