Data-Dumper-Simple-0.11/0000755000076500007650000000000010336505016017052 5ustar curtispoecurtispoe00000000000000Data-Dumper-Simple-0.11/Build.PL0000644000076500007650000000077610336505016020360 0ustar curtispoecurtispoe00000000000000use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'Data::Dumper::Simple', license => 'perl', dist_author => 'Curtis "Ovid" Poe ', dist_version_from => 'lib/Data/Dumper/Simple.pm', requires => { 'Test::More' => 0, 'Filter::Simple' => '0.77', }, add_to_cleanup => ['Data-Dumper-Simple-*'], create_makefile_pl => 'traditional', ); $builder->create_build_script(); Data-Dumper-Simple-0.11/Changes0000644000076500007650000000321110336505016020342 0ustar curtispoecurtispoe00000000000000Revision history for Perl extension Data::Dumper::Simple. 0.11 2005-11-15 - POD bug. Changed "autodump" to "autowarn" in POD. 0.10 2005-10-08 - Added POD tests. - Converted to Module::Build - Fixed tiny bug where import list error wasn't getting reported correctly (because I was missing 'strict'. Fancy that). 0.07 Thu May 19 2005 - Implemented patch from Tom Phoenix that makes parentheses optional (and a doc fix, too). - Fixed little-known bug that triggered indirect method call syntax. You can now do "diag Dumper($foo)" or "diag Dumper $foo" if you wish. 0.06 Monday Aug 2 2004 - Fixed variable with whitespace bug ($foo[ 4 ]). Added autowarning. Added ability to choose own name for &Dumper (helps with namespace collisions). 0.05 Sun Aug 01 2004 - taking a reference to an array or hash now lists the data structure as a reference in the output. Shoulda done that the first time. Perl Barbie says "Source filtering is *hard*" 0.04 Sun Aug 01 2004 - Commenting out a Dumper statement now works. 0.03 Sat Jul 31 15:30:00 PDT 2004 - Changed the filter from "code" to "executable". This will sometimes mean that quoted data could be inappropriately interpolated, but there appears to be an obscure bug in Filter::Simple. Still, this is a debugging module and it should not really be an issue. 0.02 Sat Jul 31 12:30:00 PDT 2004 - fixed tiny bug with how scalars were represented when a reference to one is taken. 0.01 Fri Jul 30 16:29:14 PDT 2004 - original version; created by make_project 0.1 Data-Dumper-Simple-0.11/lib/0000755000076500007650000000000010336505016017620 5ustar curtispoecurtispoe00000000000000Data-Dumper-Simple-0.11/lib/Data/0000755000076500007650000000000010336505016020471 5ustar curtispoecurtispoe00000000000000Data-Dumper-Simple-0.11/lib/Data/Dumper/0000755000076500007650000000000010336505016021725 5ustar curtispoecurtispoe00000000000000Data-Dumper-Simple-0.11/lib/Data/Dumper/Simple.pm0000644000076500007650000002322510336505016023520 0ustar curtispoecurtispoe00000000000000package Data::Dumper::Simple; $REVISION = '$Id: Simple.pm,v 1.10 2005/05/20 01:37:08 ovid Exp $'; $VERSION = '0.11'; use Filter::Simple; use Data::Dumper (); use strict; my $DUMPER_FUNCTION = 'Dumper'; my $AUTOWARN; my $COMMA = qr/(?:,|=>)/; my $ATOM = qr/(?!\d)[[:word:]]+/; my $SEP = qr/::/; my $NAME = qr/$SEP?$ATOM(?:$SEP$ATOM)*/; my $SCALAR = qr/\$$NAME/; my $ARRAY_ELEM = qr/\$$NAME\[[^]]+\]/; my $ARRAY = qr/\@$NAME/; my $HASH_ELEM = qr/\$$NAME\{[^}]+\}/; my $HASH = qr/\%$NAME/; my $VAR = qr/(?:$ARRAY|$HASH|$ARRAY_ELEM|$HASH_ELEM|$SCALAR)/; my $END_STMT = qr/(?=\s*[;}])/; my $ARG_LIST = qr/$VAR(?:\s*$COMMA\s*$VAR)*$END_STMT/; my $PAREN_LIST = qr/\([^)]+\)/; sub import { my ( $class, @args ) = @_; @args = $class->_validate_args(@args); my %args = @args; $DUMPER_FUNCTION = $args{as} if $args{as}; $AUTOWARN = $args{autowarn} if $args{autowarn}; } FILTER_ONLY executable => sub { # not using code due to a possible bug in Filter::Simple s{ $DUMPER_FUNCTION\s*($PAREN_LIST|$ARG_LIST) }{ my $args = $1; $args =~ s/^\((.*)\)$/$1/s; # strip parens, if any my ($references, $names) = _munge_argument_list($args); # keep it on a single line so users can comment it out my $output = "Data::Dumper->Dump( [$references], [qw/$names/] )"; if ($AUTOWARN) { $output = "$AUTOWARN($output)"; } "($output)"; # parens prevent accidental indirect method syntax }gex }; sub _validate_args { my ( $class, @args ) = @_; if ( @args % 2 ) { _croak("$class->import requires an even sized list"); } my %args = @args; if ( $args{as} && !_valid_sub_name( $args{as} ) ) { _croak("$args{as} is not a valid name for a subroutine"); } if ( $args{autowarn} ) { $args{autowarn} = 'warn' unless _valid_sub_name( $args{autowarn} ); } return %args; } sub _valid_sub_name { shift =~ /^[[:alpha:]][[:word:]]*$/ } sub _croak { require Carp; Carp::croak(shift); } sub _munge_argument_list { my $arguments = shift; my $sigils = '@%&'; my @raw_var_names = map { _strip_whitespace($_) } split /(?:,|=>)/ => $arguments; my @raw_escaped = @raw_var_names; my $varnames = join ' ' => map { s/(\\)?[$sigils]/$1 ? '$' : '*'/ge; s/\\//g; $_ } # turn @array into => [$*]array @raw_var_names; my $escaped_vars = join ', ' => map { s/\\\$/\$/g; $_ } # do not take a reference to a scalar map { s/(? is actually a source filter that replaces all instances of C in your code with a call to CDump()>. You can use the one function provided to make dumping variables for debugging a trivial task. Note that this is primarily a debugging tool. C offers a bit more than that, so don't expect this module to be more than it is. Note that if you strongly object to source filters, I've also released L. It does what this module does by it uses L instead of a source filter. Unfortunately, it has a few limitations and is not as powerful as this module. Think of L as a "proof of concept". =head2 The Problem Frequently, we use C to dump out some variables while debugging. When this happens, we often do this: use Data::Dumper; warn Dumper($foo, $bar, $baz); And we get simple output like: $VAR1 = 3; $VAR2 = 2; $VAR3 = 1; While this is usually what we want, this can be confusing if we forget which variable corresponds to which variable printed. To get around this, there is an extended interface to C: warn Data::Dumper->Dump( [$foo, $bar, $baz], [qw/*foo *bar *baz/] ); This provides much more useful output. $foo = 3; $bar = 2; $baz = 1; (There's more control over the output than what I've shown.) You can even use this to output more complex data structures: warn Data::Dumper->Dump( [$foo, \@array], [qw/*foo *array/] ); And get something like this: $foo = 3; @array = ( 8, 'Ovid' ); Unfortunately, this can involve a lot of annoying typing. warn Data::Dumper->Dump( [$foo, \%this, \@array, \%that], [qw/*foo *that *array *this/] ); You'll also notice a typo in the second array ref which can cause great confusion while debugging. =head2 The Solution With C you can do this instead: use Data::Dumper::Simple. warn Dumper($scalar, @array, %hash); Note that there's no need to even take a reference to the variables. The output of the above resembles this (sample data, of course): $scalar = 'Ovid'; @array = ( 'Data', 'Dumper', 'Simple', 'Rocks!' ); %hash = ( 'it' => 'does', 'I' => 'hope', 'at' => 'least' ); Taking a reference to an array or hash works as expected, but taking a reference to a scalar is effectively a no-op (because it can turn into a confusing reference to a reference); my $foo = { hash => 'ref' }; my @foo = qw/foo bar baz/; warn Dumper ($foo, \@foo); Produces: $foo = { 'hash' => 'ref' }; $foo = [ 'foo', 'bar', 'baz' ]; Note that this means similarly named variables can get quite confusing, as in the example above. If you already have a C<&Dumper> function, you can specify a different function name with the C key in the import list: use Data::Dumper::Simple as => 'display'; warn display( $scalar, @array, %hash ); Also, if you really, really can't stand typing C or C, you can turn on C: use Data::Dumper::Simple as => 'display', autowarn => 1; display($scalar, @array, $some->{ data }); Or you can send the output (as a list) to a different function: use Data::Dumper::Simple as => 'debug', autowarn => 'to_log'; sub to_log { my @data = @_; # some logging function } debug( $customer => @order_nums ); # yeah, we support the fat comma "=>" and newlines =head1 EXPORT The only thing exported is the Dumper() function. Well, actually that's not really true. Nothing is exported. However, a source filter is used to automatically rewrite any apparent calls to C so that it just Does The Right Thing. =head1 SEE ALSO =over 4 =item * Data::Dumper - Stringified perl data structures =item * Filter::Simple - Simplified source filtering =back =head1 BUGS This module uses a source filter. If you don't like that, don't use this. There are no known bugs but there probably are some as this is B. =head1 LIMITATIONS =over 4 =item * Calling with a sub Do not try to call C with a subroutine in the argument list: Dumper($foo, some_sub()); # Bad! The filter gets confused by the parentheses. Your author was going to fix this but it became apparent that there was no way that C could figure out how to name the return values from the subroutines, thus ensuring further breakage. So don't do that. =item * Multiple enreferencing Getting really crazy by using multiple enreferencing will confuse things (e.g., C<\\\\\\$foo>), don't do that, either. I might use C at some point to fix this if it's an issue. =item * Slices List and hash slices are not supported at this time. =item * String interpolation C can potentially interpolate if it's in a string. This is because of a weird edge case with "FILTER_ONLY code" which caused a failure on some items being dumped. I've fixed that, but made the module a wee bit less robust. This will hopefully be fixed in the next release of Text::Balanced. =item * Line numbers may be wrong Because this module uses a source filter, line numbers reported from syntax or other errors may be thrown off a little. This is probably a bug in the source filter implementation, which should use C<#line> directives. As a workaround until this is fixed, put a directive (such as C<#line 10000>) a few lines ahead of the suspected bug. If the error is reported as happening in line 10007, you know to look about eight lines below your directive for the bug. Be sure to remove the bogus directive once you find the bug! =item * The parentheses are optional, but the syntax isn't bulletproof If you try, it's not hard to confuse the parser. Patches welcome. =back Note that this is not a drop-in replacement for C. If you need the power of that module, use it. =head1 AUTHOR Curtis "Ovid" Poe, Eeop_divo_sitruc@yahoo.comE Reverse the name to email me. =head1 COPYRIGHT AND LICENSE Copyright 2004 by Curtis "Ovid" Poe This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Data-Dumper-Simple-0.11/Makefile.PL0000644000076500007650000000054010336505016021023 0ustar curtispoecurtispoe00000000000000# Note: this file was auto-generated by Module::Build::Compat version 0.03 use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'Data::Dumper::Simple', 'VERSION_FROM' => 'lib/Data/Dumper/Simple.pm', 'PREREQ_PM' => { 'Filter::Simple' => '0.77', 'Test::More' => '0' }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [], 'PL_FILES' => {} ) ; Data-Dumper-Simple-0.11/MANIFEST0000644000076500007650000000033410336505016020203 0ustar curtispoecurtispoe00000000000000Build.PL Changes lib/Data/Dumper/Simple.pm Makefile.PL MANIFEST This list of files META.yml Module meta-data (added by MakeMaker) README t/10dump.t t/20import.t t/30autowarn.t t/40noparens.t t/pod-coverage.t t/pod.t Data-Dumper-Simple-0.11/META.yml0000644000076500007650000000072310336505016020325 0ustar curtispoecurtispoe00000000000000--- name: Data-Dumper-Simple version: 0.11 author: - Curtis "Ovid" Poe abstract: Easily dump variables with names license: perl resources: license: http://dev.perl.org/licenses/ requires: Filter::Simple: 0.77 Test::More: 0 provides: Data::Dumper::Simple: file: lib/Data/Dumper/Simple.pm version: 0.11 generated_by: Module::Build version 0.2703 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 Data-Dumper-Simple-0.11/README0000644000076500007650000000066610336505016017742 0ustar curtispoecurtispoe00000000000000Data::Dumper::Simple version 0.10 ===================== INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: Filter::Simple 0.77 COPYRIGHT AND LICENCE Copyright (C) 2004 Curtis "Ovid" Poe This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Data-Dumper-Simple-0.11/t/0000755000076500007650000000000010336505016017315 5ustar curtispoecurtispoe00000000000000Data-Dumper-Simple-0.11/t/10dump.t0000755000076500007650000001034510336505016020616 0ustar curtispoecurtispoe00000000000000#!/usr/bin/perl # '$Id: 10dump.t,v 1.6 2004/08/03 04:52:28 ovid Exp $'; use warnings; use strict; use Test::More tests => 24; my $CLASS; BEGIN { chdir 't' if -d 't'; unshift @INC => '../lib'; $CLASS = 'Data::Dumper::Simple'; use_ok($CLASS) or die; } my $scalar = 'Ovid'; my @array = qw/Data Dumper Simple Rocks!/; my %hash = ( at => 'least', I => 'hope', it => 'does', ); is(Dumper($scalar), "\$scalar = 'Ovid';\n", '... and dumped variables are named'); is(Dumper(\$scalar), "\$scalar = 'Ovid';\n", '... and dumping a scalar as a reference is a no-op'); my $expected = Data::Dumper->Dump([\@array], ['*array']); is(Dumper(@array), $expected, '... and arrays should not flatten'); $expected = Data::Dumper->Dump([\@array], ['$array']); is(Dumper(\@array), $expected, '... but they DWIM if I take a take a reference to them'); $expected = Data::Dumper->Dump( [$scalar, \@array, \%hash], [qw/$scalar *array *hash/] ); is(Dumper($scalar, @array, %hash), $expected, '... or have a list of them'); $expected = Data::Dumper->Dump( [$scalar, \@array, \%hash], [qw/$scalar $array $hash/] ); is(Dumper($scalar, \@array, \%hash), $expected, '... or a list of references'); $expected = Data::Dumper->Dump( [$scalar, \@array, \%hash], [qw/$scalar *array *hash/] ); is( Dumper( $scalar => @array => %hash ), $expected, '... or fat commas "=>"'); is( Dumper( $scalar => @array => %hash ), $expected, '... regardless of whitespace'); is( Dumper( $scalar, @array, %hash ), $expected, '... and even do the right thing if there are newlines in the arg list'); $Data::Dumper::Indent = 1; $expected = Data::Dumper->Dump( [$scalar, \@array, \%hash], [qw/$scalar *array *hash/] ); is(Dumper($scalar, @array, %hash), $expected, '... and $Data::Dumper::Indent is respected'); my $foo = { hash => 'ref' }; my @foo = qw/foo bar baz/; $expected = Data::Dumper->Dump( [$foo, \@foo], [qw/$foo $foo/], ); is(Dumper($foo, \@foo), $expected, '... and a reference to a simarly named variable won\'t confuse things'); is(Dumper(\$foo, \@foo), $expected, '... even if we take references to both of them.'); is(Dumper($array[2]), "\$array[2] = 'Simple';\n", "Indexed items in arrays are dumped intuitively."); my $aref = \@array; is(Dumper($aref->[2]), "\$aref->[2] = 'Simple';\n", "... even if they're references"); is(Dumper($hash{at}), "\$hash{at} = 'least';\n", "Indexed items in hashes are dumped intuitively"); my $href = \%hash; is(Dumper($href->{at}), "\$href->{at} = 'least';\n", "... even if they're references"); my @array2 = ( [qw/foo bar baz/], [qw/one two three/], ); $expected = Data::Dumper->Dump( [$array2[1][2]], [qw/$array2[1][2]/] ); is(Dumper($array2[1][2]), $expected, 'Multi-dimensioanl arrays should be handled correctly'); my ($w, $x) = (1,2); $expected = Data::Dumper->Dump( [$array2[$w][$x]], [qw/$array2[$w][$x]/] ); is(Dumper($array2[$w][$x]), $expected, '... even if the indexes are also variables'); my %hash2 = ( first => { this => 'that' }, second => { next => 1 }, ); $expected = Data::Dumper->Dump( [$hash2{second}{next}], [qw/*hash2{second}{next}/] ); is( Dumper($hash2{second}{next}), $expected, 'Multi-level hashes should be handled correctly'); my ($y, $z) = qw/second next/; $expected = Data::Dumper->Dump( [$hash2{$y}{$z}], [qw/*hash2{$y}{$z}/] ); is( Dumper($hash2{$y}{$z}), $expected, '... even if the indexes are variables'); eval " # Dumper($foo); "; ok(! $@, 'Commenting out a dumper item should not throw an exception'); $foo = [4, 17]; $expected = Data::Dumper->Dump([$foo->[ 1 ]],[qw/$foo->[1]/]); is(Dumper($foo->[ 1 ]), $expected, 'Extra whitespace in the variable should not break things'); my @a = ({foo => 'bar'}); # this might break in the future. For now, it *has* to work because any # variable that begins with a dollar sigil will automatically be treated # as a scalar. If, in the future, we incorporate slices, this might break. $expected = Data::Dumper->Dump([$a[0]],['$a[0]']); is(Dumper($a[0]), $expected, 'Indexing into a variable will force a reference'); Data-Dumper-Simple-0.11/t/20import.t0000644000076500007650000000124210336505016021155 0ustar curtispoecurtispoe00000000000000#!/usr/bin/perl # '$Id: 20import.t,v 1.1 2004/08/03 04:48:39 ovid Exp $'; use warnings; use strict; use Test::More tests => 2; # never forget CC my $CLASS; BEGIN { chdir 't' if -d 't'; unshift @INC => '../lib'; $CLASS = 'Data::Dumper::Simple'; use_ok($CLASS, as => 'frobnitz') or die; } my $scalar = 'Ovid'; my @array = qw/Data Dumper Simple Rocks!/; my %hash = ( at => 'least', I => 'hope', it => 'does', ); my $expected = Data::Dumper->Dump( [$scalar, \@array, \%hash], [qw/$scalar *array *hash/] ); is(frobnitz($scalar, @array, %hash), $expected, 'Using a different subroutine name for "Dumper" should work as expected'); Data-Dumper-Simple-0.11/t/30autowarn.t0000644000076500007650000000161710336505016021512 0ustar curtispoecurtispoe00000000000000#!/usr/bin/perl # '$Id: 30autowarn.t,v 1.1 2004/08/03 04:48:52 ovid Exp $'; use warnings; use strict; use Test::More tests => 3; my $warning; $SIG{__WARN__} = sub { $warning = join '' => @_ }; my $carp; sub carp { $carp = join '' => @_ }; my $CLASS; BEGIN { chdir 't' if -d 't'; unshift @INC => '../lib'; $CLASS = 'Data::Dumper::Simple'; use_ok($CLASS, autowarn => 1) or die; } my $scalar = 'Ovid'; my @array = qw/Data Dumper Simple Rocks!/; my %hash = ( at => 'least', I => 'hope', it => 'does', ); my $expected = Data::Dumper->Dump( [$scalar, \@array, \%hash], [qw/$scalar *array *hash/] ); Dumper($scalar, @array, %hash); is($warning, $expected, 'Dumper should be able to autowarn'); no Data::Dumper::Simple; use Data::Dumper::Simple autowarn => 'carp'; Dumper($scalar, @array, %hash); is($carp, $expected, '... even if we use a different function name'); Data-Dumper-Simple-0.11/t/40noparens.t0000644000076500007650000000222410336505016021473 0ustar curtispoecurtispoe00000000000000#!/usr/bin/perl # '$Id: 40noparens.t,v 1.1 2005/05/20 01:36:47 ovid Exp $'; use warnings; use strict; use Test::More tests => 6; my $CLASS; BEGIN { chdir 't' if -d 't'; unshift @INC => '../lib'; $CLASS = 'Data::Dumper::Simple'; use_ok($CLASS) or die; } my $scalar = 'Ovid'; my @array = qw/Data Dumper Simple Rocks!/; my %hash = ( at => 'least', I => 'hope', it => 'does', ); my $expected = Data::Dumper->Dump( [$scalar, \@array, \%hash], [qw/$scalar *array *hash/] ); my $got = Dumper $scalar, @array, %hash; is($got, $expected, 'Having no parens is allowed'); $got = Dumper $scalar, @array, %hash; is($got, $expected, '... even split among several lines'); $got = Dumper $scalar => @array => %hash ; is($got, $expected, '... or using big arrows, or whitespace before the semicolon'); { $got = Dumper $scalar, @array, %hash } is($got, $expected, '... or at the end of a block (no semicolon)'); $got = Dumper $hash{I}, $array[3]; $expected = Data::Dumper->Dump( [$hash{I}, $array[3]], [qw/$hash{I} $array[3]/] ); is($got, $expected, '... or with aggregate elements'); Data-Dumper-Simple-0.11/t/pod-coverage.t0000644000076500007650000000065010336505016022056 0ustar curtispoecurtispoe00000000000000#!perl -T use strict; use Test::More; eval "use Test::Pod::Coverage 0.08"; plan skip_all => "Test::Pod::Coverage required for testing POD coverage" if $@; my %exception_for = (); my @modules = Test::Pod::Coverage::all_modules(); plan tests => scalar @modules; foreach my $module (@modules) { my $exception = $exception_for{$module}; pod_coverage_ok( $module, $exception ? { trustme => [$exception] } : () ); } Data-Dumper-Simple-0.11/t/pod.t0000644000076500007650000000021510336505016020262 0ustar curtispoecurtispoe00000000000000#!perl -T use Test::More; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@; all_pod_files_ok();