develooper Front page | perl.perl5.porters | Postings from January 2001

[PATCH] Data::Dumper is no longer a "DUMMY"

Thread Next
From:
Casey R. Tweten
Date:
January 10, 2001 08:08
Subject:
[PATCH] Data::Dumper is no longer a "DUMMY"
Message ID:
Pine.OSF.4.21.0101101105001.3671-100000@home.kiski.net

At least it's true for the Perl version of the Dumper.  I am not the
best XS hacker so I am hoping someone will pick this up and write the
XS version.

I use B::Deparse to print the coderefs.

*** ext/Data/Dumper/Dumper.pm.orig	Tue Jan  9 15:52:17 2001
--- ext/Data/Dumper/Dumper.pm	Wed Jan 10 11:03:50 2001
***************
*** 9,15 ****
  
  package Data::Dumper;
  
! $VERSION = '2.102';
  
  #$| = 1;
  
--- 9,15 ----
  
  package Data::Dumper;
  
! $VERSION = '2.103';
  
  #$| = 1;
  
***************
*** 349,356 ****
        $out .= ($name =~ /^\%/) ? ')' : '}';
      }
      elsif ($realtype eq 'CODE') {
!       $out .= 'sub { "DUMMY" }';
!       carp "Encountered CODE ref, using dummy placeholder" if $s->{purity};
      }
      else {
        croak "Can\'t handle $realtype type.";
--- 349,359 ----
        $out .= ($name =~ /^\%/) ? ')' : '}';
      }
      elsif ($realtype eq 'CODE') {
!        require B::Deparse;
!        my $sub  =  'sub ' . (B::Deparse->new)->coderef2text($val);
!        $pad     =  $s->{sep} . $s->{pad} . $s->{xpad} . $s->{apad} . '    ';
!        $sub     =~ s/\n/$pad/gse;
!        $out    .=  $sub;
      }
      else {
        croak "Can\'t handle $realtype type.";
***************
*** 1013,1029 ****
  C<Data::Dumper> cheats with CODE references.  If a code reference is
  encountered in the structure being processed, an anonymous subroutine that
  contains the string '"DUMMY"' will be inserted in its place, and a warning
! will be printed if C<Purity> is set.  You can C<eval> the result, but bear
! in mind that the anonymous sub that gets created is just a placeholder.
! Someday, perl will have a switch to cache-on-demand the string
! representation of a compiled piece of code, I hope.  If you have prior
! knowledge of all the code refs that your data structures are likely
! to have, you can use the C<Seen> method to pre-seed the internal reference
! table and make the dumped output point to them, instead.  See L<EXAMPLES>
! above.
  
  The C<Useqq> flag makes Dump() run slower, since the XSUB implementation
! does not support it.
  
  SCALAR objects have the weirdest looking C<bless> workaround.
  
--- 1016,1033 ----
  C<Data::Dumper> cheats with CODE references.  If a code reference is
  encountered in the structure being processed, an anonymous subroutine that
  contains the string '"DUMMY"' will be inserted in its place, and a warning
! will be printed if C<Purity> is set.  B<Note:>  This has been fixed in the
! Perl version of the Dumper.  You can C<eval> the result, but bear in mind
! that the anonymous sub that gets created is just a placeholder.  Someday,
! perl will have a switch to cache-on-demand the string representation of a
! compiled piece of code, I hope.  If you have prior knowledge of all the code
! refs that your data structures are likely to have, you can use the C<Seen>
! method to pre-seed the internal reference table and make the dumped output
! point to them, instead.  See L<EXAMPLES> above.
  
  The C<Useqq> flag makes Dump() run slower, since the XSUB implementation
! does not support it.  It is also the only current way to get your subroutine
! references to display actual code.
  
  SCALAR objects have the weirdest looking C<bless> workaround.
  
***************
*** 1036,1041 ****
--- 1040,1047 ----
  This program is free software; you can redistribute it and/or
  modify it under the same terms as Perl itself.
  
+ Perl version of subroutine references done by Casey Tweten,
+ <F<crt@kiski.net>>.
  
  =head1 VERSION
  

-- 

print(join(' ', qw(Casey R. Tweten)));my $sig={mail=>'crt@kiski.net',site=>
'http://home.kiski.net/~crt'};print "\n",'.'x(length($sig->{site})+6),"\n";
print map{$_.': '.$sig->{$_}."\n"}sort{$sig->{$a}cmp$sig->{$b}}keys%{$sig};
my $VERSION = '0.01'; #'patched' by Jerrad Pierce <belg4mit at MIT dot EDU>


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About