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