<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 &lt;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>&nbsp;&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;my $body = $c->request->body;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;if ($body) {</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; my $xs = XML::Simple->new('ForceArray' => 0,);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;my $rdata;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;eval {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$rdata = $xs->XMLin( "$body" );</div><div>--- 27,42 ----</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;my $body = $c->request->body;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;if ($body) {</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; my $deserialize_options_ref;</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; if (exists($controller->{'deserialize_options'}))</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; {</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $deserialize_options_ref = $controller->{'deserialize_options'};</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; else</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; {</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $deserialize_options_ref = [ 'ForceArray' => 0 ];</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; my $xs = XML::Simple->new(@$deserialize_options_ref);</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;my $rdata;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;eval {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$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>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if $c->debug;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return 0;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;}</div><div>! &nbsp; &nbsp; my $xs = XML::Simple->new(ForceArray => 0,);</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;my $stash_key = (</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$controller->{'serialize'} ?</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$controller->{'serialize'}->{'stash_key'} :</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$controller->{'stash_key'}&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;) || 'rest';</div><div>&nbsp;&nbsp; &nbsp; &nbsp;my $output;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;eval {</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; $output = $xs->XMLout({ data => $c->stash->{$stash_key} });</div><div>&nbsp;&nbsp; &nbsp; &nbsp;};</div><div>&nbsp;&nbsp; &nbsp; &nbsp;if ($@) {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return $@;</div><div>--- 24,56 ----</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if $c->debug;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return 0;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;}</div><div>! &nbsp; &nbsp; my $serialize_options_ref;</div><div>! &nbsp; &nbsp; if (exists($controller->{'serialize_options'}))</div><div>! &nbsp; &nbsp; {</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; $serialize_options_ref = $controller->{'serialize_options'};</div><div>! &nbsp; &nbsp; }</div><div>! &nbsp; &nbsp; else</div><div>! &nbsp; &nbsp; {</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; $serialize_options_ref = [ 'ForceArray' => 0 ];</div><div>! &nbsp; &nbsp; }</div><div>! &nbsp; &nbsp; my $xs = XML::Simple->new(@$serialize_options_ref);</div><div>&nbsp;&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;my $stash_key = (</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$controller->{'serialize'} ?</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$controller->{'serialize'}->{'stash_key'} :</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$controller->{'stash_key'}&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;) || 'rest';</div><div>+ &nbsp; &nbsp;&nbsp;</div><div>+ &nbsp; &nbsp; # Assumption: if the user chooses to monkey with serialization options,</div><div>+ &nbsp; &nbsp; # they are controlling the output structure precisely. If that's true,</div><div>+ &nbsp; &nbsp; # don't force-wrap the output in "&lt;data>" tags.</div><div>+ &nbsp; &nbsp; my $output_ref = exists($controller->{'serialize_options'}) ?</div><div>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $c->stash->{$stash_key} :</div><div>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { data => $c->stash->{$stash_key} };</div><div>+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;my $output;</div><div>&nbsp;&nbsp; &nbsp; &nbsp;eval {</div><div>! &nbsp; &nbsp; &nbsp; &nbsp; $output = $xs->XMLout( $output_ref );</div><div>&nbsp;&nbsp; &nbsp; &nbsp;};</div><div>&nbsp;&nbsp; &nbsp; &nbsp;if ($@) {</div><div>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;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>