<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>(I filed a ticket about this, but enhanced the solution since then)</div><div><br></div><div>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.</div><div><br></div><div>Specifically, I needed control over the conversion options for each direction, and I need(ed) to have the output data *not* wrapped in <data>.</div><div><br></div><div>So I put together these mods which extend the capabilities while maintaining the existing defaults.</div><div><br></div><div>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.</div><div><br></div><div>Cheers,</div><div><br></div><div>Bruce</div><div><br></div><div>diff -rc /Library/Perl/5.8.8/Catalyst/Action/Deserialize/XML/Simple.pm Catalyst/Action/Deserialize/XML/Simple.pm</div><div>*** /Library/Perl/5.8.8/Catalyst/Action/Deserialize/XML/Simple.pm<span class="Apple-tab-span" style="white-space:pre">        </span>2009-04-03 11:08:17.000000000 -0700</div><div>--- Catalyst/Action/Deserialize/XML/Simple.pm<span class="Apple-tab-span" style="white-space:pre">        </span>2009-04-02 08:08:42.000000000 -0700</div><div>***************</div><div>*** 27,33 ****</div><div> </div><div> my $body = $c->request->body;</div><div> if ($body) {</div><div>! my $xs = XML::Simple->new('ForceArray' => 0,);</div><div> my $rdata;</div><div> eval {</div><div> $rdata = $xs->XMLin( "$body" );</div><div>--- 27,42 ----</div><div> </div><div> my $body = $c->request->body;</div><div> if ($body) {</div><div>! my $deserialize_options_ref;</div><div>! if (exists($controller->{'deserialize_options'}))</div><div>! {</div><div>! $deserialize_options_ref = $controller->{'deserialize_options'};</div><div>! }</div><div>! else</div><div>! {</div><div>! $deserialize_options_ref = [ 'ForceArray' => 0 ];</div><div>! }</div><div>! my $xs = XML::Simple->new(@$deserialize_options_ref);</div><div> my $rdata;</div><div> eval {</div><div> $rdata = $xs->XMLin( "$body" );</div><div>diff -rc /Library/Perl/5.8.8/Catalyst/Action/Serialize/XML/Simple.pm Catalyst/Action/Serialize/XML/Simple.pm</div><div>*** /Library/Perl/5.8.8/Catalyst/Action/Serialize/XML/Simple.pm<span class="Apple-tab-span" style="white-space:pre">        </span>2009-04-03 11:08:03.000000000 -0700</div><div>--- Catalyst/Action/Serialize/XML/Simple.pm<span class="Apple-tab-span" style="white-space:pre">        </span>2009-04-02 08:23:01.000000000 -0700</div><div>***************</div><div>*** 24,39 ****</div><div> if $c->debug;</div><div> return 0;</div><div> }</div><div>! my $xs = XML::Simple->new(ForceArray => 0,);</div><div> </div><div> my $stash_key = (</div><div> $controller->{'serialize'} ?</div><div> $controller->{'serialize'}->{'stash_key'} :</div><div> $controller->{'stash_key'} </div><div> ) || 'rest';</div><div> my $output;</div><div> eval {</div><div>! $output = $xs->XMLout({ data => $c->stash->{$stash_key} });</div><div> };</div><div> if ($@) {</div><div> return $@;</div><div>--- 24,56 ----</div><div> if $c->debug;</div><div> return 0;</div><div> }</div><div>! my $serialize_options_ref;</div><div>! if (exists($controller->{'serialize_options'}))</div><div>! {</div><div>! $serialize_options_ref = $controller->{'serialize_options'};</div><div>! }</div><div>! else</div><div>! {</div><div>! $serialize_options_ref = [ 'ForceArray' => 0 ];</div><div>! }</div><div>! my $xs = XML::Simple->new(@$serialize_options_ref);</div><div> </div><div> my $stash_key = (</div><div> $controller->{'serialize'} ?</div><div> $controller->{'serialize'}->{'stash_key'} :</div><div> $controller->{'stash_key'} </div><div> ) || 'rest';</div><div>+ </div><div>+ # Assumption: if the user chooses to monkey with serialization options,</div><div>+ # they are controlling the output structure precisely. If that's true,</div><div>+ # don't force-wrap the output in "<data>" tags.</div><div>+ my $output_ref = exists($controller->{'serialize_options'}) ?</div><div>+ $c->stash->{$stash_key} :</div><div>+ { data => $c->stash->{$stash_key} };</div><div>+ </div><div> my $output;</div><div> eval {</div><div>! $output = $xs->XMLout( $output_ref );</div><div> };</div><div> if ($@) {</div><div> return $@;</div><div><br></div><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>---</div><div>Bruce McKenzie</div><div><a href="mailto:brucem@dynamicrange.com">brucem@dynamicrange.com</a></div><div><br></div></div></span><br class="Apple-interchange-newline"> </div><br></body></html>