1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More;
7
8BEGIN {
9    eval { require Test::Deep; };
10    plan skip_all => 'Fails with Can\'t locate object method "print" via package "IO::File" at t/github_issue_79.t line 33' if $] le 5.012005;
11    plan skip_all => 'Need Test::Deep to test' if $@;
12    Test::Deep->import('cmp_deeply');
13}
14
15{
16package DumpAsXML::Enh;
17
18use parent 'Pod::Simple::DumpAsXML';
19
20sub new {
21    my ( $class ) = @_;
22    my $self = $class->SUPER::new();
23    $self->code_handler( sub { pop( @_ )->_handle_line( 'code', @_ ); } );
24    $self->cut_handler( sub { pop( @_ )->_handle_line( 'cut', @_ ); } );
25    $self->pod_handler( sub { pop( @_ )->_handle_line( 'pod', @_ ); } );
26    $self->whiteline_handler( sub { pop( @_ )->_handle_line( 'white', @_ ); } );
27    return $self;
28};
29
30sub _handle_line {
31    my ( $self, $elem, $text, $line ) = @_;
32    my $fh = $self->{ output_fh };
33    $fh->print( '  ' x $self->{ indent }, "<$elem start_line=\"$line\"/>\n" );
34};
35
36}
37
38my $output = '';
39my $parser = DumpAsXML::Enh->new();
40$parser->output_string( \$output );
41
42my $input = [
43    '=head1 DESCRIPTION',
44    '',
45    '    Verbatim paragraph.',
46    '',
47    '=cut',
48];
49my $expected_output = [
50    '<Document start_line="1">',
51    '  <head1 start_line="1">',
52    '    DESCRIPTION',
53    '  </head1>',
54    '  <VerbatimFormatted start_line="3" xml:space="preserve">',
55    '        Verbatim paragraph.',
56    '  </VerbatimFormatted>',
57    '  <cut start_line="5"/>',
58    '</Document>',
59];
60
61$parser->parse_lines( @$input, undef );
62
63my $actual_output = [ split( "\n", $output ) ];
64cmp_deeply( $actual_output, $expected_output ) or do {
65    diag( 'actual output:' );
66    diag( "|$_" ) for @$actual_output;
67    diag( 'expected output:' );
68    diag( "|$_" ) for @$expected_output;
69};
70
71done_testing;
72exit( 0 );
73
74