[Orca-checkins] r310 - trunk/orca/lib/Orca

Blair Zajac blair at orcaware.com
Sun May 2 22:05:06 PDT 2004


Author: blair
Date: Sun May  2 22:03:27 2004
New Revision: 310

Modified:
   trunk/orca/lib/Orca/SourceFile.pm
Log:
Move duplicated code that makes a deep copy of a plot into a utility function.

* lib/Orca/SourceFile.pm
  (get_date_column):
    Fix indentation.
  (deep_clone_plot):
    New function to make a deep clone of a plot.
  (add_plots):
    Call deep_clone_plot() instead of cloning the plot.


Modified: trunk/orca/lib/Orca/SourceFile.pm
==============================================================================
--- trunk/orca/lib/Orca/SourceFile.pm	(original)
+++ trunk/orca/lib/Orca/SourceFile.pm	Sun May  2 22:03:27 2004
@@ -245,8 +245,9 @@
   }
 
   unless ($found > -1) {
-    warn "$0: warning: cannot find date '$date_column_name' in '$sfile_fids[$fid]'.\n";
-warn "@{$self->[I_COLUMN_DESCRIPTION]}\n";
+    warn "$0: warning: cannot find date '$date_column_name' in ",
+         "'$sfile_fids[$fid]'.\n";
+    warn "@{$self->[I_COLUMN_DESCRIPTION]}\n";
     return;
   }
   $self->[I_DATE_COLUMN_INDEX] = $found;
@@ -254,6 +255,23 @@
   $self;
 }
 
+# XXX
+# Utility function make a deep clone one of the plots in the
+# config_plots array, except for the 'creates' hash key.  This should
+# really be a method for a single plot, but the plot is not an object
+# right now, so it doesn't have any methods that can be given to it.
+sub deep_clone_plot {
+  # Be careful not to make a deep copy of the 'creates' reference,
+  # since it can cause recursion.
+  my $plot             = shift;
+  my $creates          = delete $plot->{creates};
+  my $new_plot         = dclone($plot);
+  $plot->{creates}     = $creates;
+  $new_plot->{creates} = $creates;
+
+  $new_plot;
+}
+
 sub add_plots {
   # Make sure that the user has called the add_groups method and
   # inserted at least one key.
@@ -370,15 +388,10 @@
       }
       $regexp_pos[$i] = @column_description;
 
-      # Start by making a deep copy of the plot.  Be careful not to make
-      # a deep copy of the 'creates' reference, since it can cause
-      # recursion.  Replace the regular expression in the first data
-      # with the name of the column that caused the match.
-      my $creates          = delete $plot->{creates};
-      my $new_plot         = dclone($plot);
-      $plot->{creates}     = $creates;
-      $new_plot->{creates} = $creates;
-      $plot                = $new_plot;
+      # Start by making a deep copy of the plot.  Replace the regular
+      # expression in the first data with the name of the column that
+      # caused the match.
+      $plot = deep_clone_plot($plot);
 
       # At this point we have a copy of plot.  Now go through looking
       # for all the columns that match and create an additional data
@@ -487,20 +500,14 @@
       }
       ++$regexp_pos[$i];
 
-      # Start by making a deep copy of the plot.  Be careful not to make
-      # a deep copy of the 'creates' reference, since it can cause
-      # recursion.  Replace the regular expression in the first data
-      # with the name of the column that caused the match.  Then create
-      # string form of the plot object using Data::Dumper::Dumper and
-      # replace all of the $1, $2, ... with what was matched in the
-      # first data source.
-      my $creates          = delete $plot->{creates};
-      my $new_plot         = dclone($plot);
-      $plot->{creates}     = $creates;
-      $plot                = $new_plot;
+      # Start by making a deep copy of the plot.  Replace the regular
+      # expression in the first data with the name of the column that
+      # caused the match.  Then create string form of the plot object
+      # using Data::Dumper::Dumper and replace all of the $1, $2,
+      # ... with what was matched in the first data source.
+      $plot                = deep_clone_plot($plot);
       $plot->{data}[0][$regexp_element_index] = $column_description;
       my $d                = Data::Dumper->Dump([$plot], [qw(plot)]);
-      $plot->{creates}     = $creates;
       my $count            = 1;
       foreach my $match (@matches) {
         $d =~ s/\$$count/$match/mge;



More information about the Orca-checkins mailing list