Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data::Dumper Feature request(s): new_with_defaults & DumpValues #16137

Open
p5pRT opened this issue Sep 4, 2017 · 1 comment
Open

Data::Dumper Feature request(s): new_with_defaults & DumpValues #16137

p5pRT opened this issue Sep 4, 2017 · 1 comment
Labels
dist-Data-Dumper issues in the dual-life blead-first Data-Dumper distribution type-library Wishlist

Comments

@p5pRT
Copy link

p5pRT commented Sep 4, 2017

Migrated from rt.perl.org#132027 (status was 'new')

Searchable as RT132027$

@p5pRT
Copy link
Author

p5pRT commented Sep 4, 2017

From @kentfredric

Created by @kentfredric

This feature request is for two new additional features to
Data​::Dumper, which make the most sense when used together.

The first of which should be implemented *before* adding any new syntax
features like RT#126812[1] and RT#126814[2]

The first feature, new_with_defaults, is sorely needed for anyone who
wants to write consistent future-proof code.

As it currently stands, anyone using Data​::Dumper in CPAN code in a
character-sensitive layer[3] needs to know​:

- The name of every possible feature
- The value their code wants to use for that feature

Which means every additional feature requires additional safeguards
*just* to defend against one reality​:

Anyone[7] setting $Data​::Dumper​::Foo will change the defaults for anyone
doing Data​::Dumper->new(), whether the latter party wanted that or not.

I've prototyped[3] an example implementation of how I expect this to
work, implemented as a wrapper around Data​::Dumper.

  local $Data​::Dumper​::Indent = 5;
  my $instance = Data​::Dumper->new_with_defaults({});
  say $instance->Indent; # 2 not 5

Naturally, there's a few logical warts inside, but they don't need to
exist when implemented natively, because a native implementation can
vulcanise itself against unwanted variable tampering without needing
double accounting.

There's more writing in my implementation docs, but the gist of it are,
Importantly​:

- new_with_defaults takes either 1 or 0 arguments ( Values and Names
  are unwanted , more on this later )

- the instance created should have the same settings/results,
  regardless of which version of Data​::Dumper you're using (at least,
  since the introduction of this feature)

- the instance created should be invulnerable to people setting
  $Data​::Dumper​::Indent and friends, either globally or locally, even
  if they set those values before creating the instance.

- the instance should support a hash of settings that match the exposed
  attribute names, to use as augments to the stock defaults

The overall design ethic is to create a Data​::Dumper interface that
doesn't need to retain state about the variables its dumping, beyond
being a *temporarily* necessary implementation detail.

The second feature, DumpValues, aims to address additional issues with
workflows that aim to create a single Data​::Dumper instance and
regularly re-use it​: The implied preservation of state in the existing
interfaces, as this can lead to memory leaks and corrupted dumps, due
to ->Seen() not having any automatic clearing mechanism, and needing
more developer hand-holding just to do what should be a default[5][8][9]

This I have also roughly prototyped the interface of[6], and the
essential logic is quite straight forward​:

  Data​::Dumper->new_with_defaults()->DumpValues( [ values ], [ names ] );

Should behave exactly as a *stock* unmodified call of

  Data​::Dumper​::Dumper( [values], [names] )

Does, but without all the risks of other people changing your defaults.

DumpValues should also *ignore* all and any predefined values of​:

- Seen
- Values
- Names

Including those passed in the event somebody did​:

  Data​::Dumper->new( $somevalues, $somenames )->DumpValues( $othervalues )

Additonally, DumpValues should *invalidate* any values of Seen, Names,
Values such that the instance would be as it was when first constructed
with ->new_with_defaults()

This is because those state preservation mechanics aren't deemed to be
incredibly useful for most people, and only introduce risks.

The way those mechanics are implemented seems as if they're there for
people who want to do advanced things with ->Seen() mechanics, but
those usecases are hard to come by, and its better to consider that as
an implementation detail, and people who desire the power of those more
advanced mechanics can simply not use ->DumpValues, and use the more
finely grained and controllable ->Dump.

NB​: I have no hard affinity for any of the names I've stated here, just
the approach taken seemed most consistent with the other existing
function names.

1​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=126812
2​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=126814
3​: https://github.com/dbsrgits/dbix-class/blob/dc7d89911b7bb98c30208cf73af522a99998dcd6/lib/DBIx/Class/_Util.pm#L416-L460
4​: https://metacpan.org/pod/release/KENTNL/Acme-Data-Dumper-Extensions-0.001000/lib/Acme/Data/Dumper/Extensions.pm#$_new_with_defaults
5​: https://github.com/dbsrgits/dbix-class/blob/dc7d89911b7bb98c30208cf73af522a99998dcd6/lib/DBIx/Class/_Util.pm#L456-L458
6​: https://metacpan.org/pod/release/KENTNL/Acme-Data-Dumper-Extensions-0.001000/lib/Acme/Data/Dumper/Extensions.pm#$_DumpValues
7​: https://grep.metacpan.org/search?q=Indent[%28]2[%29]&qd=&qft=
8​: https://grep.metacpan.org/search?q=[-][%3E]Values[%28]\s*\[\]&qd=&qft=
9​: https://grep.metacpan.org/search?q=%28%3Fi%3Adump%29.*[-][%3E]Reset[%28%3B\s]&qd=&qft=

