#!/usr/bin/perl -w use strict; use XML::Twig; foreach my $module ( qw( XML::Simple Test::More Data::Dumper YAML) ) { if( eval "require $module") { import $module; } else { print "1..1\nok 1\n"; warn "skipping: $module is not installed\n"; exit; } } if( $XML::Simple::VERSION < 2.09) { print "1..1\nok 1\n"; warn "skipping: need XML::Simple 2.09 or above\n"; exit; } undef $XML::Simple::PREFERRED_PARSER; $XML::Simple::PREFERRED_PARSER= 'XML::Parser'; $/="\n\n"; my @doc= ; my @options= ( { }, { content_key => 'foo' }, { group_tags => { templates => 'template'} }, { group_tags => { dirs => 'dir', templates => 'template'} }, { forcearray => 1 }, { forcearray => [ qw(server) ] }, { noattr => 1, }, { noattr => 0, }, { content_key => 'mycontent' }, { content_key => '-mycontent' }, { var_attr => 'var' }, { var_attr => 'var', var_regexp => qr/\$\{?(\w+)\}?/ }, { variables => { var => 'foo' } }, { keyattr => [ qw(name)] }, { keyattr => [ 'name' ] }, { keyattr => [ qw(foo bar)] }, { keyattr => {server => 'name' } }, { keyattr => {server => '+name' } }, { keyattr => {server => '-name' } }, { normalize_space => 1 }, { normalise_space => 2 }, { group_tags => { f1_ar => 'f1' } }, { group_tags => { f1_ar => 'f1', f2_ar => 'f2'} }, ); plan( tests => @options * @doc); $SIG{__WARN__} = sub { }; foreach my $doc (@doc) { foreach my $options (@options) { (my $options_text= Dumper( $options))=~ s{\s*\n\s*}{ }g; $options_text=~ s{^\$VAR1 = }{}; my( $options_twig, $options_simple)= UNIVERSAL::isa( $options, 'ARRAY') ? @$options : ($options, $options); my $t = XML::Twig->new->parse( $doc); my $twig = $t->root->simplify( %$options_twig); my $doc_name = $t->root->att( 'doc'); delete $options_simple->{var_regexp}; my $simple = XMLin( $doc, %$options_simple); my $res=is_deeply( $twig, $simple, "doc: $doc_name - options: $options_text" ); #. Dump( {twig => $twig, simple => $simple})); exit unless( $res); } } exit 0; __DATA__
10.0.0.101
10.0.1.101
10.0.0.102
10.0.0.103
10.0.1.103
localhost /home/mrodrigu/standards ${base}/tools foovar is ${var} text with spaces text with spaces text with spaces text with spaces f1 1f1 2 f2 1f2 2