Data-Dumper-Compact-0.006000/0000755000000000000000000000000014313630273015426 5ustar00rootroot00000000000000Data-Dumper-Compact-0.006000/ex/0000755000000000000000000000000014313630272016041 5ustar00rootroot00000000000000Data-Dumper-Compact-0.006000/ex/jdeep40000644000000000000000000000012313467127024017140 0ustar00rootroot00000000000000{ "-xxxxxxxxxxxxx": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" } Data-Dumper-Compact-0.006000/ex/jdeep100000644000000000000000000000030513467127026017221 0ustar00rootroot00000000000000[ { "__bless__": [ "OhGods::Lol", { "x": 3, "y": [ "foo", "bar", "baz", "quux", "fleem", "blather", "obrien" ], "z": "lololololololololololololololol", }, ] } ] Data-Dumper-Compact-0.006000/ex/jdeep10000644000000000000000000000173513467127023017146 0ustar00rootroot00000000000000[ 1, 2, [ "longstringislonglongstringislonglongstringislong", "longstringislonglongstringislong", "longstringislong", "longstringislonglongstringislonglongstringislong", "longstringislong", "longstringislonglongstringislong", "longstringislong", "longstringislonglongstringislong", "longstringislonglongstringislonglongstringislong", "longstringislonglongstringislong", "longstringislonglongstringislong", "longstringislonglongstringislonglongstringislong", "longstringislong", "longstringislong", "longstringislonglongstringislonglongstringislong", "longstringislong", "longstringislong", "longstringislong", "longstringislonglongstringislong", "longstringislonglongstringislonglongstringislong", "a", "b", "c", "longstringislonglongstringislonglongstringislonglongstringislong", "longstringislonglongstringislonglongstringislonglongstringislong", "longstringislonglongstringislonglongstringislonglongstringislong", ], 3, ] Data-Dumper-Compact-0.006000/ex/deep80000644000000000000000000000052613464124757017010 0ustar00rootroot00000000000000[ '1556933590.65383', 'Fri May 3 18:33:10 2019', 26794, 'INFO', 3, [ 'SRV:8FB66F32' ], [ [ '/opt/voice-srvc-native/bin/async-srvc-att-gateway-poller', 33, 'NERV::Voice::SRV::Native::AsyncSRVATTGatewayPoller::main', ] ], 'batch_nena_messages returned', 'OK', 6, { FILENAME => 'lqxw020323' }, 1556933584, 'lqxw020323', ] Data-Dumper-Compact-0.006000/ex/jdeep20000644000000000000000000000040113467127024017135 0ustar00rootroot00000000000000[ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", [ "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc", ], "-blah", { "baz": "quux", "foo": "bar" }, ] Data-Dumper-Compact-0.006000/ex/jdeep90000644000000000000000000000014613467127025017153 0ustar00rootroot00000000000000[ "-foo", [ "bar", "baz", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", ] ] Data-Dumper-Compact-0.006000/ex/deep90000644000000000000000000000014613465160525017001 0ustar00rootroot00000000000000[ -foo => [ 'bar', 'baz', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', ] ] Data-Dumper-Compact-0.006000/ex/deep100000644000000000000000000000024013466657134017054 0ustar00rootroot00000000000000[ bless( { x => 3, y => [ 'foo', 'bar', 'baz', 'quux', 'fleem', 'blather', 'obrien' ], z => 'lololololololololololololololol', }, "OhGods::Lol" ) ] Data-Dumper-Compact-0.006000/ex/deep40000644000000000000000000000012313462164505016766 0ustar00rootroot00000000000000{ -xxxxxxxxxxxxx => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' } Data-Dumper-Compact-0.006000/ex/jdeep50000644000000000000000000000013513467127024017144 0ustar00rootroot00000000000000{ "-xxxxxxxxxxxxx": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" } Data-Dumper-Compact-0.006000/ex/jdeep60000644000000000000000000000040313467127025017144 0ustar00rootroot00000000000000[ "xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy" ] Data-Dumper-Compact-0.006000/ex/jdeep30000644000000000000000000000027513467127024017147 0ustar00rootroot00000000000000[ { "-foo": { "bar": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "baz": "bbbbbbbbbbbbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", } } ] Data-Dumper-Compact-0.006000/ex/deep10000644000000000000000000000173513462672603017000 0ustar00rootroot00000000000000[ 1, 2, [ 'longstringislonglongstringislonglongstringislong', 'longstringislonglongstringislong', 'longstringislong', 'longstringislonglongstringislonglongstringislong', 'longstringislong', 'longstringislonglongstringislong', 'longstringislong', 'longstringislonglongstringislong', 'longstringislonglongstringislonglongstringislong', 'longstringislonglongstringislong', 'longstringislonglongstringislong', 'longstringislonglongstringislonglongstringislong', 'longstringislong', 'longstringislong', 'longstringislonglongstringislonglongstringislong', 'longstringislong', 'longstringislong', 'longstringislong', 'longstringislonglongstringislong', 'longstringislonglongstringislonglongstringislong', 'a', 'b', 'c', 'longstringislonglongstringislonglongstringislonglongstringislong', 'longstringislonglongstringislonglongstringislonglongstringislong', 'longstringislonglongstringislonglongstringislonglongstringislong', ], 3, ] Data-Dumper-Compact-0.006000/ex/deep20000644000000000000000000000040113462164505016763 0ustar00rootroot00000000000000[ 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', [ 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', ], -blah => { baz => 'quux', foo => 'bar' }, ] Data-Dumper-Compact-0.006000/ex/deep70000644000000000000000000000247713462164505017007 0ustar00rootroot00000000000000{ _ => [ 'tree_table', -join => { as => 'tree', on => { 'tree.id' => 'tree_with_path.id' }, to => { -select => { from => 'tree_with_path', select => '*', with_recursive => [ [ 'tree_with_path', 'id', 'parent_id', 'path' ], { -select => { _ => [ 'id', 'parent_id', { -as => [ { -cast => { -as => [ 'id', 'char', 255 ] } }, 'path', ] }, ], from => 'tree_table', union_all => { -select => { _ => [ 't.id', 't.parent_id', { -as => [ { -concat => [ 'r.path', \"'/'", 't.id' ] }, 'path', ] }, ], from => [ 'tree_table', -as => 't', -join => { as => 'r', on => { 't.parent_id' => 'r.id' }, to => 'tree_with_path', }, ], } }, where => { parent_id => undef }, } }, ], } }, }, ], set => { path => { -ident => [ 'tree', 'path' ] } }, } Data-Dumper-Compact-0.006000/ex/deep60000644000000000000000000000042313462164505016773 0ustar00rootroot00000000000000[ 'xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyx' .'yxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy' .'xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyx' .'yxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy' ] Data-Dumper-Compact-0.006000/ex/jdeep80000644000000000000000000000052613467127025017154 0ustar00rootroot00000000000000[ "1556933590.65383", "Fri May 3 18:33:10 2019", 26794, "INFO", 3, [ "SRV:8FB66F32" ], [ [ "/opt/voice-srvc-native/bin/async-srvc-att-gateway-poller", 33, "NERV::Voice::SRV::Native::AsyncSRVATTGatewayPoller::main", ] ], "batch_nena_messages returned", "OK", 6, { "FILENAME": "lqxw020323" }, 1556933584, "lqxw020323", ] Data-Dumper-Compact-0.006000/ex/deep30000644000000000000000000000027513462175302016772 0ustar00rootroot00000000000000[ { -foo => { bar => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', baz => "bbbbbbbbbbbbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", } } ] Data-Dumper-Compact-0.006000/ex/deep50000644000000000000000000000013513462164505016772 0ustar00rootroot00000000000000{ -xxxxxxxxxxxxx => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' } Data-Dumper-Compact-0.006000/META.json0000644000000000000000000000321014313630272017042 0ustar00rootroot00000000000000{ "abstract" : "Vertically compact width-limited data formatter", "author" : [ "mst - Matt S Trout (cpan:MSTROUT) " ], "dynamic_config" : 1, "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 }, "name" : "Data-Dumper-Compact", "no_index" : { "directory" : [ "t", "xt" ] }, "prereqs" : { "build" : { "requires" : {} }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : {} }, "runtime" : { "requires" : { "Class::Method::Modifiers" : "0", "Mu::Tiny" : "0.000002" } }, "test" : { "requires" : { "Test::More" : "0.88" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "mailto" : "bug-Data-Dumper-Compact@rt.cpan.org", "web" : "https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Dumper-Compact" }, "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "https://github.com/shadow-dot-cat/Data-Dumper-Compact.git", "web" : "https://github.com/shadow-dot-cat/Data-Dumper-Compact" } }, "version" : "0.006000", "x_authority" : "cpan:MSTROUT", "x_breaks" : {}, "x_serialization_backend" : "JSON::PP version 2.97001" } Data-Dumper-Compact-0.006000/Makefile.PL0000644000000000000000000000540313667031371017407 0ustar00rootroot00000000000000use strict; use warnings FATAL => 'all'; use 5.006; my %META = ( name => 'Data-Dumper-Compact', license => 'perl_5', prereqs => { configure => { requires => { 'ExtUtils::MakeMaker' => 0, } }, build => { requires => { } }, test => { requires => { 'Test::More' => 0.88, }, }, runtime => { requires => { 'Mu::Tiny' => '0.000002', 'Class::Method::Modifiers' => 0, }, }, develop => { requires => { }, }, }, resources => { repository => { url => 'https://github.com/shadow-dot-cat/Data-Dumper-Compact.git', web => 'https://github.com/shadow-dot-cat/Data-Dumper-Compact', type => 'git', }, bugtracker => { web => 'https://rt.cpan.org/Public/Dist/Display.html?Name=Data-Dumper-Compact', mailto => 'bug-Data-Dumper-Compact@rt.cpan.org', }, license => [ 'http://dev.perl.org/licenses/' ], }, no_index => { directory => [ 't', 'xt' ] }, x_breaks => { }, x_authority => 'cpan:MSTROUT', ); my %MM_ARGS = (); ## BOILERPLATE ############################################################### require ExtUtils::MakeMaker; (do './maint/Makefile.PL.include' or die $@) unless -f 'META.yml'; # have to do this since old EUMM dev releases miss the eval $VERSION line my $eumm_version = eval $ExtUtils::MakeMaker::VERSION; my $mymeta = $eumm_version >= 6.57_02; my $mymeta_broken = $mymeta && $eumm_version < 6.57_07; ($MM_ARGS{NAME} = $META{name}) =~ s/-/::/g; ($MM_ARGS{VERSION_FROM} = "lib/$MM_ARGS{NAME}.pm") =~ s{::}{/}g; $META{license} = [ $META{license} ] if $META{license} && !ref $META{license}; $MM_ARGS{LICENSE} = $META{license}[0] if $META{license} && $eumm_version >= 6.30; $MM_ARGS{NO_MYMETA} = 1 if $mymeta_broken; $MM_ARGS{META_ADD} = { 'meta-spec' => { version => 2 }, %META } unless -f 'META.yml'; $MM_ARGS{PL_FILES} ||= {}; $MM_ARGS{NORECURS} = 1 if not exists $MM_ARGS{NORECURS}; for (qw(configure build test runtime)) { my $key = $_ eq 'runtime' ? 'PREREQ_PM' : uc $_.'_REQUIRES'; my $r = $MM_ARGS{$key} = { %{$META{prereqs}{$_}{requires} || {}}, %{delete $MM_ARGS{$key} || {}}, }; defined $r->{$_} or delete $r->{$_} for keys %$r; } $MM_ARGS{MIN_PERL_VERSION} = delete $MM_ARGS{PREREQ_PM}{perl} || 0; delete $MM_ARGS{MIN_PERL_VERSION} if $eumm_version < 6.47_01; $MM_ARGS{BUILD_REQUIRES} = {%{$MM_ARGS{BUILD_REQUIRES}}, %{delete $MM_ARGS{TEST_REQUIRES}}} if $eumm_version < 6.63_03; $MM_ARGS{PREREQ_PM} = {%{$MM_ARGS{PREREQ_PM}}, %{delete $MM_ARGS{BUILD_REQUIRES}}} if $eumm_version < 6.55_01; delete $MM_ARGS{CONFIGURE_REQUIRES} if $eumm_version < 6.51_03; ExtUtils::MakeMaker::WriteMakefile(%MM_ARGS); ## END BOILERPLATE ########################################################### Data-Dumper-Compact-0.006000/Changes0000644000000000000000000000235514313630250016721 0ustar00rootroot00000000000000Revision 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 0.005001 - 2020-05-25 - Fixup to use Mu::Tiny everywhere and require working version of Mu::Tiny 0.005000 - 2020-05-20 - Switch to Mu::Tiny for a shallower dep tree 0.004001 - 2019-09-15 - Regexp fixup to avoid a deprecation warning 0.004000 - 2019-05-29 - Add tweak feature to DwarnT 0.003003 - 2019-05-29 - Add versions to everything so people can depend on them - Don't barf on empty array/hash refs 0.003002 - 2019-05-16 - Doc improvements for JSON::Dumper::Compact 0.003001 - 2019-05-16 - Bugfix: actually export the right subroutine name 0.003000 - 2019-05-16 - JSON dumping and rehydrating support 0.002003 - 2019-05-15 - Render blessed hashrefs and arrayrefs using DDC logic 0.002002 - 2019-05-10 - Collapse single key/value in list/array correctly 0.002001 - 2019-05-09 - Fix stupid documentation error 0.002000 - 2019-05-09 - Add Devel::DDCWarn in the style of Devel::Dwarn 0.001001 - 2019-05-09 - Remove subref test because B::Deparse output varies between perl versions 0.001000 - 2019-05-09 - initial release Data-Dumper-Compact-0.006000/maint/0000755000000000000000000000000014313630272016535 5ustar00rootroot00000000000000Data-Dumper-Compact-0.006000/maint/Makefile.PL.include0000644000000000000000000000034213467131756022144 0ustar00rootroot00000000000000BEGIN { -e 'Distar' or system("git clone git://github.com/p5sagit/Distar") } use lib 'Distar/lib'; use Distar 0.001; author 'mst - Matt S Trout (cpan:MSTROUT) '; manifest_include ex => qr/j?deep.*/; 1; Data-Dumper-Compact-0.006000/LICENSE0000644000000000000000000004350014313630273016435 0ustar00rootroot00000000000000Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2022 by mst - Matt S Trout (cpan:MSTROUT) . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2022 by mst - Matt S Trout (cpan:MSTROUT) . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through 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. - "Copyright Holder" is whoever is named in the copyright or copyrights for 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.) - "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. 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 duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote 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 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Data-Dumper-Compact-0.006000/README0000644000000000000000000005701114313630272016311 0ustar00rootroot00000000000000NAME Data::Dumper::Compact - Vertically compact width-limited data formatter SYNOPSIS Basic usage as a function: use Data::Dumper::Compact 'ddc'; warn ddc($some_data_structure); warn ddc($some_data_structure, \%options); Slightly more clever usage as a function: use Data::Dumper::Compact ddc => \%default_options; warn ddc($some_data_structure); warn ddc($some_data_structure, \%extra_options); OO usage: use Data::Dumper::Compact; warn Data::Dumper::Compact->dump($data, \%options); my $ddc = Data::Dumper::Compact->new(\%options); warn $ddc->dump($data); warn $ddc->dump($data, \%extra_options); DESCRIPTION Data::Dumper::Compact, henceforth referred to as DDC, was born because I was annoyed at valuable wasted whitespace paging through both Data::Dumper and Data::Dump based logs - Data::Dump attempts to format horizontally first, but then if it fails, immediately switches to formatting fully vertically, rather than trying to e.g. format a six element arrayref three per line. So here's a few of the specifics (noting that all examples unless otherwise specified are dumped with default options): Arrays and Strings Given arrays consisting of reasonably long strings, DDC does its best to produce a sane representation within its "max_width": [ 1, 2, [ 'longstringislonglongstringislonglongstringislong', 'longstringislonglongstringislong', 'longstringislong', 'longstringislonglongstringislonglongstringislong', 'longstringislong', 'longstringislonglongstringislong', 'longstringislong', 'longstringislonglongstringislong', 'longstringislonglongstringislonglongstringislong', 'longstringislonglongstringislong', 'longstringislonglongstringislong', 'longstringislonglongstringislonglongstringislong', 'longstringislong', 'longstringislong', 'longstringislonglongstringislonglongstringislong', 'longstringislong', 'longstringislong', 'longstringislong', 'longstringislonglongstringislong', 'longstringislonglongstringislonglongstringislong', 'a', 'b', 'c', 'longstringislonglongstringislonglongstringislonglongstringislong', 'longstringislonglongstringislonglongstringislonglongstringislong', 'longstringislonglongstringislonglongstringislonglongstringislong', ], 3, ] Keys and Hashrefs When faced with a "-foo" style value, it gets a "=>" even in an array, and hash values that we can are single-line formatted: [ 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', [ 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', ], -blah => { baz => 'quux', foo => 'bar' }, ] The String Thing Strings are single quoted when DDC is absolutely sure that's safe, and double quoted otherwise: [ { -foo => { bar => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', baz => "bbbbbbbbbbbbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", } } ] Lonely hash key When a single hash key can't be formatted in a oneline form within the length, DDC will try spilling it to its own line: { -xxxxxxxxxxxxx => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' } If even that isn't enough, it formats it below and indented: { -xxxxxxxxxxxxx => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' } Strings and the dot operator If a string simply won't fit, DDC splits it and indents it using ".": [ 'xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyx' .'yxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy' .'xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyx' .'yxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy' ] Unknown unknowns Anything DDC doesn't understand is passed through its "dumper" option, though since Data::Dumper (at the time of writing) forgets to pass through its indentation level to B::Concise, we slightly tweak that behaviour on the way in for the default "dumper". But the end result looks like: { foo => { bar => sub { use warnings; use strict 'refs'; my($x, $y) = @_; return $x * $y; } } } Bless you When encountering an object, if it's a blessed array or hashref, DDC will attempt to format that too: [ bless( { x => 3, y => [ 'foo', 'bar', 'baz', 'quux', 'fleem', 'blather', 'obrien' ], z => 'lololololololololololololololol', }, "OhGods::Lol" ) ] All together now The full set of behaviours allows compact (and, we hope, readable) versions of complex data structures. To provide one of the examples that expired this module - here is the formatting under standard options for a moderately complex SQL::Abstract update statement: { _ => [ 'tree_table', -join => { as => 'tree', on => { 'tree.id' => 'tree_with_path.id' }, to => { -select => { from => 'tree_with_path', select => '*', with_recursive => [ [ 'tree_with_path', 'id', 'parent_id', 'path' ], { -select => { _ => [ 'id', 'parent_id', { -as => [ { -cast => { -as => [ 'id', 'char', 255 ] } }, 'path', ] }, ], from => 'tree_table', union_all => { -select => { _ => [ 't.id', 't.parent_id', { -as => [ { -concat => [ 'r.path', \"'/'", 't.id' ] }, 'path', ] }, ], from => [ 'tree_table', -as => 't', -join => { as => 'r', on => { 't.parent_id' => 'r.id' }, to => 'tree_with_path', }, ], } }, where => { parent_id => undef }, } }, ], } }, }, ], set => { path => { -ident => [ 'tree', 'path' ] } }, } And the version (generated by setting "max_width" to 40) that runs out of space and thereby forces the "spill vertically" logic to kick in while still attemping to be at least somewhat compact: { _ => [ 'tree_table', '-join', { as => 'tree', on => { 'tree.id' => 'tree_with_path.id', }, to => { -select => { from => 'tree_with_path', select => '*', with_recursive => [ [ 'tree_with_path', 'id', 'parent_id', 'path', ], { -select => { _ => [ 'id', 'parent_id', { -as => [ { -cast => { -as => [ 'id', 'char', 255, ], }, }, 'path', ], }, ], from => 'tree_table', union_all => { -select => { _ => [ 't.id', 't.parent_id', { -as => [ { -concat => [ 'r.path', \"'/'", 't.id', ], }, 'path', ], }, ], from => [ 'tree_table', '-as', 't', '-join', { as => 'r', on => { 't.parent_id' => 'r.id', }, to => 'tree_with_path', }, ], }, }, where => { parent_id => undef, }, }, }, ], }, }, }, ], set => { path => { -ident => [ 'tree', 'path', ], }, }, } Summary Hopefully it's clear what the goal is, and what we've done to achieve it. While the system is already somewhat configurable, further options are almost certainly implementable, although if you really want such an option then we expect you to turn up with documentation and test cases for it so we just have to write the code. OPTIONS max_width Represents the width that DDC will attempt to keep as the maximum (if something overflows it in spite of our best efforts, DDC will fall back to a more vertically sprawling format to at least overflow as little as feasible). Default: 78 indent_by The string to indent by. To set e.g. 4 space indent, pass "' 'x4". Default: ' ' (two spaces). indent_width How many characters one indent should be considered to be. Generally you only need to manually set this if your "indent_by" is "\t". Default: "length($self->indent_by)" transforms Set of transforms to apply on every "dump" operation. See "transform" for more information. Default: "[]" dumper The dumper function to be used for dumping things DDC doesn't understand, such as coderefs, regexprefs, etc. Defaults to the same options as Data::Dumper::Concise (which is, itself, only a Data::Dumper configuration albeit it comes with Devel::Dwarn which is rather more interesting) - although on top of that we add a little bit of extra cleverness to make B::Deparse use the correct indentation, since for some reason Data::Dumper doesn't (at the time of writing) do that. If you supply it yourself, it needs to be a single argument coderef - you could for example use "\&Data::Dumper::Dumper" though that would almost certainly be pointless. EXPORTS ddc use Data::Dumper::Compact 'ddc'; use Data::Dumper::Compact 'ddc' => \%options; If the first argument to "use"/"import()" is 'ddc', a subroutine "ddc()" is installed in the calling package which behaves like calling "dump". If the second argument is a hashref, it becomes the options passed to "new". This feature is effectively sugar over "dump_cb", in that: Data::Dumper::Compact->import(ddc => \%options) is equivalent to: *ddc = Data::Dumper::Compact->new(\%options)->dump_cb; METHODS new my $ddc = Data::Dumper::Compact->new; my $ddc = Data::Dumper::Compact->new(%options); my $ddc = Data::Dumper::Compact->new(\%options); Constructor. Takes a hash or hashref of "OPTIONS" dump my $formatted = Data::Dumper::Compact->dump($data, \%options?); my $formatted = $ddc->dump($data, \%merge_options?); This is the method you're going to want to call most of the time, and ties together the rest of the functionality into a single data-structure-to-string bundle. With just a data argument, it's equivalent to: $ddc->format( $ddc->transform( $ddc->transforms, $ddc->expand($data) ); In class method form, options provided are passed to "new"; in instance method form, options if provided are merged into $ddc just for this invocation. dump_cb my $cb = $ddc->dump_cb; Returns a subroutine reference that's a curried call to "dump": $cb->($data, \%extra_options); # equivalent to $ddc->dump(...) Mostly useful for if you want to create a custom "ddc()" like thing: use Data::Dumper::Compact; BEGIN { *Dumper = Data::Dumper::Compact->new->dump_cb } expand my $exp = $ddc->expand($data); Expands a data structure to DDC tagged data. The result is, recursively, [ $type, $payload ] where if $type is one of "string", "key", or "thing", the payload is a simple string ("thing" meaning something unknown and therefore delegated to "dumper"). If the type is an array: [ array => \@values ] and if the type is a hash: [ hash => [ \@keys, \%value_map ] ] where the keys provide an order for formatting, and the value map is a hashref of keys to expanded values. A plain string becomes a "string", unless it fits the "-foo" style pattern that autoquotes, in which case it becomes a "key". add_transform $ddc->add_transform(sub { ... }); $ddc->add_transform({ hash => sub { ... }, _ => sub { ... }); Appends a transform to "$ddc->transforms", see "transform" for behaviour. Returns $ddc to enable chaining. transform my $tf_exp = $ddc->transform($tfspec, $exp); Takes a transform specification and expanded tagged data and returns the transformed expanded expression. A transform spec is an arrayref containing transforms, where each transform is applied in order, so the last transform added via "add_transform" will be the last one to transform the data (each transform will consist of a datastructure representing which parts of the $exp tree it should be called for, plus subroutines representing the relevant transforms). Transform subroutines are called as a method on the $ddc with the arguments of "$type, $payload, $path" where $path is an arrayref of the keys/values of the containing hashes and arrays, aggregated as DDC descends through the $exp tree. Each transform is expected to return either nothing, to indicate it doesn't wish to modify the result, or a replacement expanded data structure. The simplest form of transform is a subref, which gets called for everything. So, to add ' IN MICE' to every string that's part of an array under a hash key called study_results, i.e.: my $data = { study_results => [ 'Sense Of Touch Is Formed In the Brain Before Birth'. "We can't currently cure MS but a single cell could change that", ] }; my $tf_exp = $ddc->transform([ sub { my ($self, $type, $payload, $path) = @_; return unless $type eq 'string' and ($path->[-2]||'') eq 'study_results'; return [ $type, $payload.' IN MICE' ]; } ], $ddc->expand($data)); will return: [ hash => [ [ 'study_results' ], { study_results => [ array => [ [ string => 'Sense Of Touch Is Formed In the Brain Before Birth IN MICE' ], [ string => "We can't currently cure MS but a single cell could change that IN MICE", ], ] ] } ] ] If a hashref is found, then the values are expected to be transforms, and DDC will use "$hashref->{$type}||$hashref->{_}" as the transform, or skip if neither is present. So the previous example could be written as: $ddc->transform([ { string => sub { my ($self, $type, $payload, $path) = @_; return unless ($path->[-2]||'') eq 'study_results'; return [ $type, $payload.' IN MICE' ]; } } ], $ddc->expand($data)); If the value of the spec entry itself *or* the relevant hash value is an arrayref, it is assumed to contain a spec for trailing path entries, with the last element being the transform subroutine. A path entry match can be an exact scalar (tested via "eq" since it works fine for both strings and integer array indices), regexp, "undef" to indicate "any value is fine here", or a subroutine which will be called with the path entry as both $_[0] and $_. So the example we've been using could also be written as: $ddc->transform([ { string => [ 'study_results', undef, sub { [ string => $_[2].' IN MICE' ] } ] } ], $ddc->expand($data)); or $ddc->transform([ { string => [ qr/^study_results$/, sub { 1 }, sub { [ string => $_[2].' IN MICE' ] } ] } ], $ddc->expand($data)); Note that while the $tfspec is not passed to transform subroutines, for the duration of the "transform" call the "transforms" option is localised to the provided routine, so sub { my ($self, $type, $payload, $path) = @_; my $tfspec = $self->transforms; ... } will return the top level $tfspec passed to the transform call. Thanks to for the inspiration. format my $formatted = $ddc->format($exp); Takes expanded tagged data and renders it to a formatted string, suitable for printing or warning or etc. Accepts the following type tags: "array", "list", "hash", "key", "string", "thing". Arrays and hashes are formatted as compactly as possible within the constraint of "max_width", but if overflow occurs then DDC falls back to spilling everything vertically, so newlines are used for most spacing and therefore it doesn't exceed the max width any more than strictly necessary. Strings are formatted as single quote if obvious, and double quote if not. Keys are treated as strings when present as hash values, but when an element of array values, are formatted ask "the_key =>" where possible. Lists are formatted as single line "qw()" expressions if possible, or "( ... )" if not. Arrays and hashes are formatted in the manner to which one would hope readers are accustomed, except more compact. ALGORITHM The following is a description of the current algorithm of DDC. We reserve the right to change it for the better. If you didn't already read the overview examples in "WHY" do that first. Vertical mode means DDC has given up on fitting within the desired width and is now just trying to not use *too* much vertical space. Oneline mode is DDC testing to see if a single line rendering of something will fit within the available space. Things will often be rendered more than once since DDC is optimising for compact readable output rather than raw straight line performance. Top level formatting If something is formatted and the remaining width is zero or negative, DDC accepts default on "max_width" and bails out to a fully vertical approach so it overflows the desired width no more than necessary. Array formatting If already in vertical mode, formats one array element per line, appended with ",": [ 1, 2, 3 ] If in possible oneline mode, formats all but the last element according to the "Array element" rules, the last element according to normal formatting, and joins them with ' ' in the hopes this is narrow enough. Return this if oneline is forced or it fits: [ 1, 2, 3 ] If there's only a single internal member, tries to use the "Single entry formatting" strategy to cuddle it. [ [ ] ] Otherwise, attempts to bundle things as best possible: Each element is formatted according to the "Array element" rules, and multiple results are concatenated together onto a single line where that still remains within the available width. [ 'foo', 'bar', 'baz', 'red', 'white', 'blue', ] Array element Elements are normally formatted as "$formatted.','" except if an element is of type "key" in which cases it becomes "$key =>". "whatever the smeg", smeg_off => List formatting The type "list" is synthetic and only introduced by transforms. It is formatted identically to an arrayref except with "( )" instead of "[ ]", with the exception that if it consists of only plain strings and will fit onto a single line, it formats as a "qw(x y x)" style list. qw(foo bar baz) ( 'foo', 'bar', 'baz', ) Single entry formatting Where possible, a single entry will be cuddled such that the opening delimiters are both on the first line, and the closing delimeters both on the final line, to reduce the vertical space consumption of nested single entry array and/or hashrefs. to => { -select => { ... } } [ 'SRV:8FB66F32' ], [ [ '/opt/voice-srvc-native/bin/async-srvc-att-gateway-poller', 33, 'NERV::Voice::SRV::Native::AsyncSRVATTGatewayPoller::main', ] ], Hash formatting If already in vertical mode, key/value pairs are formatted separated by newlines, with no attention paid to key length. { foo => ..., bar => ..., } If potentially in oneline mode, key/value pairs are formatted separated by ', ' and the value is returned if forced or if remaining width allows the oneline rendering. { foo => ..., bar => ... } Otherwise, all key/value pairs are formatted as "key => value" where possible, but if the first line of the value is too long, the value is moved to the next line and indented. key => 'shortvalue' key => 'overlylongvalue' If there's only a single such key/value pair, tries to use the "Single entry formatting" strategy to cuddle it. { zathrus => { listened_to => 0, } } Otherwise returns key/value pairs indented and separated by newlines { foo => ..., bar => ..., } String formatting Uses single quotes if sure that's safe, double quotes otherwise. 'foo bar baz quux' "could have been '' but nicer to not screw up\n the indents with a newline" Attempts to format a string within the available width, using multiple lines and the "." concatenation operator if necessary,. 'this would be an' .'annoyingly long' .'string' The target width is set to 20 in vertical mode to try and not be too ugly. Object formatting Objects are tested to see if their underlying reference is an array or hash. If so, it's formatted with 'bless( ' prepended and ', $class)' appended. This so far appears to interact nicely with everything else. AUTHOR mst - Matt S Trout (cpan:MSTROUT) CONTRIBUTORS None so far. COPYRIGHT Copyright (c) 2019 the Data::Dumper::Compact "AUTHOR" and "CONTRIBUTORS" as listed above. LICENSE This library is free software and may be distributed under the same terms as perl itself. See . Data-Dumper-Compact-0.006000/META.yml0000644000000000000000000000156614313630272016706 0ustar00rootroot00000000000000--- abstract: 'Vertically compact width-limited data formatter' author: - 'mst - Matt S Trout (cpan:MSTROUT) ' build_requires: Test::More: '0.88' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 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 version: '1.4' name: Data-Dumper-Compact no_index: directory: - t - xt requires: Class::Method::Modifiers: '0' Mu::Tiny: '0.000002' 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.006000' x_authority: cpan:MSTROUT x_breaks: {} x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Data-Dumper-Compact-0.006000/MANIFEST0000644000000000000000000000123314313630273016556 0ustar00rootroot00000000000000Changes ex/deep1 ex/deep10 ex/deep2 ex/deep3 ex/deep4 ex/deep5 ex/deep6 ex/deep7 ex/deep8 ex/deep9 ex/jdeep1 ex/jdeep10 ex/jdeep2 ex/jdeep3 ex/jdeep4 ex/jdeep5 ex/jdeep6 ex/jdeep8 ex/jdeep9 lib/Data/Dumper/Compact.pm lib/Devel/DDCWarn.pm lib/JSON/Dumper/Compact.pm 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) LICENSE LICENSE file (added by Distar) Data-Dumper-Compact-0.006000/lib/0000755000000000000000000000000014313630272016173 5ustar00rootroot00000000000000Data-Dumper-Compact-0.006000/lib/Devel/0000755000000000000000000000000014313630272017232 5ustar00rootroot00000000000000Data-Dumper-Compact-0.006000/lib/Devel/DDCWarn.pm0000644000000000000000000001441614313630215021015 0ustar00rootroot00000000000000package Devel::DDCWarn; use strictures 2; use Data::Dumper::Compact; use base qw(Exporter); our $VERSION = '0.006000'; $VERSION =~ tr/_//d; our @EXPORT = map +($_, $_.'T'), qw(Df Dto Dwarn Derr); our $ddc = Data::Dumper::Compact->new; sub import { my ($class, @args) = @_; my $opts; if (@args and ref($args[0]) eq 'HASH') { $opts = shift @args; } else { while (@args and $args[0] =~ /^-(.*)$/) { my $k = $1; my $v = (shift(@args), shift(@args)); $opts->{$k} = $v; } } $ddc = Data::Dumper::Compact->new($opts) if $opts; return if @args == 1 and $args[0] eq ':none'; $class->export_to_level(1, @args); } sub _ef { map +(@_ > 1 ? [ list => $_ ] : $_->[0]), [ map $ddc->expand($_), @_ ]; } sub Df { $ddc->format(_ef(@_)) } sub DfT { my ($tag, @args) = @_; my @fmt = (ref($tag) eq 'ARRAY' ? do { ($tag, my $tweak) = @$tag; _ef($tweak->(@args)) } : _ef(@args) ); $ddc->format([ list => [ [ key => $tag ], @fmt ] ]); } sub _dto { my ($fmt, $noret, $to, @args) = @_; return unless @args > $noret; $to->($fmt->(@args)); return wantarray ? @args[$noret..$#args] : $args[$noret]; } sub Dto { _dto(\&Df, 0, @_) } sub DtoT { _dto(\&DfT, 1, @_) } my $W = sub { warn $_[0] }; sub Dwarn { Dto($W, @_) } sub DwarnT { DtoT($W, @_) } sub Dwarn1 { return () unless @_; my $one = shift; wantarray ? (Dwarn($one), @_) : Dwarn($one) } my $E = sub { print STDERR $_[0] }; sub Derr { Dto($E, @_) } sub DerrT { DtoT($E, @_) } sub Derr1 { return () unless @_; my $one = shift; wantarray ? (Derr($one), @_) : Derr($one) } 1; =head1 NAME Devel::DDCWarn - Easy printf-style debugging with L =head1 SYNOPSIS use Devel::DDCWarn; my $x = Dwarn some_sub_call(); # warns and returns value my @y = Derr other_sub_call(); # prints to STDERR and returns value my $x = DwarnT X => some_sub_call(); # warns with tag 'X' and returns value my @y = DerrT X => other_sub_call(); # similar =head1 DESCRIPTION L is a L equivalent for L. The idea, basically, is that it's incredibly annoying to start off with code like this: return some_sub_call(); and then realise you need the value, so you have to write: my @ret = some_sub_call(); warn Dumper [ THE_THING => @ret ]; return @ret; With L, one can instead write: return DwarnT THE_THING => some_sub_call(); and expect it to Just Work. To integrate with your logging, you can do: our $L = sub { $log->debug("DDC debugging: ".$_[0] }; ... return DtoT $L, THE_THING => some_sub_call(); When applying printf debugging style approaches, it's also very useful to be able to do: perl -MDevel::DDCwarn ... and then within the code being debugged, abusing the fact that a prefix of :: is short for main:: so we can add: return ::DwarnT THE_THING => some_sub_call(); and if we forget to remove them, the lack of command-line L exported into main:: will produce a compile time failure. This is exceedingly useful for noticing you forgot to remove a debug statement I you commit it along with the test and fix. =head1 EXPORTS All of these subroutines are exported by default. L is referred to herein as DDC. =head2 Dwarn my $x = Dwarn make_x(); my @y = Dwarn make_y_array(); Cs the L DDC dump of its input, then returns the first element in scalar context or all arguments in list context. =head2 Derr my $x = Derr make_x(); my @y = Derr make_y_array(); prints the L DDC dump of its input to STDERR, then returns the first element in scalar context or all arguments in list context. =head2 DwarnT my $x = Dwarn TAG => make_x(); my @y = Dwarn TAG => make_y_array(); Like L, but passes its first argument, the tag, through to L but skips it for the return value. =head2 DerrT my $x = Derr TAG => make_x(); my @y = Derr TAG => make_y_array(); Like L, but accepts a tag argument that is included in the output but is skipped for the return value. =head2 Dto Dto(sub { warn $_[0] }, @args); Like L, but instead of warning, calls the subroutine passed as the first argument - this function is low level but still returns the C<@args>. =head2 DtoT DtoT(sub { err $_[0] }, $tag, @args); The tagged version of L. =head2 Df my $x = Df($thing); my $y = Df(@other_things); A single value is returned formatted by DDC. Multiple values are transformed to a DDC list. =head2 DfT my $x = Df($tag => $thing); my $y = Df($tag => @other_things); A tag plus a single value is formatted as a two element list. A tag plus multiple values is formatted as a list containing the tag and a list of the values. If the tag is an arrayref, is assumed to be: my $x = Df([ $tag, $tweak ] => @things); and what's dumped is C<<$tweak->(@things)>> instead of C<@things>. This means that e.g. one can write: return Dwarn([ foo => sub { +{ @_ } } ], %things); to output the things as a hashref while still returning a flattened hash. =head1 CONFIGURATION use Devel::DDCWarn \%options, ...; perl -MDevel::DDCWarn=-optname,value,-other,value ...; $Devel::DDCWarn::ddc = Data::Dumper::Compact->new(\%options); Options passed as a hashref on a C line or using - prefixing on the command line are used to initialise the L object. Note that this primarily being a debugging and/or scripting oriented tool, if something initialises us again later, this will reset the (single) global C<$ddc> used by this code and change all output throught the process. However, if you need a localised change of formatting style, C<$ddc> is a full fledged global so you are absolutely allowed to C it: my $ddc = Data::Dumper::Compact->new(\%my_local_options); local $Devel::DDCWarn::ddc = $ddc; If you have a convincing reason for using this functionality in a way where the globality is a bug rather than a feature, please start a conversation with the authors so we can figure out what to do about it. =head1 COPYRIGHT Copyright (c) 2019 the L and L as listed in L. =head1 LICENSE This library is free software and may be distributed under the same terms as perl itself. See L. =cut Data-Dumper-Compact-0.006000/lib/Data/0000755000000000000000000000000014313630272017044 5ustar00rootroot00000000000000Data-Dumper-Compact-0.006000/lib/Data/Dumper/0000755000000000000000000000000014313630272020300 5ustar00rootroot00000000000000Data-Dumper-Compact-0.006000/lib/Data/Dumper/Compact.pm0000644000000000000000000010426314313630215022227 0ustar00rootroot00000000000000package Data::Dumper::Compact; use List::Util qw(sum); use Scalar::Util qw(blessed reftype); use Data::Dumper (); use Mu::Tiny; our $VERSION = '0.006000'; $VERSION =~ tr/_//d; sub import { my ($class, $ddc, $opts) = @_; return unless defined($ddc); die "Don't know how to export '$ddc'" unless ($ddc||'') =~ /^[jd]dc$/; my $targ = caller; my $cb = $class->new($opts||{})->dump_cb; no strict 'refs'; *{"${targ}::${ddc}"} = $cb; } lazy max_width => sub { 78 }; lazy width => sub { shift->max_width }; lazy indent_width => sub { length($_[0]->indent_by) }; sub _next_width { $_[0]->width - $_[0]->indent_width } lazy indent_by => sub { ' ' }; lazy transforms => sub { [] }; sub add_transform { push(@{$_[0]->transforms}, $_[1]); $_[0] } sub _indent { my ($self, $string) = @_; my $ib = $self->indent_by; $string =~ s/^/$ib/msg; $string; } lazy dumper => sub { my ($self) = @_; my $dd = Data::Dumper->new([]); $dd->Trailingcomma(1) if $dd->can('Trailingcomma'); $dd->Terse(1)->Indent(1)->Useqq(1)->Deparse(1)->Quotekeys(0)->Sortkeys(1); my $indent_width = $self->indent_width; # feed the indent width down into B::Deparse - not using tabs because # it has no way to tell it how wide a tab is that I could find my $dp_new = do { require B::Deparse; my $orig = \&B::Deparse::new; sub { my ($self, @args) = @_; $self->$orig('-si'.$indent_width, @args) } }; sub { no warnings 'redefine'; local *B::Deparse::new = $dp_new; $dd->Values([ $_[0] ])->Dump }, }; sub _dumper { $_[0]->dumper->($_[1]) } sub _optify { my ($self, $opts, $method, @args) = @_; # if we're an object, localize anything provided in the options, # and also blow away the dependent attributes if indent_by is changed ref($self) and $opts and (local @{$self}{keys %$opts} = values %$opts, 1) and $opts->{indent_by} and delete @{$self}{grep !$opts->{$_}, qw(indent_width dumper)}; ref($self) or $self = $self->new($opts||{}); $self->$method(@args); } sub dump { my ($self, $data, $opts) = @_; $self->_optify($opts, sub { my ($self) = @_; $self->format($self->transform($self->transforms, $self->expand($data))); }); } sub dump_cb { my ($self) = @_; return sub { $self->dump(@_) }; } sub expand { 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->{$_}, [ key => $_ ])), sort keys %$data } ] ]; } elsif (ref($data) eq 'ARRAY') { my $idx = 0; return [ array => [ map $self->expand($_, [ idx => $idx++ ]), @$data ] ]; } elsif (blessed($data) and my $ret = $self->_expand_blessed($data)) { return $ret; } (my $thing = $self->_dumper($data)) =~ s/\n\Z//; # -foo and friends automatically become 'key' type, all else stays 'string' if (my ($string) = $thing =~ /^"(.*)"$/) { return [ ($string =~ /^-[a-zA-Z]\w*$/ ? 'key' : 'string') => $string ]; } return [ thing => $thing ]; } sub _expand_blessed { my ($self, $blessed) = @_; return unless grep { $_ eq 'ARRAY' or $_ eq 'HASH' } reftype($blessed); my $cursed = reftype($blessed) eq 'ARRAY' ? [ @$blessed ] : { %$blessed }; return [ blessed => [ $self->expand($cursed), blessed($blessed) ] ]; } sub transform { my ($self, $tfspec, $exp) = @_; return $exp unless $tfspec; # This is redundant from ->dump but consistent for direct user calls local $self->{transforms} = $tfspec; $self->_transform($exp, []); } sub _transform { my ($self, $exp, $path) = @_; my ($type, $payload) = @$exp; if ($type eq 'hash') { my %h = %{$payload->[1]}; $payload = [ $payload->[0], { map +( $_ => $self->_transform($h{$_}, [ @$path, $_ ]) ), sort keys %h }, ]; } elsif ($type eq 'array') { my @a = @$payload; $payload = [ map $self->_transform($a[$_], [ @$path, $_ ]), 0..$#a ]; } TF: foreach my $this_tf (@{$self->transforms}) { my $tf = $this_tf; my $last_tf = 0; while ($tf != $last_tf) { $last_tf = $tf; if (ref($tf) eq 'ARRAY') { my @match = @$tf; $tf = pop @match; next TF if @match > @$path; # not deep enough MATCH: foreach my $idx (0..$#match) { next MATCH unless defined(my $m = $match[$idx]); my $rpv = $path->[$idx-@match]; if (!ref($m)) { next TF unless $rpv eq $m; } elsif (ref($m) eq 'Regexp') { next TF unless $rpv =~ $m; } elsif (ref($m) eq 'CODE') { local $_ = $rpv; next TF unless $m->($rpv); } else { die "Unknown path match type for $m"; } } } elsif (ref($tf) eq 'HASH') { next TF unless $tf = $tf->{$type}||$tf->{_}; } } ($type, $payload) = @{ $self->$tf($type, $payload, $path) || [ $type, $payload ] }; } return [ $type, $payload ]; } sub format { my ($self, $exp) = @_; return $self->_format($exp)."\n"; # If we realise we've flat run out of horizontal space, we need to be able # to jump back up the call stack to the top and start again - hence the # presence of this label to jump to from _format - of course, if that # clause never gets hit then our first _format call returns and therefore # the label is never reached. VERTICAL: local $self->{vertical} = 1; return $self->_format($exp)."\n"; } sub _format { my ($self, $exp) = @_; my ($type, $payload) = @$exp; if (!$self->{vertical} and $self->width <= 0) { # We've run out of horizontal space, engage 'vertical sprawl mode' and # restart from the top by jumping back up the current call stack to the # VERTICAL label in the top-level call to format. no warnings 'exiting'; goto VERTICAL; } return $self->${\"_format_${type}"}($payload); } sub _format_list { my ($self, $payload) = @_; my @plain = grep !/\s/, map $_->[1], grep $_->[0] eq 'string', @$payload; if (@plain == @$payload) { my $try = 'qw('.join(' ', @plain).')'; return $try if $self->{oneline} or length($try) <= $self->width; } return $self->_format_arraylike('(', ')', $payload); } sub _format_array { my ($self, $payload) = @_; $self->_format_arraylike('[', ']', $payload); } sub _format_el { my ($self, $el) = @_; return $el->[1].' =>' if $el->[0] eq 'key'; return $self->_format($el).','; } sub _format_arraylike { my ($self, $l, $r, $payload) = @_; if ($self->{vertical}) { return join("\n", $l, (map $self->_indent($self->_format($_).','), @$payload), $r); } return $l.$r unless my @pl = @$payload; my $last_pl = pop @pl; # We don't want 'foo =>' at the end of the array, so for the last # entry use plain _format which will render key-as-string, and don't # add a comma yet because we don't want a trailing comma on a single # line render my @oneline = do { local $self->{oneline} = 1; ((map $self->_format_el($_), @pl), $self->_format($last_pl)); }; if (!grep /\n/, @oneline) { my $try = join(' ', $l, @oneline, $r); return $try if $self->{oneline} or length $try <= $self->width; } local $self->{width} = $self->_next_width; if (@$payload == 1) { # single entry, re-format the payload without oneline set return $self->_format_single($l, $r, $self->_format($payload->[0])); } if (@$payload == 2 and $payload->[0][0] eq 'key') { my $s = (my $k = $self->_format_el($payload->[0])) .' '.$self->_format(my $p = $payload->[1]); return $self->_format_single($l, $r, do { $s =~ /\A(.{0,${\$self->width}})(?:\n|\Z)/ ? $s : $k."\n".do { local $self->{width} = $self->_next_width; $self->_indent($self->_format($p)); } }); } my @lines; my @bits; $oneline[-1] .= ','; # going into multiline mode, *now* we add the comma foreach my $idx (0..$#$payload) { my $spare = $self->width - sum((scalar @bits)+1, map length($_), @bits); my $f = $oneline[$idx]; if ($f !~ /\n/) { # single line entry, add to the bits for the current line if it'll fit # otherwise collapse bits into a line and start afresh with this entry if (length($f) <= $spare) { push @bits, $f; next; } if (length($f) <= $self->width) { push(@lines, join(' ', @bits)); @bits = ($f); next; } } # If it didn't format as a single line, re-format to avoid confusion $f = $self->_format_el($payload->[$idx]); # if we can fit the first line in the available remaining space in the # current line, do that if ($spare > 0 and $f =~ s/^(.{0,${spare}})\n//sm) { push @bits, $1; } push(@lines, join(' ', @bits)) if @bits; @bits = (); # if the last line is less than our available width, turn that into # an entry in a new line if ($f =~ s/(?:\A|\n)(.{0,${\$self->width}})\Z//sm) { push @bits, $1; } # stuff whatever's left from the middle into the line array push(@lines, $f) if length($f); } push @lines, join(' ', @bits) if @bits; return join("\n", $l, (map $self->_indent($_), @lines), $r); } sub _format_hashkey { my ($self, $key) = @_; ($key =~ /^-?[a-zA-Z_]\w*$/ ? $key # stick a space on the front to force dumping of e.g. 123, then strip it : do { s/^" //, s/"\n\Z// for my $s = $self->_dumper(" $key"); $self->_format_string($s) } ).' =>'; } sub _format_hash { my ($self, $payload) = @_; my ($keys, $hash) = @$payload; return '{}' unless @$keys; @$keys = sort @$keys; my %k = (map +( $_ => $self->_format_hashkey($_)), @$keys ); if ($self->{vertical}) { return join("\n", '{', (map $self->_indent($k{$_}.' '.$self->_format($hash->{$_}).','), @$keys), '}'); } my $oneline = do { local $self->{oneline} = 1; join(' ', '{', join(', ', map $k{$_}.' '.$self->_format($hash->{$_}), @$keys ), '}'); }; return $oneline if $self->{oneline}; return $oneline if $oneline !~ /\n/ and length($oneline) <= $self->width; my $width = local $self->{width} = $self->_next_width; my @f = map { my $s = $k{$_}.' '.$self->_format(my $p = $hash->{$_}); $s =~ /\A(.{0,${width}})(?:\n|\Z)/ ? $s : $k{$_}."\n".do { local $self->{width} = $self->_next_width; $self->_indent($self->_format($p)); } } @$keys; local $self->{width} = $self->_next_width; if (@f == 1) { return $self->_format_single('{', '}', $f[0]); } return join("\n", '{', (map $self->_indent($_).',', @f), '}', ); } sub _format_key { shift->_format_string(@_) } sub _format_string { my ($self, $str) = @_; my $q = $str =~ /[\\']/ ? q{"} : q{'}; my $w = $self->{vertical} ? 20 : $self->_next_width; return $q.$str.$q if length($str) <= $w; $w--; my @f; while (length(my $chunk = substr($str, 0, $w, ''))) { push @f, $q.$chunk.$q; } return join("\n.", @f); } sub _format_thing { $_[1] } sub _format_single { my ($self, $l, $r, $raw) = @_; my ($first, @lines) = split /\n/, $raw; return join("\n", $l, $self->_indent($first), $r) unless @lines; (my $pad = $self->indent_by) =~ s/^ //; my $last = $lines[-1] =~ /^[\}\]\)]/ ? (pop @lines).$pad: ''; local $self->{width} = $self->_next_width; return join("\n", $l.($l eq '{' ? ' ' : $pad).$first, (map $self->_indent($_), @lines), $last.$r ); } sub _format_blessed { my ($self, $payload) = @_; my ($content, $class) = @$payload; 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__ =head1 NAME Data::Dumper::Compact - Vertically compact width-limited data formatter =head1 SYNOPSIS Basic usage as a function: use Data::Dumper::Compact 'ddc'; warn ddc($some_data_structure); warn ddc($some_data_structure, \%options); Slightly more clever usage as a function: use Data::Dumper::Compact ddc => \%default_options; warn ddc($some_data_structure); warn ddc($some_data_structure, \%extra_options); OO usage: use Data::Dumper::Compact; warn Data::Dumper::Compact->dump($data, \%options); my $ddc = Data::Dumper::Compact->new(\%options); warn $ddc->dump($data); warn $ddc->dump($data, \%extra_options); =head1 DESCRIPTION L, henceforth referred to as DDC, was born because I was annoyed at valuable wasted whitespace paging through both L and L based logs - L attempts to format horizontally first, but then if it fails, immediately switches to formatting fully vertically, rather than trying to e.g. format a six element arrayref three per line. So here's a few of the specifics (noting that all examples unless otherwise specified are dumped with default options): =head2 Arrays and Strings Given arrays consisting of reasonably long strings, DDC does its best to produce a sane representation within its L: [ 1, 2, [ 'longstringislonglongstringislonglongstringislong', 'longstringislonglongstringislong', 'longstringislong', 'longstringislonglongstringislonglongstringislong', 'longstringislong', 'longstringislonglongstringislong', 'longstringislong', 'longstringislonglongstringislong', 'longstringislonglongstringislonglongstringislong', 'longstringislonglongstringislong', 'longstringislonglongstringislong', 'longstringislonglongstringislonglongstringislong', 'longstringislong', 'longstringislong', 'longstringislonglongstringislonglongstringislong', 'longstringislong', 'longstringislong', 'longstringislong', 'longstringislonglongstringislong', 'longstringislonglongstringislonglongstringislong', 'a', 'b', 'c', 'longstringislonglongstringislonglongstringislonglongstringislong', 'longstringislonglongstringislonglongstringislonglongstringislong', 'longstringislonglongstringislonglongstringislonglongstringislong', ], 3, ] =head2 Keys and Hashrefs When faced with a C<-foo> style value, it gets a C<< => >> even in an array, and hash values that we can are single-line formatted: [ 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', [ 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', ], -blah => { baz => 'quux', foo => 'bar' }, ] =head2 The String Thing Strings are single quoted when DDC is absolutely sure that's safe, and double quoted otherwise: [ { -foo => { bar => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', baz => "bbbbbbbbbbbbbbbbbbbb\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", } } ] =head2 Lonely hash key When a single hash key can't be formatted in a oneline form within the length, DDC will try spilling it to its own line: { -xxxxxxxxxxxxx => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' } If even that isn't enough, it formats it below and indented: { -xxxxxxxxxxxxx => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' } =head2 Strings and the dot operator If a string simply won't fit, DDC splits it and indents it using C<.>: [ 'xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyx' .'yxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy' .'xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyx' .'yxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy' ] =head2 Unknown unknowns Anything DDC doesn't understand is passed through its L option, though since L (at the time of writing) forgets to pass through its indentation level to L, we slightly tweak that behaviour on the way in for the default L. But the end result looks like: { foo => { bar => sub { use warnings; use strict 'refs'; my($x, $y) = @_; return $x * $y; } } } =head2 Bless you When encountering an object, if it's a blessed array or hashref, DDC will attempt to format that too: [ bless( { x => 3, y => [ 'foo', 'bar', 'baz', 'quux', 'fleem', 'blather', 'obrien' ], z => 'lololololololololololololololol', }, "OhGods::Lol" ) ] =head2 All together now The full set of behaviours allows compact (and, we hope, readable) versions of complex data structures. To provide one of the examples that expired this module - here is the formatting under standard options for a moderately complex L update statement: { _ => [ 'tree_table', -join => { as => 'tree', on => { 'tree.id' => 'tree_with_path.id' }, to => { -select => { from => 'tree_with_path', select => '*', with_recursive => [ [ 'tree_with_path', 'id', 'parent_id', 'path' ], { -select => { _ => [ 'id', 'parent_id', { -as => [ { -cast => { -as => [ 'id', 'char', 255 ] } }, 'path', ] }, ], from => 'tree_table', union_all => { -select => { _ => [ 't.id', 't.parent_id', { -as => [ { -concat => [ 'r.path', \"'/'", 't.id' ] }, 'path', ] }, ], from => [ 'tree_table', -as => 't', -join => { as => 'r', on => { 't.parent_id' => 'r.id' }, to => 'tree_with_path', }, ], } }, where => { parent_id => undef }, } }, ], } }, }, ], set => { path => { -ident => [ 'tree', 'path' ] } }, } And the version (generated by setting L to C<40>) that runs out of space and thereby forces the "spill vertically" logic to kick in while still attemping to be at least somewhat compact: { _ => [ 'tree_table', '-join', { as => 'tree', on => { 'tree.id' => 'tree_with_path.id', }, to => { -select => { from => 'tree_with_path', select => '*', with_recursive => [ [ 'tree_with_path', 'id', 'parent_id', 'path', ], { -select => { _ => [ 'id', 'parent_id', { -as => [ { -cast => { -as => [ 'id', 'char', 255, ], }, }, 'path', ], }, ], from => 'tree_table', union_all => { -select => { _ => [ 't.id', 't.parent_id', { -as => [ { -concat => [ 'r.path', \"'/'", 't.id', ], }, 'path', ], }, ], from => [ 'tree_table', '-as', 't', '-join', { as => 'r', on => { 't.parent_id' => 'r.id', }, to => 'tree_with_path', }, ], }, }, where => { parent_id => undef, }, }, }, ], }, }, }, ], set => { path => { -ident => [ 'tree', 'path', ], }, }, } =head2 Summary Hopefully it's clear what the goal is, and what we've done to achieve it. While the system is already somewhat configurable, further options are almost certainly implementable, although if you really want such an option then we expect you to turn up with documentation and test cases for it so we just have to write the code. =head1 OPTIONS =head2 max_width Represents the width that DDC will attempt to keep as the maximum (if something overflows it in spite of our best efforts, DDC will fall back to a more vertically sprawling format to at least overflow as little as feasible). Default: C<78> =head2 indent_by The string to indent by. To set e.g. 4 space indent, pass C<' 'x4>. Default: C<' '> (two spaces). =head2 indent_width How many characters one indent should be considered to be. Generally you only need to manually set this if your L is C<"\t">. Default: C<< length($self->indent_by) >> =head2 transforms Set of transforms to apply on every L operation. See L for more information. Default: C<[]> =head2 dumper The dumper function to be used for dumping things DDC doesn't understand, such as coderefs, regexprefs, etc. Defaults to the same options as L (which is, itself, only a L configuration albeit it comes with L which is rather more interesting) - although on top of that we add a little bit of extra cleverness to make L use the correct indentation, since for some reason L doesn't (at the time of writing) do that. If you supply it yourself, it needs to be a single argument coderef - you could for example use C<\&Data::Dumper::Dumper> though that would almost certainly be pointless. =head1 EXPORTS =head2 ddc use Data::Dumper::Compact 'ddc'; use Data::Dumper::Compact 'ddc' => \%options; If the first argument to C/C is 'ddc', a subroutine C is installed in the calling package which behaves like calling L. If the second argument is a hashref, it becomes the options passed to L. This feature is effectively sugar over L, in that: Data::Dumper::Compact->import(ddc => \%options) is equivalent to: *ddc = Data::Dumper::Compact->new(\%options)->dump_cb; =head1 METHODS =head2 new my $ddc = Data::Dumper::Compact->new; my $ddc = Data::Dumper::Compact->new(%options); my $ddc = Data::Dumper::Compact->new(\%options); Constructor. Takes a hash or hashref of L =head2 dump my $formatted = Data::Dumper::Compact->dump($data, \%options?); my $formatted = $ddc->dump($data, \%merge_options?); This is the method you're going to want to call most of the time, and ties together the rest of the functionality into a single data-structure-to-string bundle. With just a data argument, it's equivalent to: $ddc->format( $ddc->transform( $ddc->transforms, $ddc->expand($data) ); In class method form, options provided are passed to L; in instance method form, options if provided are merged into C<$ddc> just for this invocation. =head2 dump_cb my $cb = $ddc->dump_cb; Returns a subroutine reference that's a curried call to L: $cb->($data, \%extra_options); # equivalent to $ddc->dump(...) Mostly useful for if you want to create a custom C like thing: use Data::Dumper::Compact; BEGIN { *Dumper = Data::Dumper::Compact->new->dump_cb } =head2 expand my $exp = $ddc->expand($data); Expands a data structure to DDC tagged data. The result is, recursively, [ $type, $payload ] where if $type is one of C, C, or C, the payload is a simple string (C meaning something unknown and therefore delegated to L). If the type is an array: [ array => \@values ] and if the type is a hash: [ hash => [ \@keys, \%value_map ] ] where the keys provide an order for formatting, and the value map is a hashref of keys to expanded values. A plain string becomes a C, unless it fits the C<-foo> style pattern that autoquotes, in which case it becomes a C. =head2 add_transform $ddc->add_transform(sub { ... }); $ddc->add_transform({ hash => sub { ... }, _ => sub { ... }); Appends a transform to C<< $ddc->transforms >>, see L for behaviour. Returns C<$ddc> to enable chaining. =head2 transform my $tf_exp = $ddc->transform($tfspec, $exp); Takes a transform specification and expanded tagged data and returns the transformed expanded expression. A transform spec is an arrayref containing transforms, where each transform is applied in order, so the last transform added via L will be the last one to transform the data (each transform will consist of a datastructure representing which parts of the C<$exp> tree it should be called for, plus subroutines representing the relevant transforms). Transform subroutines are called as a method on the C<$ddc> with the arguments of C<$type, $payload, $path> where C<$path> is an arrayref of the keys/values of the containing hashes and arrays, aggregated as DDC descends through the C<$exp> tree. Each transform is expected to return either nothing, to indicate it doesn't wish to modify the result, or a replacement expanded data structure. The simplest form of transform is a subref, which gets called for everything. So, to add ' IN MICE' to every string that's part of an array under a hash key called study_results, i.e.: my $data = { study_results => [ 'Sense Of Touch Is Formed In the Brain Before Birth'. "We can't currently cure MS but a single cell could change that", ] }; my $tf_exp = $ddc->transform([ sub { my ($self, $type, $payload, $path) = @_; return unless $type eq 'string' and ($path->[-2]||'') eq 'study_results'; return [ $type, $payload.' IN MICE' ]; } ], $ddc->expand($data)); will return: [ hash => [ [ 'study_results' ], { study_results => [ array => [ [ string => 'Sense Of Touch Is Formed In the Brain Before Birth IN MICE' ], [ string => "We can't currently cure MS but a single cell could change that IN MICE", ], ] ] } ] ] If a hashref is found, then the values are expected to be transforms, and DDC will use C<< $hashref->{$type}||$hashref->{_} >> as the transform, or skip if neither is present. So the previous example could be written as: $ddc->transform([ { string => sub { my ($self, $type, $payload, $path) = @_; return unless ($path->[-2]||'') eq 'study_results'; return [ $type, $payload.' IN MICE' ]; } } ], $ddc->expand($data)); If the value of the spec entry itself I the relevant hash value is an arrayref, it is assumed to contain a spec for trailing path entries, with the last element being the transform subroutine. A path entry match can be an exact scalar (tested via C since it works fine for both strings and integer array indices), regexp, C to indicate "any value is fine here", or a subroutine which will be called with the path entry as both C<$_[0]> and C<$_>. So the example we've been using could B be written as: $ddc->transform([ { string => [ 'study_results', undef, sub { [ string => $_[2].' IN MICE' ] } ] } ], $ddc->expand($data)); or $ddc->transform([ { string => [ qr/^study_results$/, sub { 1 }, sub { [ string => $_[2].' IN MICE' ] } ] } ], $ddc->expand($data)); Note that while the C<$tfspec> is not passed to transform subroutines, for the duration of the L call the L option is localised to the provided routine, so sub { my ($self, $type, $payload, $path) = @_; my $tfspec = $self->transforms; ... } will return the top level C<$tfspec> passed to the transform call. Thanks to L for the inspiration. =head2 format my $formatted = $ddc->format($exp); Takes expanded tagged data and renders it to a formatted string, suitable for printing or warning or etc. Accepts the following type tags: C, C, C, C, C, C. Arrays and hashes are formatted as compactly as possible within the constraint of L, but if overflow occurs then DDC falls back to spilling everything vertically, so newlines are used for most spacing and therefore it doesn't exceed the max width any more than strictly necessary. Strings are formatted as single quote if obvious, and double quote if not. Keys are treated as strings when present as hash values, but when an element of array values, are formatted ask C<< the_key => >> where possible. Lists are formatted as single line C expressions if possible, or C<( ... )> if not. Arrays and hashes are formatted in the manner to which one would hope readers are accustomed, except more compact. =head1 ALGORITHM The following is a description of the current algorithm of DDC. We reserve the right to change it for the better. If you didn't already read the overview examples in L do that first. Vertical mode means DDC has given up on fitting within the desired width and is now just trying to not use I much vertical space. Oneline mode is DDC testing to see if a single line rendering of something will fit within the available space. Things will often be rendered more than once since DDC is optimising for compact readable output rather than raw straight line performance. =head2 Top level formatting If something is formatted and the remaining width is zero or negative, DDC accepts default on L and bails out to a fully vertical approach so it overflows the desired width no more than necessary. =head2 Array formatting If already in vertical mode, formats one array element per line, appended with C<,>: [ 1, 2, 3 ] If in possible oneline mode, formats all but the last element according to the L rules, the last element according to normal formatting, and joins them with C<' '> in the hopes this is narrow enough. Return this if oneline is forced or it fits: [ 1, 2, 3 ] If there's only a single internal member, tries to use the L strategy to cuddle it. [ [ ] ] Otherwise, attempts to bundle things as best possible: Each element is formatted according to the L rules, and multiple results are concatenated together onto a single line where that still remains within the available width. [ 'foo', 'bar', 'baz', 'red', 'white', 'blue', ] =head2 Array element Elements are normally formatted as C<< $formatted.',' >> except if an element is of type C in which cases it becomes C<< $key => >>. "whatever the smeg", smeg_off => =head2 List formatting The type C is synthetic and only introduced by transforms. It is formatted identically to an arrayref except with C<( )> instead of C<[ ]>, with the exception that if it consists of only plain strings and will fit onto a single line, it formats as a C style list. qw(foo bar baz) ( 'foo', 'bar', 'baz', ) =head2 Single entry formatting Where possible, a single entry will be cuddled such that the opening delimiters are both on the first line, and the closing delimeters both on the final line, to reduce the vertical space consumption of nested single entry array and/or hashrefs. to => { -select => { ... } } [ 'SRV:8FB66F32' ], [ [ '/opt/voice-srvc-native/bin/async-srvc-att-gateway-poller', 33, 'NERV::Voice::SRV::Native::AsyncSRVATTGatewayPoller::main', ] ], =head2 Hash formatting If already in vertical mode, key/value pairs are formatted separated by newlines, with no attention paid to key length. { foo => ..., bar => ..., } If potentially in oneline mode, key/value pairs are formatted separated by C<', '> and the value is returned if forced or if remaining width allows the oneline rendering. { foo => ..., bar => ... } Otherwise, all key/value pairs are formatted as C<< key => value >> where possible, but if the first line of the value is too long, the value is moved to the next line and indented. key => 'shortvalue' key => 'overlylongvalue' If there's only a single such key/value pair, tries to use the L strategy to cuddle it. { zathrus => { listened_to => 0, } } Otherwise returns key/value pairs indented and separated by newlines { foo => ..., bar => ..., } =head2 String formatting Uses single quotes if sure that's safe, double quotes otherwise. 'foo bar baz quux' "could have been '' but nicer to not screw up\n the indents with a newline" Attempts to format a string within the available width, using multiple lines and the C<.> concatenation operator if necessary,. 'this would be an' .'annoyingly long' .'string' The target width is set to 20 in vertical mode to try and not be too ugly. =head2 Object formatting Objects are tested to see if their underlying reference is an array or hash. If so, it's formatted with 'bless( ' prepended and ', $class)' appended. This so far appears to interact nicely with everything else. =head1 AUTHOR mst - Matt S Trout (cpan:MSTROUT) =head1 CONTRIBUTORS None so far. =head1 COPYRIGHT Copyright (c) 2019 the Data::Dumper::Compact L and L as listed above. =head1 LICENSE This library is free software and may be distributed under the same terms as perl itself. See L. =cut Data-Dumper-Compact-0.006000/lib/JSON/0000755000000000000000000000000014313630272016744 5ustar00rootroot00000000000000Data-Dumper-Compact-0.006000/lib/JSON/Dumper/0000755000000000000000000000000014313630272020200 5ustar00rootroot00000000000000Data-Dumper-Compact-0.006000/lib/JSON/Dumper/Compact.pm0000644000000000000000000000765414313630215022135 0ustar00rootroot00000000000000package JSON::Dumper::Compact; use JSON::MaybeXS; use Mu::Tiny; use Class::Method::Modifiers; our $VERSION = '0.006000'; $VERSION =~ tr/_//d; extends 'Data::Dumper::Compact'; lazy json_obj => sub { JSON->new ->allow_nonref(1) ->relaxed(1) ->filter_json_single_key_object(__bless__ => sub { bless($_[0][1], $_[0][0]); }); }; sub _json_decode { shift->json_obj->decode(@_) } sub _build_dumper { my $j = shift->json_obj; sub { $j->encode($_[0]) } } sub _format_el { shift->_format(@_).',' } sub _format_hashkey { $_[0]->json_obj->encode($_[1]).':' } sub _format_string { '"'.$_[1].'"' } sub _format_thing { $_[1] } around _expand_blessed => sub { my ($orig, $self) = (shift, shift); my ($blessed) = @_; return $self->expand($blessed->TO_JSON) if $blessed->can('TO_JSON'); return $self->$orig(@_); }; sub _format_blessed { my ($self, $payload) = @_; my ($content, $class) = @$payload; $self->_format([ hash => [ [ '__bless__' ], { '__bless__' => [ array => [ [ string => $class ], $content ] ] }, ] ]); } 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 { my ($self, $data, $opts) = @_; $self->_optify($opts, _json_decode => $data); } 1; =head1 NAME JSON::Dumper::Compact - JSON processing with L aesthetics =head1 SYNOPSIS use JSON::Dumper::Compact 'jdc'; my $json = jdc($data); =head1 DESCRIPTION JSON::Dumper::Compact is a subclass of L that turns arrayrefs and hashrefs intead into JSON. Deep data structures are rendered highly compactly: [ "1556933590.65383", "Fri May 3 18:33:10 2019", 26794, "INFO", 3, [ "SRV:8FB66F32" ], [ [ "/opt/voice-srvc-native/bin/async-srvc-att-gateway-poller", 33, "NERV::Voice::SRV::Native::AsyncSRVATTGatewayPoller::main", ] ], "batch_nena_messages returned", "OK", 6, { "FILENAME": "lqxw020323" }, 1556933584, "lqxw020323", ] To ease debugging, blessed references without a C method are rendered as an object with a single two-element arrayref value: { "__bless__": [ "The::Class", { "the": "object" }, ] } =head1 METHODS In addition to the L methods, we provide: =head2 encode JSON::Dumper::Compact->encode($data, \%opts?); $jdc->encode($data, \%opts?); Operates identically to L but named to be less confusing to code expecting a JSON object. =head2 decode JSON::Dumper::Compact->decode($string, \%opts?); $jdc->decode($string, \%opts); Runs the supplied string through an L C with options set to be able to reliably reparse what we can currently format - notably setting C to allow for trailing commas and using C to re-inflate blessed objects. Note that using this method on untrusted data is a security risk. While C/C should be usable for JSON formatting, in general, C fully rehydrates for debugging purposes and as such can e.g. cause DESTROY methods to be called unexpectedly, which can allow a malicious user to do things to your perl5 VM. Rather than using debugging specific code on untrusted data, use L or L directly (if the C output doesn't parse correctly via other libraries, please report that as a bug).. DO NOT USE THIS METHOD ON UNTRUSTED DATA IT WAS NOT DESIGNED TO BE SECURE. =head1 COPYRIGHT Copyright (c) 2019 the L and L as listed in L. =head1 LICENSE This library is free software and may be distributed under the same terms as perl itself. See L. =cut Data-Dumper-Compact-0.006000/t/0000755000000000000000000000000014313630272015670 5ustar00rootroot00000000000000Data-Dumper-Compact-0.006000/t/basic.t0000644000000000000000000000121513467127443017147 0ustar00rootroot00000000000000use strict; use warnings; use Test::More; use Data::Dumper::Compact; my $can_j = eval { require JSON::Dumper::Compact; 1 }; DEEP: foreach my $example (glob('ex/deep*')) { my $contents = do { local (@ARGV, $/) = $example; <> }; my $data = eval '+'.$contents; is(Data::Dumper::Compact->dump($data), $contents); if ($can_j) { (my $jfile = $example) =~ s/deep/jdeep/; next DEEP unless -e $jfile; my $jcont = do { local (@ARGV, $/) = $jfile; <> }; is(my $res = JSON::Dumper::Compact->dump($data), $jcont); is( Data::Dumper::Compact->dump(JSON::Dumper::Compact->decode($res)), $contents, ); } } done_testing; Data-Dumper-Compact-0.006000/t/circular.t0000644000000000000000000000105114313630051017651 0ustar00rootroot00000000000000use 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;