3 package Pod::Simple::DumpAsXML;
6 BEGIN {@ISA = ('Pod::Simple')}
12 BEGIN { *DEBUG = \&Pod::Simple::DEBUG unless defined &DEBUG }
16 my $new = $self->SUPER::new(@_);
17 $new->{'output_fh'} ||= *STDOUT{IO};
18 $new->accept_codes('VerbatimFormatted');
22 #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
24 sub _handle_element_start {
25 # ($self, $element_name, $attr_hash_r)
26 my $fh = $_[0]{'output_fh'};
28 DEBUG and print "++ $_[1]\n";
30 print $fh ' ' x ($_[0]{'indent'} || 0), "<", $_[1];
32 foreach my $key (sort keys %{$_[2]}) {
33 unless($key =~ m/^~/s) {
34 next if $key eq 'start_line' and $_[0]{'hide_line_numbers'};
35 _xml_escape($value = $_[2]{$key});
36 print $fh ' ', $key, '="', $value, '"';
47 DEBUG and print "== \"$_[1]\"\n";
49 my $indent = ' ' x $_[0]{'indent'};
52 $text =~ # A not-totally-brilliant wrapping algorithm:
54 [^\n]{55} # Snare some characters from a line
55 [^\n\ ]{0,50} # and finish any current word
57 \x20{1,10}(?!\n) # capture some spaces not at line-end
58 /$1\n$indent/gx # => line-break here
61 print {$_[0]{'output_fh'}} $indent, $text, "\n";
66 sub _handle_element_end {
67 DEBUG and print "-- $_[1]\n";
68 print {$_[0]{'output_fh'}}
69 ' ' x --$_[0]{'indent'}, "</", $_[1], ">\n";
73 # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
77 # Escape things very cautiously:
78 $x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg;
79 # Yes, stipulate the list without a range, so that this can work right on
80 # all charsets that this module happens to run under.
81 # Altho, hmm, what about that ord? Presumably that won't work right
82 # under non-ASCII charsets. Something should be done about that.
87 #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
94 Pod::Simple::DumpAsXML -- turn Pod into XML
98 perl -MPod::Simple::DumpAsXML -e \
99 "exit Pod::Simple::DumpAsXML->filter(shift)->any_errata_seen" \
104 Pod::Simple::DumpAsXML is a subclass of L<Pod::Simple> that parses Pod
105 and turns it into indented and wrapped XML. This class is of
106 interest to people writing Pod formatters based on Pod::Simple.
108 Pod::Simple::DumpAsXML inherits methods from
114 L<Pod::Simple::XMLOutStream> is rather like this class.
115 Pod::Simple::XMLOutStream's output is space-padded in a way
116 that's better for sending to an XML processor (that is, it has
117 no ignoreable whitespace). But
118 Pod::Simple::DumpAsXML's output is much more human-readable, being
119 (more-or-less) one token per line, with line-wrapping.
121 L<Pod::Simple::DumpAsText> is rather like this class,
122 except that it doesn't dump with XML syntax. Try them and see
123 which one you like best!
125 L<Pod::Simple>, L<Pod::Simple::DumpAsXML>
127 The older libraries L<Pod::PXML>, L<Pod::XML>, L<Pod::SAX>
130 =head1 COPYRIGHT AND DISCLAIMERS
132 Copyright (c) 2002 Sean M. Burke. All rights reserved.
134 This library is free software; you can redistribute it and/or modify it
135 under the same terms as Perl itself.
137 This program is distributed in the hope that it will be useful, but
138 without any warranty; without even the implied warranty of
139 merchantability or fitness for a particular purpose.
143 Sean M. Burke C<sburke@cpan.org>