Skip Menu |

This queue is for tickets about the Catalyst-Action-REST CPAN distribution.

Report information
The Basics
Id: 44662
Status: open
Priority: 0/
Queue: Catalyst-Action-REST

People
Owner: Nobody in particular
Requestors: Brucem [...] dynamicrange.com
Cc: bo [...] startsiden.no
ddascalescu+perl [...] gmail.com
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



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'} ?
From: ddascalescu+perl [...] gmail.com
I'm seconding this request. It would be very useful to support, for example, SuppressEmpty => 1 which disables warnings if serialized values are undef. Right now I have to manually iterate through $c->stash->{rest} and delete hash entries that are undef. However, for hashes of hashes, this becomes very clumsy.
I'm also voting for this request. - Bjørn-Olav
Heya guys... There are three votes for this now, so I'd just like to say that I'm entirely unlikely to work on this, as I don't use XML::Simple. As far as I'm concerned, it is significantly too naïve to do XML properly or be particularly useful. It also has a bad habit of generating data it can't round trip... Patches are, of course - welcome, and a method of passing arguments down to serializers would be handy in a number of cases (including a less naïve XML serializer).
Hi, You want to have standarized options? I have made a patch to pass options via the stash, but that might not be the way you want to do it. br, Bjørn-Olav
Subject: xml_simple.diff
--- lib/Catalyst/Action/Serialize/XML/Simple.pm 2010-04-14 10:54:05.000000000 +0200 +++ /Library/Perl/5.8.8/Catalyst/Action/Serialize/XML/Simple.pm 2010-04-13 22:43:26.000000000 +0200 @@ -27,11 +27,7 @@ $controller->{'serialize'}->{'stash_key'} : $controller->{'stash_key'} ) || 'rest'; - - my $data_key = $c->stash->{xml_simple_data_key} || 'data'; - my %config = %{$c->stash->{xml_simple_config}}; - - my $output = $xs->XMLout({ $data_key => $c->stash->{$stash_key} }, %config); + my $output = $xs->XMLout({ data => $c->stash->{$stash_key} }); $c->response->output( $output ); return 1; }
On Wed Apr 14 05:00:43 2010, BOLAV wrote: Show quoted text
> You want to have standarized options? > > I have made a patch to pass options via the stash, but that might not be > the way you want to do it.
No, I want a generic mechanism for passing options to serializers, not an XML::Simple specific one. Also, your patch appears to be backwards :)
From: nebulous
On Wed Apr 14 16:06:58 2010, BOBTFISH wrote: Show quoted text
> On Wed Apr 14 05:00:43 2010, BOLAV wrote:
> > You want to have standarized options? > > > > I have made a patch to pass options via the stash, but that might not be > > the way you want to do it.
> > No, I want a generic mechanism for passing options to serializers, not > an XML::Simple specific one. Also, your patch appears to be backwards :)
I submitted a pull request in github for this a few months ago. I'm assuming it was a case of one of the idots(to quote mst) DoingItWrong, so it wasn't accepted. Has anyone come up with the right way to do this? Regardless of the fragility of relying on XML::Simple for serialization, being able to pass options to serializers seems like a fairly useful thing.
From: icestar [...] inbox.ru
+1 from me to this request. But it seems to me no one is going to accomplish it in the production release.
From: icestar [...] inbox.ru
On Tue Jun 21 05:27:13 2011, Alien wrote: Show quoted text
> +1 from me to this request. But it seems to me no one is going to > accomplish it in the production release.
Please, take a look at my patch for Catalyst/Action/Serialize/XML/ Simple.pm In configuration map we can pass our own options like that: __PACKAGE__->config( default => 'text/xml', map => { 'application/json' => 'JSON', 'text/xml' => ['XML::Simple', { serializer => { NoAttr => 1, RootName => 'data' } }], }, ); Options for deserializer we can pass through 'deserializer' parameter.
Subject: xml_simple3.patch
13c13 < my ( $controller, $c ) = @_; --- > my ( $controller, $c, $data ) = @_; 23c23,25 < my $xs = XML::Simple->new(ForceArray => 0,); --- > my %options = (defined $data and ref($data) eq 'HASH' and ref($data->{serializer}) eq 'HASH') ? > %{$data->{serializer}} : ('ForceArray' => 0); > my $xs = XML::Simple->new(%options); 30c32 < my $output = $xs->XMLout({ data => $c->stash->{$stash_key} }); --- > my $output = $xs->XMLout( $c->stash->{$stash_key} );