Subject: | Enhance XML::Simple Ser/Deser to support options |
I've found that XML::Simple is sufficient for a wide range of operations
if I have control over the parser options for XMLin and XMLout, but the
Catalyst serializer and deserializer use hard-coded "ForceArray => 0".
Would you consider a small mod to them that permits these parameters to
be set in the application (i.e. controller)?
In support of this, I'm submitting a patch that allows controller-level
setting of the options:
__PACKAGE__->config->{serialize_options} = [qw{ForceArray 1 RootName
response}];
__PACKAGE__->config->{deserialize_options} = [qw{ForceArray 1}];
I left the key generic so that other serializers could be extended to
use this too if that fits.
It does not change the default behavior (ForceArray => 0).
Thanks for a great set of modules!
Subject: | xml-simple.patch |
Only in Catalyst/Action: .DS_Store
Only in Catalyst/Action/Deserialize: .DS_Store
diff -rp orig/Catalyst/Action/Deserialize/XML/Simple.pm Catalyst/Action/Deserialize/XML/Simple.pm
*** orig/Catalyst/Action/Deserialize/XML/Simple.pm 2009-03-27 22:54:32.000000000 -0700
--- Catalyst/Action/Deserialize/XML/Simple.pm 2009-03-29 17:43:47.000000000 -0700
*************** sub execute {
*** 27,33 ****
my $body = $c->request->body;
if ($body) {
! my $xs = XML::Simple->new('ForceArray' => 0,);
my $rdata;
eval {
$rdata = $xs->XMLin( "$body" );
--- 27,42 ----
my $body = $c->request->body;
if ($body) {
! my $deserialize_options_ref;
! if (exists($controller->{'deserialize_options'}))
! {
! $deserialize_options_ref = $controller->{'deserialize_options'};
! }
! else
! {
! $deserialize_options_ref = [ 'ForceArray' => 0 ];
! }
! my $xs = XML::Simple->new(@$deserialize_options_ref);
my $rdata;
eval {
$rdata = $xs->XMLin( "$body" );
diff -rp orig/Catalyst/Action/Serialize/XML/Simple.pm Catalyst/Action/Serialize/XML/Simple.pm
*** orig/Catalyst/Action/Serialize/XML/Simple.pm 2009-03-27 22:54:44.000000000 -0700
--- Catalyst/Action/Serialize/XML/Simple.pm 2009-03-29 18:09:49.000000000 -0700
*************** sub execute {
*** 24,30 ****
if $c->debug;
return 0;
}
! my $xs = XML::Simple->new(ForceArray => 0,);
my $stash_key = (
$controller->{'serialize'} ?
--- 24,39 ----
if $c->debug;
return 0;
}
! my $serialize_options_ref;
! if (exists($controller->{'serialize_options'}))
! {
! $serialize_options_ref = $controller->{'serialize_options'};
! }
! else
! {
! $serialize_options_ref = [ 'ForceArray' => 0 ];
! }
! my $xs = XML::Simple->new(@$serialize_options_ref);
my $stash_key = (
$controller->{'serialize'} ?