1 2require 5; 3package Pod::Simple::DumpAsText; 4$VERSION = '3.20'; 5use Pod::Simple (); 6BEGIN {@ISA = ('Pod::Simple')} 7 8use strict; 9 10use Carp (); 11 12BEGIN { *DEBUG = \&Pod::Simple::DEBUG unless defined &DEBUG } 13 14sub new { 15 my $self = shift; 16 my $new = $self->SUPER::new(@_); 17 $new->{'output_fh'} ||= *STDOUT{IO}; 18 $new->accept_codes('VerbatimFormatted'); 19 return $new; 20} 21 22#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 23 24sub _handle_element_start { 25 # ($self, $element_name, $attr_hash_r) 26 my $fh = $_[0]{'output_fh'}; 27 my($key, $value); 28 DEBUG and print "++ $_[1]\n"; 29 30 print $fh ' ' x ($_[0]{'indent'} || 0), "++", $_[1], "\n"; 31 $_[0]{'indent'}++; 32 while(($key,$value) = each %{$_[2]}) { 33 unless($key =~ m/^~/s) { 34 next if $key eq 'start_line' and $_[0]{'hide_line_numbers'}; 35 _perly_escape($key); 36 _perly_escape($value); 37 printf $fh qq{%s \\ "%s" => "%s"\n}, 38 ' ' x ($_[0]{'indent'} || 0), $key, $value; 39 } 40 } 41 return; 42} 43 44sub _handle_text { 45 DEBUG and print "== \"$_[1]\"\n"; 46 47 if(length $_[1]) { 48 my $indent = ' ' x $_[0]{'indent'}; 49 my $text = $_[1]; 50 _perly_escape($text); 51 $text =~ # A not-totally-brilliant wrapping algorithm: 52 s/( 53 [^\n]{55} # Snare some characters from a line 54 [^\n\ ]{0,50} # and finish any current word 55 ) 56 \x20{1,10}(?!\n) # capture some spaces not at line-end 57 /$1"\n$indent . "/gx # => line-break here 58 ; 59 60 print {$_[0]{'output_fh'}} $indent, '* "', $text, "\"\n"; 61 } 62 return; 63} 64 65sub _handle_element_end { 66 DEBUG and print "-- $_[1]\n"; 67 print {$_[0]{'output_fh'}} 68 ' ' x --$_[0]{'indent'}, "--", $_[1], "\n"; 69 return; 70} 71 72# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 74sub _perly_escape { 75 foreach my $x (@_) { 76 $x =~ s/([^\x00-\xFF])/sprintf'\x{%X}',ord($1)/eg; 77 # Escape things very cautiously: 78 $x =~ s/([^-\n\t \&\<\>\'!\#\%\(\)\*\+,\.\/\:\;=\?\~\[\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/sprintf'\x%02X',ord($1)/eg; 79 } 80 return; 81} 82 83#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 841; 85 86 87__END__ 88 89=head1 NAME 90 91Pod::Simple::DumpAsText -- dump Pod-parsing events as text 92 93=head1 SYNOPSIS 94 95 perl -MPod::Simple::DumpAsText -e \ 96 "exit Pod::Simple::DumpAsText->filter(shift)->any_errata_seen" \ 97 thingy.pod 98 99=head1 DESCRIPTION 100 101This class is for dumping, as text, the events gotten from parsing a Pod 102document. This class is of interest to people writing Pod formatters 103based on Pod::Simple. It is useful for seeing exactly what events you 104get out of some Pod that you feed in. 105 106This is a subclass of L<Pod::Simple> and inherits all its methods. 107 108=head1 SEE ALSO 109 110L<Pod::Simple::DumpAsXML> 111 112L<Pod::Simple> 113 114=head1 SUPPORT 115 116Questions or discussion about POD and Pod::Simple should be sent to the 117pod-people@perl.org mail list. Send an empty email to 118pod-people-subscribe@perl.org to subscribe. 119 120This module is managed in an open GitHub repository, 121L<http://github.com/theory/pod-simple/>. Feel free to fork and contribute, or 122to clone L<git://github.com/theory/pod-simple.git> and send patches! 123 124Patches against Pod::Simple are welcome. Please send bug reports to 125<bug-pod-simple@rt.cpan.org>. 126 127=head1 COPYRIGHT AND DISCLAIMERS 128 129Copyright (c) 2002 Sean M. Burke. 130 131This library is free software; you can redistribute it and/or modify it 132under the same terms as Perl itself. 133 134This program is distributed in the hope that it will be useful, but 135without any warranty; without even the implied warranty of 136merchantability or fitness for a particular purpose. 137 138=head1 AUTHOR 139 140Pod::Simple was created by Sean M. Burke <sburke@cpan.org>. 141But don't bother him, he's retired. 142 143Pod::Simple is maintained by: 144 145=over 146 147=item * Allison Randal C<allison@perl.org> 148 149=item * Hans Dieter Pearcey C<hdp@cpan.org> 150 151=item * David E. Wheeler C<dwheeler@cpan.org> 152 153=back 154 155=cut 156