Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the XML-Quick CPAN distribution.

Report information
The Basics
Id: 22020
Status: resolved
Priority: 0/
Queue: XML-Quick

People
Owner: ROBN [...] cpan.org
Requestors: HIO [...] cpan.org
Cc:
AdminCc:

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



Subject: xml() drops _attrs in original hash
xml() drops _attrs in original hash. this breaks reuse of that object.
Subject: XML-Quick-0.02.keep_object.patch
diff -urN XML-Quick-0.02.orig/lib/XML/Quick.pm XML-Quick-0.02.keep_object/lib/XML/Quick.pm --- XML-Quick-0.02.orig/lib/XML/Quick.pm 2006-07-03 07:37:28.000000000 +0900 +++ XML-Quick-0.02.keep_object/lib/XML/Quick.pm 2006-10-11 11:05:50.390170313 +0900 @@ -25,6 +25,7 @@ # make sure we have some options, even if we don't $opts = {} if not defined $opts or reftype $opts ne 'HASH'; + $opts = {%$opts}; # shallow copy. # escape by default $opts->{escape} = 1 if not exists $opts->{escape}; @@ -41,12 +42,10 @@ # move attrs/cdata into opts as necessary if(exists $data->{_attrs}) { $opts->{attrs} = $data->{_attrs} if not exists $opts->{attrs}; - delete $data->{_attrs}; } if(exists $data->{_cdata}) { $opts->{cdata} = $data->{_cdata} if not exists $opts->{cdata}; - delete $data->{cdata}; } # loop over the keys
Subject: v003_keep_object.t
#! /usr/bin/perl -w ## ---------------------------------------------------------------------------- # t/v003_keep_object.t # ----------------------------------------------------------------------------- # $Id$ # ----------------------------------------------------------------------------- use strict; use warnings; use Test::More tests => 9; use XML::Quick; use Data::Dumper; &test_001_keep_attrs; &test_002_keep_opts_hash; &test_003_keep_cdata_tag; # ----------------------------------------------------------------------------- # $text = _dump($hash); # sub _dump { my $hash = shift; local($Data::Dumper::Terse) = 1; local($Data::Dumper::Indent) = 1; Dumper($hash); } # ----------------------------------------------------------------------------- # test_001_keep_attrs. # sub test_001_keep_attrs { my $hash = { root => { _attrs => { attr=>'value', }, }, }; my $hash_orig = _dump($hash); my $dump = q{<root attr='value'/>}; is( _dump($hash), $hash_orig, "[keep attrs] before calling xml()." ); is( xml($hash), $dump, "[keep attrs] 1st call of xml()." ); is( _dump($hash), $hash_orig, "[keep attrs] after calling xml()." ); is( xml($hash), $dump, "[keep attrs] 2nd call of xml()." ); } # ----------------------------------------------------------------------------- # test_002_keep_opts_hash. # sub test_002_keep_opts_hash { my $hash = { root => { _attrs => { attr=>'value', }, }, }; my $opts = {}; my $opts_orig = _dump($opts); is( _dump($opts), $opts_orig, "[keep opts hash] before calling xml()." ); xml($hash,$opts); is( _dump($opts), $opts_orig, "[keep opts hash] after calling xml()." ); } # ----------------------------------------------------------------------------- # test_003_keep_cdata_tag. # sub test_003_keep_cdata_tag { my $hash = { root => { # hairy thing. _cdata => '_cdata text', cdata => 'cdata tag', tag => 'text', }, }; my $hash_orig = _dump($hash); is( _dump($hash), $hash_orig, "[keep cdata tag] before calling xml()." ); ok( xml($hash), "[keep cdata tag] call xml()." ); is( _dump($hash), $hash_orig, "[keep cdata tag] after calling xml()." ); } # ----------------------------------------------------------------------------- # End of File. # -----------------------------------------------------------------------------
From: rob [...] cataclysm.cx
Fixed in 0.03, which will hit CPAN any moment now. Thanks for the patch.