Or to be a bit more concise -- I would think this is enough: sub thaw { my ( $class, $json, @args ) = @_; return $class->unpack( JSON::Any->decode( $json ), @args ); }
sub freeze { my ( $self, @args ) = @_; return JSON::Any->encode( $self->pack( @args ) ); } On Wed, Feb 27, 2013 at 8:38 PM, Bill Moseley <mose...@hank.org> wrote: > > > On Wed, Feb 27, 2013 at 7:59 PM, Chris Prather <ch...@prather.org> wrote: > >> On Wed, Feb 27, 2013 at 10:15 PM, Bill Moseley <mose...@hank.org> wrote: >> > I had forgot about this until today until I saw errors in some new code. >> > >> > Is there anything below that needs clarification? IIRC, I got stuck >> > because I didn't really follow what the tests were attempting to test. >> > Does the test need to do anything more than make sure wide characters >> get >> > turned into octets when freezing and then when thawed it's character >> data >> > again (i.e. the utf8 flag survives round trip)? >> > >> > Thanks, >> >> Looking at the JSON::Any code this *may* be a bug with that. At some >> point in time (someone) had to add the line: >> >> $conf->{utf8} = !$conf->{utf8} >> > > Maybe I'm not following, but the bug is in MooseX::Storage::Format::JSON. > this line should just be removed. > > utf8::decode($json) if !utf8::is_utf8($json) and utf8::valid($json); # if > it's valid utf8 mark it as such > > That's just wrong a number of ways. > > $ perl -le 'use utf8; print "Yes, ASCII is valid utf8" if utf8::valid( > "just ASCII" )' > Yes, ASCII is valid utf8 > > plus the fact that JSON just encoded into octets -- so why decode back to > characters? > > $ perl -MJSON::Any -MEncode -wle 'print "Happy octets" unless > Encode::is_utf8( JSON::Any->new->objToJson( { smile => "I am wide > \N{U+263A}" } ))' > Happy octets > > All the specific "utf8" code doesn't need to be there. Even in thaw. The > character data (flagged correctly with the utf8 flag) survives round trip > w/o needing to use "utf8" anywhere. > > $ perl -MJSON::Any -MEncode -wle 'print "Happy characters" if > Encode::is_utf8( JSON::Any->new->jsonToObj( JSON::Any->new->objToJson( { > smile => "I am wide \N{U+263A}" } ))->{smile} )' > Happy characters > > Sorry, if the one-liners are a bit hard to read. > > > -- > Bill Moseley > mose...@hank.org -- Bill Moseley mose...@hank.org