Skip Menu |

This queue is for tickets about the Data-Clone CPAN distribution.

Report information
The Basics
Id: 82584
Status: open
Priority: 0/
Queue: Data-Clone

People
Owner: Nobody in particular
Requestors: TOSHIOITO [...] cpan.org
Cc:
AdminCc:

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



Subject: Data::Clone dies when it tries to clone JSON::XS::true or JSON::XS::false
I use: - perl 5.14.2 - Data::Clone 0.003 - JSON::XS 2.33 - JSON::PP 2.27200 Data::Clone's clone() method dies when it tries to clone JSON::XS::false or JSON::XS::true objects. Test------ use strict; use warnings; use JSON::XS (); use JSON::PP (); use Data::Clone; use Test::More; use Test::Exception; foreach my $class (qw(JSON::PP JSON::XS)) { my ($true, $false) = eval qq{ (${class}::true, ${class}::false) }; my $clone_true; lives_ok { $clone_true = clone($true) } "${class}::true: clone OK"; ok($clone_true, "${class}::true is true"); my $clone_false; lives_ok { $clone_false = clone($false) } "${class}::false: clone OK"; ok(!$clone_false, "${class}::false is false"); } done_testing(); ----------- The above test gives the following result. ok 1 - JSON::PP::true: clone OK ok 2 - JSON::PP::true is true ok 3 - JSON::PP::false: clone OK ok 4 - JSON::PP::false is false not ok 5 - JSON::XS::true: clone OK # Failed test 'JSON::XS::true: clone OK' # at clone_json.pl line 12. # died: Modification of a read-only value attempted at clone_json.pl line 12. not ok 6 - JSON::XS::true is true # Failed test 'JSON::XS::true is true' # at clone_json.pl line 13. not ok 7 - JSON::XS::false: clone OK # Failed test 'JSON::XS::false: clone OK' # at clone_json.pl line 15. # died: Modification of a read-only value attempted at clone_json.pl line 15. ok 8 - JSON::XS::false is false 1..8 # Looks like you failed 3 tests of 8.
Adding the following lines to my code, fixes the problem for me. Also this is not a fix, it works: package JSON::XS::Boolean ; $JSON::XX::true = do { bless \(my $dummy = 1), "JSON::XS::Boolean" }; $JSON::XX::false = do { bless \(my $dummy = 0), "JSON::XS::Boolean" }; sub clone { return scalar($_[0]?$JSON::XX::true:$JSON::XX::false) ; }