added credit for dave cash
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator.pm
index c063957..de3d65c 100644 (file)
@@ -1,7 +1,7 @@
 package SQL::Translator;
 
 # ----------------------------------------------------------------------
-# $Id: Translator.pm,v 1.44 2003-08-22 22:26:41 kycl4rk Exp $
+# $Id: Translator.pm,v 1.50 2004-02-02 20:30:35 allenday Exp $
 # ----------------------------------------------------------------------
 # Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
 #                    darren chamberlain <darren@cpan.org>,
@@ -28,8 +28,8 @@ use base 'Class::Base';
 
 require 5.004;
 
-$VERSION  = '0.03';
-$REVISION = sprintf "%d.%02d", q$Revision: 1.44 $ =~ /(\d+)\.(\d+)/;
+$VERSION  = '0.04';
+$REVISION = sprintf "%d.%02d", q$Revision: 1.50 $ =~ /(\d+)\.(\d+)/;
 $DEBUG    = 0 unless defined $DEBUG;
 $ERROR    = "";
 
@@ -75,13 +75,13 @@ sub init {
     $self->parser  ($config->{'parser'}   || $config->{'from'} || $DEFAULT_SUB);
     $self->producer($config->{'producer'} || $config->{'to'}   || $DEFAULT_SUB);
 
-       #
-       # Set up callbacks for formatting of pk,fk,table,package names in producer
-       #
-       $self->format_table_name($config->{'format_table_name'});
-       $self->format_package_name($config->{'format_package_name'});
-       $self->format_fk_name($config->{'format_fk_name'});
-       $self->format_pk_name($config->{'format_pk_name'});
+        #
+        # Set up callbacks for formatting of pk,fk,table,package names in producer
+        #
+        $self->format_table_name($config->{'format_table_name'});
+        $self->format_package_name($config->{'format_package_name'});
+        $self->format_fk_name($config->{'format_fk_name'});
+        $self->format_pk_name($config->{'format_pk_name'});
 
     #
     # Set the parser_args and producer_args
@@ -334,9 +334,9 @@ sub filename {
         if (-d $filename) {
             my $msg = "Cannot use directory '$filename' as input source";
             return $self->error($msg);
-       } elsif (ref($filename) eq 'ARRAY') {
-           $self->{'filename'} = $filename;
-           $self->debug("Got array of files: ".join(', ',@$filename)."\n");
+        } elsif (ref($filename) eq 'ARRAY') {
+            $self->{'filename'} = $filename;
+            $self->debug("Got array of files: ".join(', ',@$filename)."\n");
         } elsif (-f _ && -r _) {
             $self->{'filename'} = $filename;
             $self->debug("Got filename: '$self->{'filename'}'\n");
@@ -389,21 +389,21 @@ sub data {
         local $/;
         my $data;
 
-       my @files = ref($filename) eq 'ARRAY' ? @$filename : ($filename);
+        my @files = ref($filename) eq 'ARRAY' ? @$filename : ($filename);
 
-       foreach my $file (@files) {
-               unless (open FH, $file) {
-                   return $self->error("Can't read file '$file': $!");
-               }
+        foreach my $file (@files) {
+                unless (open FH, $file) {
+                    return $self->error("Can't read file '$file': $!");
+                }
 
-               $data .= <FH>;
+                $data .= <FH>;
 
-               unless (close FH) {
-                   return $self->error("Can't close file '$file': $!");
-               }
-       }
+                unless (close FH) {
+                    return $self->error("Can't close file '$file': $!");
+                }
+        }
 
-       $self->{'data'} = \$data;
+        $self->{'data'} = \$data;
     }
 
     return $self->{'data'};
@@ -528,9 +528,6 @@ sub translate {
     # Get the data.
     # ----------------------------------------------------------------
     my $data = $self->data;
-    unless (ref($data) eq 'SCALAR' and length $$data) {
-        return $self->error("Empty data file!");
-    }
 
     # ----------------------------------------------------------------
     # Local reference to the parser subroutine
@@ -575,8 +572,8 @@ sub translate {
 
     eval { $producer_output = $producer->($self) };
     if ($@ || ! $producer_output) {
-        my $msg = sprintf "translate: Error with producer '%s': %s",
-            $producer_type, ($@) ? $@ : " no results";
+        my $err = $@ || $self->error || "no results";
+        my $msg = "translate: Error with producer '$producer_type': $err";
         return $self->error($msg);
     }
 
@@ -686,7 +683,7 @@ sub _list {
                 my $mod      =  $_;
                    $mod      =~ s/\.pm$//;
                 my $cur_dir  = $File::Find::dir;
-                my $base_dir = catfile 'SQL', 'Translator', $uctype;
+                my $base_dir = quotemeta catfile 'SQL', 'Translator', $uctype;
 
                 #
                 # See if the current directory is below the base directory.
@@ -1114,6 +1111,8 @@ The following people have contributed to the SQLFairy project:
 
 =item * Sam Angiuoli <angiuoli@users.sourceforge.net>
 
+=item * Dave Cash <dave@gnofn.org>
+
 =item * Darren Chamberlain <dlc@users.sourceforge.net>
 
 =item * Ken Y. Clark <kclark@cpan.org>