1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
use strict;
use warnings;
use Test::More;
{
package DumpAsXML::Enh;
use Pod::Simple::DumpAsXML ();
our @ISA = qw(Pod::Simple::DumpAsXML);
sub new {
my ( $class ) = @_;
my $self = $class->SUPER::new();
$self->code_handler( sub { pop( @_ )->_handle_line( 'code', @_ ); } );
$self->cut_handler( sub { pop( @_ )->_handle_line( 'cut', @_ ); } );
$self->pod_handler( sub { pop( @_ )->_handle_line( 'pod', @_ ); } );
$self->whiteline_handler( sub { pop( @_ )->_handle_line( 'white', @_ ); } );
return $self;
};
sub _handle_line {
my ( $self, $elem, $text, $line ) = @_;
my $fh = $self->{ output_fh };
print { $fh } ' ' x $self->{ indent }, "<$elem start_line=\"$line\"/>\n";
};
}
my $output = '';
my $parser = DumpAsXML::Enh->new();
$parser->output_string( \$output );
my $input = [
'=head1 DESCRIPTION',
'',
' Verbatim paragraph.',
'',
'=cut',
];
my $expected_output = join "\n",
'<Document start_line="1">',
' <head1 start_line="1">',
' DESCRIPTION',
' </head1>',
' <VerbatimFormatted start_line="3" xml:space="preserve">',
' Verbatim paragraph.',
' </VerbatimFormatted>',
' <cut start_line="5"/>',
'</Document>',
'',
;
$parser->parse_lines( @$input, undef );
is($output, $expected_output);
done_testing;
|