Author: timbo
Date: Thu May 24 08:43:19 2007
New Revision: 9607

Modified:
   dbi/trunk/lib/DBI/ProfileDumper.pm

Log:
Add trace mechanism to DBI/ProfileDumper


Modified: dbi/trunk/lib/DBI/ProfileDumper.pm
==============================================================================
--- dbi/trunk/lib/DBI/ProfileDumper.pm  (original)
+++ dbi/trunk/lib/DBI/ProfileDumper.pm  Thu May 24 08:43:19 2007
@@ -216,8 +216,10 @@
     my $data = $self->{Data};
 
     if (1) { # make an option
-        return undef if not $data;
-        return undef if ref $data eq 'HASH' && !%$data;
+        if (not $data or ref $data eq 'HASH' && !%$data) {
+            DBI->trace_msg("flush_to_disk skipped for empty profile\n",0) if 
$self->{Trace};
+            return undef;
+        }
     }
 
     my $fh = gensym;
@@ -236,17 +238,20 @@
     # write header if file is empty - typically because we just opened it
     # in '>' mode, or perhaps we used '>>' but the file had been truncated 
externally.
     if (-s $fh == 0) {
+        DBI->trace_msg("flush_to_disk wrote header to $filename\n",0) if 
$self->{Trace};
         $self->write_header($fh);
         $self->{_wrote_header} = $filename;
     }
 
-    $self->write_data($fh, $self->{Data}, 1);
+    my $lines = $self->write_data($fh, $self->{Data}, 1);
+    DBI->trace_msg("flush_to_disk wrote $lines lines to $filename\n",0) if 
$self->{Trace};
 
     close($fh)  # unlocks the file
         or croak("Error closing '$filename': $!");
 
     $self->empty();
 
+
     return $filename;
 }
 
@@ -294,23 +299,26 @@
 
     # XXX it's valid for $data to be an ARRAY ref, i.e., Path is empty.
     # produce an empty profile for invalid $data
-    return unless $data and UNIVERSAL::isa($data,'HASH');
+    return 0 unless $data and UNIVERSAL::isa($data,'HASH');
     
     # isolate us against globals which affect print
     local ($\, $,);
 
+    my $lines = 0;
     while (my ($key, $value) = each(%$data)) {
         # output a key
         print $fh "+ $level ". escape_key($key). "\n";
         if (UNIVERSAL::isa($value,'ARRAY')) {
             # output a data set for a leaf node
             print $fh "= ".join(' ', @$value)."\n";
+            $lines += 1;
         } else {
             # recurse through keys - this could be rewritten to use a
             # stack for some small performance gain
-            $self->write_data($fh, $value, $level + 1);
+            $lines += $self->write_data($fh, $value, $level + 1);
         }
     }
+    return $lines;
 }
 
 

Reply via email to