Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Dev

Proposed patch for XML::Simple ser/deser

 

 

Catalyst dev RSS feed   Index | Next | Previous | View Threaded


brucem at dynamicrange

Apr 3, 2009, 11:27 AM

Post #1 of 2 (959 views)
Permalink
Proposed patch for XML::Simple ser/deser

(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


hdp.perl.catalyst.dev at weftsoar

Apr 3, 2009, 11:31 AM

Post #2 of 2 (891 views)
Permalink
Re: Proposed patch for XML::Simple ser/deser [In reply to]

On Fri, Apr 03, 2009 at 11:27:50AM -0700, Bruce McKenzie wrote:
> Specifically, I needed control over the conversion options for each direction,
> and I need(ed) to have the output data *not* wrapped in <data>.

Knowing the kinds of things people need to do with de/serialization is probably
even more important than patches, but thank you for both; I'll try to take a
look at it this weekend.

hdp.

_______________________________________________
Catalyst-dev mailing list
Catalyst-dev [at] lists
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev

Catalyst dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.