Data-Dump-Streamer

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN

    },
    recommends => {
        # Core 5.007_003+
        'MIME::Base64' => 0,

        # Core 5.009_003+
        'Compress::Zlib' => 0,

        # CPAN
        'Algorithm::Diff' => 0,
        'PadWalker'       => '0.99',

        # optional for testing
        'Cpanel::JSON::XS' => 0,
    },
    meta_merge => {
        resources => {
            repository => 'https://github.com/demerphq/Data-Dump-Streamer'
        }
    },
);

META.json  view on Meta::CPAN

            "Module::Build" : "0",
            "perl" : "5.006"
         }
      },
      "runtime" : {
         "recommends" : {
            "Algorithm::Diff" : "0",
            "Compress::Zlib" : "0",
            "Cpanel::JSON::XS" : "0",
            "MIME::Base64" : "0",
            "PadWalker" : "0.99"
         },
         "requires" : {
            "B" : "0",
            "B::Deparse" : "0",
            "B::Utils" : "0",
            "Data::Dumper" : "0",
            "DynaLoader" : "0",
            "Exporter" : "0",
            "Hash::Util" : "0",
            "IO::File" : "0",

META.yml  view on Meta::CPAN

    file: lib/Data/Dump/Streamer.pm
    version: '2.42'
  Data::Dump::Streamer::Deparser:
    file: lib/Data/Dump/Streamer.pm
    version: '2.42'
recommends:
  Algorithm::Diff: '0'
  Compress::Zlib: '0'
  Cpanel::JSON::XS: '0'
  MIME::Base64: '0'
  PadWalker: '0.99'
requires:
  B: '0'
  B::Deparse: '0'
  B::Utils: '0'
  Data::Dumper: '0'
  DynaLoader: '0'
  Exporter: '0'
  Hash::Util: '0'
  IO::File: '0'
  Symbol: '0'

lib/Data/Dump/Streamer.pm  view on Meta::CPAN


use vars qw(
    $VERSION
    $XS_VERSION
    $AUTOLOAD
    @ISA
    @EXPORT @EXPORT_OK @EXPORT_FAIL %EXPORT_TAGS
    %Freeze
    %Thaw
    $DEBUG
    $HasPadWalker
);

$DEBUG= 0;
BEGIN { $HasPadWalker= eval "use PadWalker 0.99; 1"; }

BEGIN {
    $VERSION= '2.42';
    $XS_VERSION= $VERSION;
    $VERSION= eval $VERSION;    # used for beta stuff.
    @ISA= qw(Exporter DynaLoader);
    @EXPORT= qw(Dump DumpLex DumpVars);
    @EXPORT_OK= qw(
        Dump
        DumpLex

lib/Data/Dump/Streamer.pm  view on Meta::CPAN


  use Data::Dumper::Streamer as => 'DDS';

  # or if you prefer
  use Data::Dumper::Streamer;
  import Data::Dumper::Streamer as => 'DDS';

You can use any alias you like, but that doesn't mean you should.. Folks
doing as => 'DBI' will be mercilessly ridiculed.

=head2 PadWalker support

If PadWalker 1.0 is installed you can use DumpLex() to try to
automatically determine the names of the vars being dumped. As
long as the vars being dumped have my or our declarations in scope
the vars will be correctly named. Padwalker will also be used
instead of the B:: modules when dumping closures when it is available.

=head1 INTERFACE

=head2 Data::Dumper Compatibility

For drop in compatibility with the Dumper() usage of Data::Dumper, you may

lib/Data/Dump/Streamer.pm  view on Meta::CPAN

        }
        else {
            return __PACKAGE__->new();
        }
    }
}

=item DumpLex VALUES

DumpLex is similar to Dump except it will try to automatically determine
the names to use for the variables being dumped by using PadWalker to
have a poke around the calling lexical scope to see what is declared. If
a name for a var can't be found then it will be named according to the
normal scheme. When PadWalker isn't installed this is just a wrapper for
L<Dump()|/Dump>.

Thanks to Ovid for the idea of this. See L<Data::Dumper::Simple> for a
similar wrapper around L<Data::Dumper>.

=cut

sub DumpLex {
    if (!$HasPadWalker) {

        #warn( "Can't use DumpLex without ".
        #    "PadWalker v1.0 or later installed.");
        goto &Dump;
    }
    my $obj;
    if (blessed($_[0]) and blessed($_[0]) eq __PACKAGE__) {
        $obj= shift;
    }
    my @names;

    # = map {
    #        PadWalker::var_name(1,\$_)
    #        || PadWalker::var_name(1,\$_)
    #        (ref $_ && PadWalker::var_name(1,$_));
    #                $str
    #          } @_;
    #if ( !@names && @_ ) {

    my %pad_vars;
    foreach my $pad (PadWalker::peek_my(1), PadWalker::peek_our(1)) {
        while (my ($var, $ref)= each %$pad) {
            $pad_vars{ refaddr $ref } ||= $var;
        }
    }
    foreach (@_) {
        my $name;
        INNER: foreach (\$_, $_) {
            $name= $pad_vars{ refaddr $_}
                and last INNER;
        }

lib/Data/Dump/Streamer.pm  view on Meta::CPAN

                    if $s && $s !~ /^\*?\w+$/;
                $s
            } grep { defined } @$v
        ];
        return $self;
    }
    elsif (!defined wantarray) {
        $self->{unames}= [];
    }

    #elsif ( eval { require PadWalker; 1 } ) {
    #    print DDumper(PadWalker::peek_my(1));
    #    return $self;
    #}

    return wantarray ? @{ $self->{unames} || [] } : $self->{unames};
}

