diff options
author | gregor herrmann <gregoa@debian.org> | 2022-10-04 22:48:58 +0200 |
---|---|---|
committer | gregor herrmann <gregoa@debian.org> | 2022-10-04 22:48:58 +0200 |
commit | a655791c3c275af8745a17d543223feaea7824f7 (patch) | |
tree | 1ce588581101aebc22c17147c761f75f07f3e4ce | |
parent | 9be8e4ea80cc0e8a751376a2a2b14eb6dfcc6a60 (diff) | |
parent | 2dcb3b072c23dbb0ee85311e91a9c299838be354 (diff) |
Update upstream source from tag 'upstream/0.006000'
Update to upstream version '0.006000'
with Debian dir b289c1a8f9015c219b24e021fa5a01a136552f2a
-rw-r--r-- | Changes | 3 | ||||
-rw-r--r-- | LICENSE | 16 | ||||
-rw-r--r-- | MANIFEST | 1 | ||||
-rw-r--r-- | META.json | 8 | ||||
-rw-r--r-- | META.yml | 6 | ||||
-rw-r--r-- | lib/Data/Dumper/Compact.pm | 45 | ||||
-rw-r--r-- | lib/Devel/DDCWarn.pm | 2 | ||||
-rw-r--r-- | lib/JSON/Dumper/Compact.pm | 12 | ||||
-rw-r--r-- | t/circular.t | 34 |
9 files changed, 105 insertions, 22 deletions
@@ -1,5 +1,8 @@ Revision history for Data-Dumper-Compact +0.006000 - 2022-09-24 + - Handle recursive data structures with $_ deref in perl and JSON Reference + 0.005002 - 2020-06-07 - Fix JSON::Dumper::Compact @@ -7,7 +7,7 @@ b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- -This software is Copyright (c) 2020 by mst - Matt S Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>. +This software is Copyright (c) 2022 by mst - Matt S Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>. This is free software, licensed under: @@ -267,7 +267,7 @@ That's all there is to it! --- The Artistic License 1.0 --- -This software is Copyright (c) 2020 by mst - Matt S Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>. +This software is Copyright (c) 2022 by mst - Matt S Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>. This is free software, licensed under: @@ -287,21 +287,21 @@ Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through - textual modification. + textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright - Holder. + Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for - the package. + the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the - computing community at large as a market that must bear the fee.) + computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they - received it. + received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you @@ -368,7 +368,7 @@ products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF -MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End @@ -25,6 +25,7 @@ maint/Makefile.PL.include Makefile.PL MANIFEST This list of files t/basic.t +t/circular.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) README README file (added by Distar) @@ -4,13 +4,13 @@ "mst - Matt S Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>" ], "dynamic_config" : 1, - "generated_by" : "ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010", + "generated_by" : "ExtUtils::MakeMaker version 7.62, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", - "version" : "2" + "version" : 2 }, "name" : "Data-Dumper-Compact", "no_index" : { @@ -58,8 +58,8 @@ "web" : "https://github.com/shadow-dot-cat/Data-Dumper-Compact" } }, - "version" : "0.005002", + "version" : "0.006000", "x_authority" : "cpan:MSTROUT", "x_breaks" : {}, - "x_serialization_backend" : "JSON::PP version 2.27300" + "x_serialization_backend" : "JSON::PP version 2.97001" } @@ -7,7 +7,7 @@ build_requires: configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 -generated_by: 'ExtUtils::MakeMaker version 7.34, CPAN::Meta::Converter version 2.150010' +generated_by: 'ExtUtils::MakeMaker version 7.62, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html @@ -24,7 +24,7 @@ resources: bugtracker: https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Dumper-Compact license: http://dev.perl.org/licenses/ repository: https://github.com/shadow-dot-cat/Data-Dumper-Compact.git -version: '0.005002' +version: '0.006000' x_authority: cpan:MSTROUT x_breaks: {} -x_serialization_backend: 'CPAN::Meta::YAML version 0.012' +x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff --git a/lib/Data/Dumper/Compact.pm b/lib/Data/Dumper/Compact.pm index 28f554a..e06cd49 100644 --- a/lib/Data/Dumper/Compact.pm +++ b/lib/Data/Dumper/Compact.pm @@ -5,7 +5,7 @@ use Scalar::Util qw(blessed reftype); use Data::Dumper (); use Mu::Tiny; -our $VERSION = '0.005002'; +our $VERSION = '0.006000'; $VERSION =~ tr/_//d; sub import { @@ -87,14 +87,28 @@ sub dump_cb { } sub expand { - my ($self, $data) = @_; + my ($self, $data, $p) = @_; + local $self->{expand_seen} = {} unless $self->{expand_seen}; + my $this_path = [ + ($self->{expand_path} ? @{$self->{expand_path}} : ()), + (defined($p) ? ($p) : ()) + ]; + if (ref($data)) { + if (my $seen_path = $self->{expand_seen}{$data}) { + return [ ref => $seen_path ]; + } else { + $self->{expand_seen}{$data} = $this_path; + } + } + local $self->{expand_path} = $this_path; if (ref($data) eq 'HASH') { return [ hash => [ [ sort keys %$data ], - { map +($_ => $self->expand($data->{$_})), keys %$data } + { map +($_ => $self->expand($data->{$_}, [ key => $_ ])), sort keys %$data } ] ]; } elsif (ref($data) eq 'ARRAY') { - return [ array => [ map $self->expand($_), @$data ] ]; + my $idx = 0; + return [ array => [ map $self->expand($_, [ idx => $idx++ ]), @$data ] ]; } elsif (blessed($data) and my $ret = $self->_expand_blessed($data)) { return $ret; } @@ -131,7 +145,7 @@ sub _transform { $payload->[0], { map +( $_ => $self->_transform($h{$_}, [ @$path, $_ ]) - ), keys %h + ), sort keys %h }, ]; } elsif ($type eq 'array') { @@ -315,6 +329,7 @@ sub _format_hash { my ($self, $payload) = @_; my ($keys, $hash) = @$payload; return '{}' unless @$keys; + @$keys = sort @$keys; my %k = (map +( $_ => $self->_format_hashkey($_)), @$keys ); @@ -389,6 +404,26 @@ sub _format_blessed { return 'bless( '.$self->_format($content).qq{, "${class}"}.' )'; } +sub _format_ref { + my ($self, $payload) = @_; + return '$_->'.join('', + map { + if ($_->[0] eq 'key') { + my $quoted = quotemeta($_->[1]); + if ($_->[1] eq $quoted) { + '{'.$quoted.'}' + } else { + '{"'.$quoted.'"}' + } + } elsif ($_->[0] eq 'idx') { + '['.$_->[1].']' + } else { + die "Invalid ref element type ".$_->[0]; + } + } @$payload + ); +} + 1; __END__ diff --git a/lib/Devel/DDCWarn.pm b/lib/Devel/DDCWarn.pm index 300411d..9df5aca 100644 --- a/lib/Devel/DDCWarn.pm +++ b/lib/Devel/DDCWarn.pm @@ -4,7 +4,7 @@ use strictures 2; use Data::Dumper::Compact; use base qw(Exporter); -our $VERSION = '0.005002'; +our $VERSION = '0.006000'; $VERSION =~ tr/_//d; our @EXPORT = map +($_, $_.'T'), qw(Df Dto Dwarn Derr); diff --git a/lib/JSON/Dumper/Compact.pm b/lib/JSON/Dumper/Compact.pm index ff82f72..2b4c5a7 100644 --- a/lib/JSON/Dumper/Compact.pm +++ b/lib/JSON/Dumper/Compact.pm @@ -4,7 +4,7 @@ use JSON::MaybeXS; use Mu::Tiny; use Class::Method::Modifiers; -our $VERSION = '0.005002'; +our $VERSION = '0.006000'; $VERSION =~ tr/_//d; extends 'Data::Dumper::Compact'; @@ -46,6 +46,16 @@ sub _format_blessed { ] ]); } +sub _format_ref { + my ($self, $payload) = @_; + my %subst = ('/' => '~1', '~' => '~0'); + my @path = map { (my $x = $_->[1]) =~ s{[/~]}{$subst{$_}}eg; $x } @$payload; + return $self->format([ hash => [ + [ '$ref' ], + { '$ref' => [ string => join('/', '#', @path) ] }, + ] ]); +} + sub encode { shift->dump(@_) } sub decode { diff --git a/t/circular.t b/t/circular.t new file mode 100644 index 0000000..4b35d85 --- /dev/null +++ b/t/circular.t @@ -0,0 +1,34 @@ +use strict; +use warnings; +use Test::More; + +use Data::Dumper::Compact; + +my $can_j = eval { require JSON::Dumper::Compact; 1 }; + +my $circular = { + quux => { bar => 73 }, + foo => { baz => [ 42 ] }, +}; + +$circular->{foo}{baz}[1] = $circular->{foo}; + +is( + Data::Dumper::Compact->dump($circular), + '{ foo => { baz => [ 42, $_->{foo} ] }, quux => { bar => 73 } }'."\n" +); + +if ($can_j) { + is( + JSON::Dumper::Compact->dump($circular), + '{ + "foo": { "baz": [ + 42, { "$ref": "#/foo" } + , + ] }, + "quux": { "bar": 73 }, +} +'); +} + +done_testing; |