[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 2 require 5; 3 package Pod::Simple::Text; 4 use strict; 5 use Carp (); 6 use Pod::Simple::Methody (); 7 use Pod::Simple (); 8 use vars qw( @ISA $VERSION $FREAKYMODE); 9 $VERSION = '2.02'; 10 @ISA = ('Pod::Simple::Methody'); 11 BEGIN { *DEBUG = defined(&Pod::Simple::DEBUG) 12 ? \&Pod::Simple::DEBUG 13 : sub() {0} 14 } 15 16 use Text::Wrap 98.112902 (); 17 $Text::Wrap::wrap = 'overflow'; 18 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 19 20 sub new { 21 my $self = shift; 22 my $new = $self->SUPER::new(@_); 23 $new->{'output_fh'} ||= *STDOUT{IO}; 24 $new->accept_target_as_text(qw( text plaintext plain )); 25 $new->nix_X_codes(1); 26 $new->nbsp_for_S(1); 27 $new->{'Thispara'} = ''; 28 $new->{'Indent'} = 0; 29 $new->{'Indentstring'} = ' '; 30 return $new; 31 } 32 33 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 34 35 sub handle_text { $_[0]{'Thispara'} .= $_[1] } 36 37 sub start_Para { $_[0]{'Thispara'} = '' } 38 sub start_head1 { $_[0]{'Thispara'} = '' } 39 sub start_head2 { $_[0]{'Thispara'} = '' } 40 sub start_head3 { $_[0]{'Thispara'} = '' } 41 sub start_head4 { $_[0]{'Thispara'} = '' } 42 43 sub start_Verbatim { $_[0]{'Thispara'} = '' } 44 sub start_item_bullet { $_[0]{'Thispara'} = $FREAKYMODE ? '' : '* ' } 45 sub start_item_number { $_[0]{'Thispara'} = $FREAKYMODE ? '' : "$_[1]{'number'}. " } 46 sub start_item_text { $_[0]{'Thispara'} = '' } 47 48 sub start_over_bullet { ++$_[0]{'Indent'} } 49 sub start_over_number { ++$_[0]{'Indent'} } 50 sub start_over_text { ++$_[0]{'Indent'} } 51 sub start_over_block { ++$_[0]{'Indent'} } 52 53 sub end_over_bullet { --$_[0]{'Indent'} } 54 sub end_over_number { --$_[0]{'Indent'} } 55 sub end_over_text { --$_[0]{'Indent'} } 56 sub end_over_block { --$_[0]{'Indent'} } 57 58 59 # . . . . . Now the actual formatters: 60 61 sub end_head1 { $_[0]->emit_par(-4) } 62 sub end_head2 { $_[0]->emit_par(-3) } 63 sub end_head3 { $_[0]->emit_par(-2) } 64 sub end_head4 { $_[0]->emit_par(-1) } 65 sub end_Para { $_[0]->emit_par( 0) } 66 sub end_item_bullet { $_[0]->emit_par( 0) } 67 sub end_item_number { $_[0]->emit_par( 0) } 68 sub end_item_text { $_[0]->emit_par(-2) } 69 70 sub emit_par { 71 my($self, $tweak_indent) = splice(@_,0,2); 72 my $indent = ' ' x ( 2 * $self->{'Indent'} + 4 + ($tweak_indent||0) ); 73 # Yes, 'STRING' x NEGATIVE gives '', same as 'STRING' x 0 74 75 $self->{'Thispara'} =~ tr{\xAD}{}d if Pod::Simple::ASCII; 76 my $out = Text::Wrap::wrap($indent, $indent, $self->{'Thispara'} .= "\n"); 77 $out =~ tr{\xA0}{ } if Pod::Simple::ASCII; 78 print {$self->{'output_fh'}} $out, "\n"; 79 $self->{'Thispara'} = ''; 80 81 return; 82 } 83 84 # . . . . . . . . . . And then off by its lonesome: 85 86 sub end_Verbatim { 87 my $self = shift; 88 if(Pod::Simple::ASCII) { 89 $self->{'Thispara'} =~ tr{\xA0}{ }; 90 $self->{'Thispara'} =~ tr{\xAD}{}d; 91 } 92 93 my $i = ' ' x ( 2 * $self->{'Indent'} + 4); 94 #my $i = ' ' x (4 + $self->{'Indent'}); 95 96 $self->{'Thispara'} =~ s/^/$i/mg; 97 98 print { $self->{'output_fh'} } '', 99 $self->{'Thispara'}, 100 "\n\n" 101 ; 102 $self->{'Thispara'} = ''; 103 return; 104 } 105 106 #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 107 1; 108 109 110 __END__ 111 112 =head1 NAME 113 114 Pod::Simple::Text -- format Pod as plaintext 115 116 =head1 SYNOPSIS 117 118 perl -MPod::Simple::Text -e \ 119 "exit Pod::Simple::Text->filter(shift)->any_errata_seen" \ 120 thingy.pod 121 122 =head1 DESCRIPTION 123 124 This class is a formatter that takes Pod and renders it as 125 wrapped plaintext. 126 127 Its wrapping is done by L<Text::Wrap>, so you can change 128 C<$Text::Wrap::columns> as you like. 129 130 This is a subclass of L<Pod::Simple> and inherits all its methods. 131 132 =head1 SEE ALSO 133 134 L<Pod::Simple>, L<Pod::Simple::TextContent>, L<Pod::Text> 135 136 =head1 COPYRIGHT AND DISCLAIMERS 137 138 Copyright (c) 2002 Sean M. Burke. All rights reserved. 139 140 This library is free software; you can redistribute it and/or modify it 141 under the same terms as Perl itself. 142 143 This program is distributed in the hope that it will be useful, but 144 without any warranty; without even the implied warranty of 145 merchantability or fitness for a particular purpose. 146 147 =head1 AUTHOR 148 149 Sean M. Burke C<sburke@cpan.org> 150 151 =cut 152
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Mar 17 22:47:18 2015 | Cross-referenced by PHPXref 0.7.1 |