=item Terse

=item Terse BOOL

lib/Data/Dump/Streamer.pm  view on Meta::CPAN

        goto &$meth;
    }
    elsif ($meth =~ /[^A-Z]/) {
        Carp::confess "Unhandled method/subroutine call $AUTOLOAD";
    }
}

sub _get_lexicals {
    my $cv= shift;

    if ($HasPadWalker) {
        my ($names, $targs)= PadWalker::closed_over($cv);
        if ($PadWalker::VERSION < 1) {
            $names->{$_}= $names->{ $targs->{$_} } for keys %$targs;
        }
        else {
            %$names= (%$names, %$targs);
        }
        return $names;
    }

    my $svo= B::svref_2object($cv);
    my @pl_array= eval { $svo->PADLIST->ARRAY };

t/dump.t  view on Meta::CPAN


}
{
    my ($x, %y, @z);
    $x= \@z;
    our $global= \@z;
    my $res1= Dump($x, \%y, \@z)->Names(qw(x *y *z))->Out();
    my $res3= DumpVars(x => $x, -y => \%y, -z => \@z)->Out();
    is($res1, $res3, 'DumpVars');
    SKIP: {
        skip "needs PadWalker 0.99 or later", 3
            if !eval "use PadWalker 0.99; 1";
        my $res2= DumpLex($x, \%y, \@z)->Out();
        is($res1,                            $res2,      'DumpLex');
        is($res2,                            $res3,      'DumpLex eq DumpVars');
        is("" . DumpLex($x, $global)->Out(), <<'EXPECT', 'DumpLex w/global');
$x = [];
$global = $x;
EXPECT
    }
}
SKIP: {

t/lexicals.t  view on Meta::CPAN

use strict;
use warnings;

use Data::Dump::Streamer;
use Test::More tests => 14;
require "./t/test_helper.pl";
diag "\nPadWalker ",
    eval "use PadWalker 0.99; 1" ? qq($PadWalker::VERSION is) : "isn't",
    " installed";

$::No_Redump= $::No_Redump= 1;
$::No_Dumper= $::No_Dumper= 1;

{
    my $v= 'foo';
    my @v= ('f', 'o', 'o');
    my $z= 1;
    no warnings;



( run in 0.727 second using v1.01-cache-2.11-cpan-05444aca049 )