← Index
Performance Profile   « block view • line view • sub view »
For /wise/base/deliv/dev/bin/getfix
  Run on Thu May 20 15:30:03 2010
Reported on Thu May 20 16:25:21 2010

File/wise/base/deliv/dev/lib/perl/WISE/Dumper.pm
Statements Executed18
Total Time0.00109 seconds

Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
00000WISE::Dumper::BEGIN
00000WISE::Dumper::_print_ary
00000WISE::Dumper::_print_datum
00000WISE::Dumper::_print_hash
00000WISE::Dumper::add
00000WISE::Dumper::new
00000WISE::Dumper::print_tree

LineStmts.Exclusive
Time
Avg.Code
1package WISE::Dumper;
2
333.2e-51.1e-5use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION);
# spent 73µs making 1 call to vars::import
4
532.7e-59.0e-6use Exporter;
# spent 34µs making 1 call to Exporter::import
632.9e-59.7e-6use Carp;
# spent 51µs making 1 call to Exporter::import
7
830.000980.00033use Data::Dumper;
# spent 37µs making 1 call to Exporter::import
9
1011.0e-61.0e-6$VERSION = 1.00;
11
1219.0e-69.0e-6@ISA = qw(Data::Dumper);
1311.0e-61.0e-6@EXPORT = qw(Dumper print_tree);
1411.0e-61.0e-6@EXPORT_OK = qw();
15
16100$Data::Dumper::Sortkeys = 1;
17
18# Override the creator to allow option passing
19sub new {
20 my $class = shift;
21 my $vars = shift;
22 my $what = shift;
23 my @allowed = qw/purity pad terse indent useqq freezer toaster deepcopy
24 quotekeys bless maxdepth varname/;
25 my ($new,$names,$opts,@got,@args);
26 if( ref($what) eq "ARRAY") { $names = $what; $opts = shift||{}; }
27 elsif(ref($what) eq "HASH") { $opts = $what; }
28 else { $opts = {}; }
29 $vars = [$vars] if ref($vars) !~ /array/i;
30 @args = ($vars);
31 push @args,$names if defined $names;
32 #print "@args\n";
33 $new = $class->SUPER::new(@args) or return;
34 @got = grep defined $opts->{$_}, @allowed;
35 @{$new}{@got} = @{$opts}{@got};
36 $new->{opts} = { %$opts };
37 if (! $new->{indent}) {
38 $new->{xpad} = "";
39 $new->{sep} = "";
40 }
41 return bless $new,$class;
42}
43
44# An add method
45sub add {
46 my ($s,$v) = @_;
47 if (ref($v) eq 'ARRAY') {
48 $s->{todump} = [@{$s->{todump}||[]},@$v];
49 return $s;
50 }
51 else {
52 return @{$s->{todump}};
53 }
54}
55
56# Print a compact data tree structure
57
58sub print_tree {
59 if( ref($_[0]) =~ /hash/i) { &_print_hash; }
60 elsif(ref($_[0]) =~ /array/i) { &_print_ary; }
61 else { &_print_datum; }
62 return;
63}
64
65sub _print_hash {
66 my $r = shift;
67 my $full = shift;
68 my $keysort= shift;
69 my $indent = shift || '';
70 my $level = shift || 0;
71 my @keys = keys %$r;
72 if( ref($keysort) =~ /array/i && @$keysort) {
73 my %there;
74 my @yes = grep {exists $r->{$_}} @$keysort;
75 @there{@yes} = (1) x @yes;
76 my @no = grep {! $there{$_}} @keys;
77 @keys = (@yes, @no);
78 } elsif(ref($keysort) =~ /hash/i && keys %$keysort) {
79 @keys = sort {$keysort->{$a} <=> $keysort->{$b}} @keys;
80 } elsif($keysort) {
81 @keys = sort @keys;
82 }
83 for my $k (@keys) {
84 my $last = $k eq $keys[-1];
85 print +($level?"$indent".($last?"`":"|"):"")."- $k ";
86 _print_datum($r->{$k},$full,$keysort,$indent,$last,$level+1);
87 }
88 return;
89}
90
91sub _print_ary {
92 my $r = shift;
93 my $full = shift;
94 my $keysort= shift;
95 my $indent = shift || '';
96 my $level = shift || 0;
97 for my $k (0..$#{$r}) {
98 my $last = $k == $#{$r};
99 print +($level?"$indent".($last?"`":"|"):"")."- $k ";
100 _print_datum($r->[$k],$full,$keysort,$indent,$last,$level+1);
101 }
102 return;
103}
104
105sub _print_datum {
106 my $r = shift;
107 my $full = shift;
108 my $keysort= shift;
109 my $indent = shift || '';
110 my $last = shift || 0;
111 my $level = shift || 0;
112 my $continue = $last ? " " : "|";
113 my $intro = "$indent".$continue." \\_";
114 $expand = $full && $level <= $full ? 1 : 0;
115 if(ref($r) =~ /hash/i) {
116 print("(empty)\n"),return if keys(%$r) == 0;
117 print "\n"; #print "\n$intro\n";
118 _print_hash($r,$full,$keysort,$indent.$continue.' ',$level+1);
119 } elsif(ref($r) =~ /array/i) {
120 if(! $expand) {
121 while(ref($r) =~ /array/i) { print "[".@$r."]"; $r = $r->[0]; }
122 print " ";
123 _print_datum($r,$full,$keysort,$indent,$last,$level+1);
124 } else {
125 print "[".@$r."]";
126 print("\n"),return if @$r == 0;
127 print "\n"; #print "\n$intro\n";
128 _print_ary($r,$full,$keysort,$indent.$continue.' ',$level+1);
129 }
130 } else {
131 $r = '(undefined)' if ! defined $r;
132 (my $txt = substr("$r",0,64)) =~ s/\n+/ /g;
133 print "=> '$txt'\n";
134 }
135 return;
136}
137
13817.0e-67.0e-61;