Acme-Data-Dumper-Extensions
view release on metacpan or search on metacpan
{
"abstract" : "Experimental Enhancements to core Data::Dumper",
"author" : [
"Kent Fredric <kentnl@cpan.org>"
],
"dynamic_config" : 1,
"generated_by" : "ExtUtils::MakeMaker version 7.3, CPAN::Meta::Converter version 2.150010",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"build" : {
"requires" : {}
},
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"Data::Dumper" : "0"
}
},
"test" : {
"requires" : {
"Test::More" : "0.89"
}
}
},
"provides" : {
"Acme::Data::Dumper::Extensions" : {
"file" : "lib/Acme/Data/Dumper/Extensions.pm",
"version" : "0.001000"
}
},
"release_status" : "stable",
"resources" : {
"bugtracker" : {
"web" : "https://github.com/kentnl/Acme-Data-Dumper-Extensions/issues"
},
"homepage" : "https://github.com/kentnl/Acme-Data-Dumper-Extensions",
---
abstract: 'Experimental Enhancements to core Data::Dumper'
author:
- 'Kent Fredric <kentnl@cpan.org>'
build_requires:
Test::More: '0.89'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 7.3, 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: Acme-Data-Dumper-Extensions
no_index:
directory:
- t
- inc
provides:
Acme::Data::Dumper::Extensions:
file: lib/Acme/Data/Dumper/Extensions.pm
version: '0.001000'
requires:
Data::Dumper: '0'
resources:
bugtracker: https://github.com/kentnl/Acme-Data-Dumper-Extensions/issues
homepage: https://github.com/kentnl/Acme-Data-Dumper-Extensions
license: http://dev.perl.org/licenses/
repository: git://github.com/kentnl/Acme-Data-Dumper-Extensions
version: '0.001000'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
Makefile.PL view on Meta::CPAN
my $MAINFILE = 'lib/' . do { ( my $x = $DISTNAME ) =~ s/-/\//g; $x }
. '.pm';
my %requirements = (
configure_requires => {
"ExtUtils::MakeMaker" => 0,
},
build_requires => {},
runtime_requires => {
"Data::Dumper" => 0,
},
test_requires => {
"Test::More" => "0.89",
},
);
my %merged_requirements = (
"ExtUtils::MakeMaker" => 0,
"Data::Dumper" => 0,
"Test::More" => 0.89,
);
my %meta = (
name => $DISTNAME,
license => ['perl'],
prereqs => {
configure => { requires => $requirements{configure_requires} },
build => { requires => $requirements{build_requires} },
runtime => { requires => $requirements{runtime_requires} },
lib/Acme/Data/Dumper/Extensions.pm view on Meta::CPAN
use 5.006; # our
use strict;
use warnings;
package Acme::Data::Dumper::Extensions;
our $VERSION = '0.001000';
# ABSTRACT: Experimental Enhancements to core Data::Dumper
# AUTHORITY
use Data::Dumper ();
use Exporter ();
my $DD_Defaults;
BEGIN {
no warnings 'once';
$DD_Defaults = {
Bless => q[bless],
Deepcopy => 0,
Deparse => 0,
Freezer => q[],
Indent => 2,
Maxdepth => 0,
Pad => q[],
Pair => q[ => ],
Purity => 0,
Quotekeys => 1,
Sortkeys => 0,
Terse => 0,
Toaster => q[],
Useperl => !( grep $_ eq 'Data::Dumper', @DynaLoader::dl_modules ),
Useqq => 0,
Varname => q[VAR],
};
$DD_Defaults->{Sparseseen} = 0 if eval { Data::Dumper->VERSION(2.136) };
$DD_Defaults->{Maxrecurse} = 1000 if eval { Data::Dumper->VERSION(2.153) };
$DD_Defaults->{Trailingcomma} = 0 if eval { Data::Dumper->VERSION(2.160) };
}
sub DD_Defaults {
{ %$DD_Defaults }
}
our $_new_with_defaults = sub {
my ( $self, $user_defaults ) = @_;
my $instance = $self->new( [] );
lib/Acme/Data/Dumper/Extensions.pm view on Meta::CPAN
};
our @EXPORT_OK = qw( $_new_with_defaults $_DumpValues );
BEGIN { *import = \&Exporter::import; }
1;
=head1 NAME
Acme::Data::Dumper::Extensions - Experimental Enhancements to core Data::Dumper
=head1 SYNOPSIS
use Data::Dumper;
use Acme::Data::Dumper::Extensions qw/$_new_with_defaults/;
local $Data::Dumper::Indent = 5;
my $instance = Data::Dumper->$_new_with_defaults({ }); # Indent is still 2!
$instance = Data::Dumper->$_new_with_defaults({
Indent => 4, # Easier initalizer
});
=head1 DESCRIPTION
This is just a testing ground for things that I'm suggesting for Data::Dumper.
It will likely be terrible because bolting on features after-the-fact its also
pretty ugly.
But its just a prototype.
For some, it will serve more as a proof-of-concept for various interfaces until
they get accepted into core.
=head1 EXPORTS
=head2 C<$_new_with_defaults>
This is a prototype function for construcing a Data::Dumper instance without
being prone to leak from other people using the global values.
At the time of this writing, if you need perfect consistency from Data::Dumper
in widely used code, you by necessity have to know every version of
Data::Dumper that exists, and know what the default values are of various
arguments, in order to revert them to your "known good" state if 3rd party
code decides to locally change those values for their own purposes.
Getting an instance of a Data::Dumper object before anyone tweaks those values
would also work, but trying to bet on getting loaded and getting an instance
before anyone else does is just foolhardy
Additionally, due to how C<< ->Values >> works, having a global instance of
Data::Dumper can lend itself to a memory leak and you have to take additional
care to make sure you free values passed to it.
=head3 Syntax
The name used here is C<$_new_with_defaults> as this makes it straight forward
to migrate code that uses this once its adopted, without needing to
monkey-patch Data::Dumper itself.
Data::Dumper->$_new_with_defaults( ... )
Data::Dumper->new_with_defaults( ... )
=head3 Arguments
# Using the defaults
Data::Dumper->$_new_with_defaults()
# Augmenting the defaults
Data::Dumper->$_new_with_defaults({ Name => value, Name => value });
The approach I've taken here is to ignore the standard arguments to C<new>,
because it wasn't clear to me how else to organise this with the existing
alternative interfaces.
Given there's an alternative way of passing the dump values, its suggested
to just use those until this part of the design is sorted out:
Data::Dumper->$_new_with_defaults()->Values([ stuff, to, dump ])->Dump();
Or use the other feature suggested in this module:
Data::Dumper->$_new_with_defaults()->$_DumpValues([ stuff, to, dump ]);
=head3 Unrecognised Features
I'm still not sure how to handle what happens when somebody passes the name
of a feature which doesn't exist yet, but does in a future version.
Ideally, calling C<$_new_with_defaults()> should give you the same results in
perpetuity ( or at least, from the date this feature gets added )
For now I think the best thing to do is die fatally if a feature that is
lib/Acme/Data/Dumper/Extensions.pm view on Meta::CPAN
This will just become a nightmare if somebody ever changes "The Default" for
a I<new> feature wherein, users have to I<< Opt-B<Out> >>, causing an
explosion on older versions where that feature didn't exist.
This should be a hazard to never even consider changing the default behaviour.
=head2 C<$_DumpValues>
This function is a helper that does what people who maintain a long-lived
C<Data::Dumper> instance generally desire: The ability to just set up an
instance, and then call it an arbitrary number of times with arbitrary inputs
and have it act without side effects.
However, the current implementation of Data::Dumper is such that if you have
an instance, you must B<first> store the data in the object, and B<then>
dump it, which introduces fun problems with your data living longer than you
intended it to.
Currently, you also must call C<< ->Reset >> after dumping to reset the
C<Seen> state.
This function is designed to be used atomically. Any pre-existing variable
state (eg: C<Names>, C<Values>, C<Seen> ) should be thouroughly ignored, and
any of those values will be left in a "reset" state after using this function.
t/proof-of-concept.t view on Meta::CPAN
use strict;
use warnings;
use Test::More 0.89;
plan tests => 10;
use Data::Dumper;
use Acme::Data::Dumper::Extensions qw/ $_new_with_defaults $_DumpValues /;
{
local $Data::Dumper::Indent = 10;
my $bad_instance = Data::Dumper->new( [] );
my $instance = Data::Dumper->$_new_with_defaults();
is( $instance->Indent, 2, "Indent not inherited from localisation" );
is( $bad_instance->Indent, 10, "Bad Indent inherited from localisation" );
$instance = Data::Dumper->$_new_with_defaults( { Indent => 4 } );
is( $instance->Indent, 4, "Indent passed from constructor" );
}
{
my $bad_instance = Data::Dumper->new( [qw( a b )] );
my $rval = scalar $bad_instance->$_DumpValues( [qw( xxx yyy )] );
my $local_plan = 3;
$local_plan -= unlike $rval, qr/[ab]/,
"DumpValues replaces constructor values";
$local_plan -= like $rval, qr/xxx/, "DumpValues gives new values";
$local_plan -=
is( scalar $bad_instance->Values, 0, "Instance values wiped" );
$local_plan == 0 or diag explain [ $rval, $bad_instance ];
}
{
my $bad_instance = Data::Dumper->new( [qw( a b )], [qw( first second )] );
{
my $rval = scalar $bad_instance->$_DumpValues( [qw( xxx yyy )] );
my $local_plan = 2;
$local_plan -= unlike $rval, qr/first/,
"DumpValues ignores preset value names";
$local_plan -= unlike + ( join q[], $bad_instance->Names ), qr/first/,
"Instance names wiped";
( run in 0.249 second using v1.01-cache-2.11-cpan-4d50c553e7e )