summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-11-25 18:03:02 +0100
committerfranck cuny <franck@lumberjaph.net>2010-11-25 18:03:02 +0100
commit90718d02219b79d358a349bd8e342b9f3b0d0115 (patch)
tree9838cbf0579c49e3b8d2abeb07c6e1df220428da
parentadd .gitignore (diff)
downloadnet-http-spore-90718d02219b79d358a349bd8e342b9f3b0d0115.tar.gz
allow XML::Simple options (fperrad)
-rw-r--r--lib/Net/HTTP/Spore/Middleware/Format/XML.pm18
-rw-r--r--t/spore-middleware/format-xml.t2
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/Net/HTTP/Spore/Middleware/Format/XML.pm b/lib/Net/HTTP/Spore/Middleware/Format/XML.pm
index a5a5743..85917ac 100644
--- a/lib/Net/HTTP/Spore/Middleware/Format/XML.pm
+++ b/lib/Net/HTTP/Spore/Middleware/Format/XML.pm
@@ -7,10 +7,24 @@ extends 'Net::HTTP::Spore::Middleware::Format';
 
 use XML::Simple;
 
+my @KnownOptIn     = qw(keyattr keeproot forcecontent contentkey noattr
+                        searchpath forcearray cache suppressempty parseropts
+                        grouptags nsexpand datahandler varattr variables
+                        normalisespace normalizespace valueattr);
+
+my @KnownOptOut    = qw(keyattr keeproot contentkey noattr
+                        rootname xmldecl outputfile noescape suppressempty
+                        grouptags nsexpand handler noindent attrindent nosort
+                        valueattr numericescape);
+
 sub accept_type  { ( 'Accept'       => 'text/xml' ); }
 sub content_type { ( 'Content-Type' => 'text/xml' ) }
-sub encode       { XMLout( $_[1] ) }
-sub decode       { XMLin( $_[1] ) }
+sub encode       { my $mw = $_[0];
+                   my @args = map { $_ => $mw->{$_} } grep { $mw->{$_} } @KnownOptOut;
+                   XMLout( $_[1], @args ) }
+sub decode       { my $mw = $_[0];
+                   my @args = map { $_ => $mw->{$_} } grep { $mw->{$_} } @KnownOptIn;
+                   XMLin( $_[1], @args ) }
 
 1;
 
diff --git a/t/spore-middleware/format-xml.t b/t/spore-middleware/format-xml.t
index 492f564..25fa508 100644
--- a/t/spore-middleware/format-xml.t
+++ b/t/spore-middleware/format-xml.t
@@ -20,7 +20,7 @@ ok my $client =
   Net::HTTP::Spore->new_from_spec( 't/specs/api.json',
     base_url => 'http://localhost:5984' );
 
-$client->enable('Format::XML');
+$client->enable('Format::XML', forcearray => 1, normalizespace => 1);
 $client->enable( 'Mock', tests => $mock_server );
 
 my $res = $client->get_info();