Perl Info

Flags:
    category=library
    severity=wishlist
    module=Data::Dumper

Site configuration information for perl 5.26.0:

Configured by kent at Sun May 21 12:09:05 NZST 2017.

Summary of my perl5 (revision 5 version 26 subversion 0) configuration:
   
  Platform:
    osname=linux
    osvers=4.10.13-gentoo
    archname=x86_64-linux
    uname='linux katipo2 4.10.13-gentoo #48 smp preempt tue may 2 15:18:23 nzst 2017 x86_64 intel(r) core(tm) i5-2410m cpu @ 2.30ghz genuineintel gnulinux '
    config_args='-de -Dprefix=/home/kent/perl5/perlbrew/perls/5.26.0-RC1-nossp-sip13-nopmc-nodot -Ddefault_inc_excludes_dot -Doptimize= -fstack-protector-strong -fno-stack-protector -O3 -march=native -mtune=native -Dman1dir=none -Dman3dir=none -Accflags= -fstack-protector-strong -fno-stack-protector -DPERL_HASH_FUNC_SIPHASH13 -DPERL_DISABLE_PMC -Aldflags= -fstack-protector-strong -fno-stack-protector -Aeval:scriptdir=/home/kent/perl5/perlbrew/perls/5.26.0-RC1-nossp-sip13-nopmc-nodot/bin'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-fstack-protector-strong -fno-stack-protector -DPERL_HASH_FUNC_SIPHASH13 -DPERL_DISABLE_PMC -fwrapv -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    optimize=' -fstack-protector-strong -fno-stack-protector -O3 -march=native -mtune=native'
    cppflags='-fstack-protector-strong -fno-stack-protector -DPERL_HASH_FUNC_SIPHASH13 -DPERL_DISABLE_PMC -fwrapv -fno-strict-aliasing -pipe'
    ccversion=''
    gccversion='5.4.0'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags ='	-fstack-protector-strong -fno-stack-protector -L/usr/local/lib'
    libpth=/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include-fixed /usr/lib /usr/local/lib /lib/../lib64 /usr/lib/../lib64 /lib /lib64 /usr/lib64 /usr/local/lib64
    libs=-lpthread -lnsl -lndbm -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.24.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.24'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared	-fstack-protector-strong -fno-stack-protector -O3 -march=native -mtune=native -L/usr/local/lib'

Locally applied patches:
    RC1


@INC for perl 5.26.0:
    /home/kent/perl5/perlbrew/perls/5.26.0-RC1-nossp-sip13-nopmc-nodot/lib/site_perl/5.26.0/x86_64-linux
    /home/kent/perl5/perlbrew/perls/5.26.0-RC1-nossp-sip13-nopmc-nodot/lib/site_perl/5.26.0
    /home/kent/perl5/perlbrew/perls/5.26.0-RC1-nossp-sip13-nopmc-nodot/lib/5.26.0/x86_64-linux
    /home/kent/perl5/perlbrew/perls/5.26.0-RC1-nossp-sip13-nopmc-nodot/lib/5.26.0


Environment for perl 5.26.0:
    HOME=/home/kent
    LANG=en_NZ.UTF8
    LANGUAGE (unset)
    LC_CTYPE=en_NZ.UTF8
    LC_TIME=en_NZ.UTF8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/kent/.rvm/gems/ruby-2.1.2/bin:/home/kent/.rvm/gems/ruby-2.1.2@global/bin:/home/kent/.rvm/rubies/ruby-2.1.2/bin:/home/kent/perl5/perlbrew/bin:/home/kent/perl5/perlbrew/perls/5.26.0-RC1-nossp-sip13-nopmc-nodot/bin:/home/kent/.perl6/2013.04/bin:/home/kent/.gem/ruby/1.8/bin/:/usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/5.4.0:/usr/x86_64-pc-linux-gnu/x86_64-pc-linux-gnux32/gcc-bin/5.4.0:/usr/x86_64-pc-linux-gnu/arm-unknown-linux-gnueabi/gcc-bin/5.4.0:/usr/lib/llvm/4/bin:/usr/games/bin:/home/kent/.rvm/bin:/home/kent/.rvm/bin
    PERLBREW_BASHRC_VERSION=0.74
    PERLBREW_HOME=/home/kent/.perlbrew
    PERLBREW_MANPATH=/home/kent/perl5/perlbrew/perls/5.26.0-RC1-nossp-sip13-nopmc-nodot/man
    PERLBREW_PATH=/home/kent/perl5/perlbrew/bin:/home/kent/perl5/perlbrew/perls/5.26.0-RC1-nossp-sip13-nopmc-nodot/bin
    PERLBREW_PERL=5.26.0-RC1-nossp-sip13-nopmc-nodot
    PERLBREW_ROOT=/home/kent/perl5/perlbrew
    PERLBREW_VERSION=0.74
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@jkeenan jkeenan added the dist-Data-Dumper issues in the dual-life blead-first Data-Dumper distribution label Jul 5, 2021
@xenu xenu removed the affects-5.26 label Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dist-Data-Dumper issues in the dual-life blead-first Data-Dumper distribution type-library Wishlist
Projects
None yet
Development

No branches or pull requests

3 participants