[Catalyst-dev] Proposed patch for XML::Simple ser/deser
Bruce McKenzie
brucem at dynamicrange.com
Fri Apr 3 18:27:50 GMT 2009
(I filed a ticket about this, but enhanced the solution since then)
Subject to Hans' comments about big picture moving of Ser/Deser stuff
out, I need(ed) some small extensions to the XML de/serializer to make
it general-purpose.
Specifically, I needed control over the conversion options for each
direction, and I need(ed) to have the output data *not* wrapped in
<data>.
So I put together these mods which extend the capabilities while
maintaining the existing defaults.
Please let me know if they're useful, and if there is anything else
that I can do. I can add some tests and doc if that would help.
Cheers,
Bruce
diff -rc /Library/Perl/5.8.8/Catalyst/Action/Deserialize/XML/Simple.pm
Catalyst/Action/Deserialize/XML/Simple.pm
*** /Library/Perl/5.8.8/Catalyst/Action/Deserialize/XML/Simple.pm
2009-04-03 11:08:17.000000000 -0700
--- Catalyst/Action/Deserialize/XML/Simple.pm 2009-04-02
08:08:42.000000000 -0700
***************
*** 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 -rc /Library/Perl/5.8.8/Catalyst/Action/Serialize/XML/Simple.pm
Catalyst/Action/Serialize/XML/Simple.pm
*** /Library/Perl/5.8.8/Catalyst/Action/Serialize/XML/Simple.pm
2009-04-03 11:08:03.000000000 -0700
--- Catalyst/Action/Serialize/XML/Simple.pm 2009-04-02
08:23:01.000000000 -0700
***************
*** 24,39 ****
if $c->debug;
return 0;
}
! my $xs = XML::Simple->new(ForceArray => 0,);
my $stash_key = (
$controller->{'serialize'} ?
$controller->{'serialize'}->{'stash_key'} :
$controller->{'stash_key'}
) || 'rest';
my $output;
eval {
! $output = $xs->XMLout({ data => $c->stash->{$stash_key} });
};
if ($@) {
return $@;
--- 24,56 ----
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'} ?
$controller->{'serialize'}->{'stash_key'} :
$controller->{'stash_key'}
) || 'rest';
+
+ # Assumption: if the user chooses to monkey with serialization
options,
+ # they are controlling the output structure precisely. If that's
true,
+ # don't force-wrap the output in "<data>" tags.
+ my $output_ref = exists($controller->{'serialize_options'}) ?
+ $c->stash->{$stash_key} :
+ { data => $c->stash->{$stash_key} };
+
my $output;
eval {
! $output = $xs->XMLout( $output_ref );
};
if ($@) {
return $@;
---
Bruce McKenzie
brucem at dynamicrange.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst-dev/attachments/20090403/140d6c15/attachment.htm
More information about the Catalyst-dev
mailing list