File Coverage

blib/lib/Pod/Simple/DumpAsXML.pm
Criterion Covered Total %
statement 52 54 96.3
branch 8 10 80.0
condition 6 7 85.7
subroutine 11 11 100.0
pod 1 1 100.0
total 78 83 93.9


line stmt bran cond sub pod time code
1              
2             require 5;
3             package Pod::Simple::DumpAsXML;
4             $VERSION = '3.43';
5 29     29   243440 use Pod::Simple ();
  29         100  
  29         991  
6 29     29   1276 BEGIN {@ISA = ('Pod::Simple')}
7              
8 29     29   195 use strict;
  29         63  
  29         572  
9              
10 29     29   141 use Carp ();
  29         56  
  29         627  
11 29     29   16100 use Text::Wrap qw(wrap);
  29         73972  
  29         2185  
12              
13 29 50   29   19203 BEGIN { *DEBUG = \&Pod::Simple::DEBUG unless defined &DEBUG }
14              
15             sub new {
16 149     149 1 21330 my $self = shift;
17 149         524 my $new = $self->SUPER::new(@_);
18 149   50     805 $new->{'output_fh'} ||= *STDOUT{IO};
19 149         487 $new->accept_codes('VerbatimFormatted');
20 149         453 $new->keep_encoding_directive(1);
21 149         303 return $new;
22             }
23              
24             #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
25              
26             sub _handle_element_start {
27             # ($self, $element_name, $attr_hash_r)
28 801     801   1399 my $fh = $_[0]{'output_fh'};
29 801         1154 my($key, $value);
30 801         1015 DEBUG and print STDERR "++ $_[1]\n";
31            
32 801   100     4253 print $fh ' ' x ($_[0]{'indent'} || 0), "<", $_[1];
33              
34 801         1353 foreach my $key (sort keys %{$_[2]}) {
  801         3004  
35 1050 100       2595 unless($key =~ m/^~/s) {
36 921 100 100     3329 next if $key eq 'start_line' and $_[0]{'hide_line_numbers'};
37 647         1766 _xml_escape($value = $_[2]{$key});
38 647         1641 print $fh ' ', $key, '="', $value, '"';
39             }
40             }
41              
42              
43 801         2017 print $fh ">\n";
44 801         1509 $_[0]{'indent'}++;
45 801         1552 return;
46             }
47              
48             sub _handle_text {
49 625     625   789 DEBUG and print STDERR "== \"$_[1]\"\n";
50 625 100       1511 if(length $_[1]) {
51 624         1360 my $indent = ' ' x $_[0]{'indent'};
52 624         1026 my $text = $_[1];
53 624         1340 _xml_escape($text);
54 624         1036 local $Text::Wrap::huge = 'overflow';
55 624         1672 $text = wrap('', $indent, $text);
56 624         252951 print {$_[0]{'output_fh'}} $indent, $text, "\n";
  624         2552  
57             }
58 625         2105 return;
59             }
60              
61             sub _handle_element_end {
62 801     801   1048 DEBUG and print STDERR "-- $_[1]\n";
63 801         2723 print {$_[0]{'output_fh'}}
64 801         1053 ' ' x --$_[0]{'indent'}, "\n";
65 801         1666 return;
66             }
67              
68             # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
69              
70             sub _xml_escape {
71 1271     1271   1890 foreach my $x (@_) {
72             # Escape things very cautiously:
73 1271 50       5013 if ($] ge 5.007_003) {
74 1271         3769 $x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(utf8::native_to_unicode(ord($1))).';'/eg;
  6872         16732  
75             } else { # Is broken for non-ASCII platforms on early perls
76 0         0 $x =~ s/([^-\n\t !\#\$\%\(\)\*\+,\.\~\/\:\;=\?\@\[\\\]\^_\`\{\|\}abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789])/'&#'.(ord($1)).';'/eg;
  0         0  
77             }
78             # Yes, stipulate the list without a range, so that this can work right on
79             # all charsets that this module happens to run under.
80             }
81 1271         1927 return;
82             }
83              
84             #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
85             1;
86              
87             __END__