take out duplicate docs
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / xSV.pm
index fad98a9..d155fc1 100644 (file)
@@ -1,10 +1,7 @@
 package SQL::Translator::Parser::xSV;
 
 # -------------------------------------------------------------------
-# $Id: xSV.pm,v 1.10 2003-06-11 03:59:49 kycl4rk Exp $
-# -------------------------------------------------------------------
-# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
-#                    darren chamberlain <darren@cpan.org>
+# Copyright (C) 2002-2009 SQLFairy Authors
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -37,11 +34,13 @@ SQL::Translator::Parser::xSV - parser for arbitrarily delimited text files
 
 =head1 DESCRIPTION
 
-Parses arbitrarily delimited text files.  See the 
+Parses arbitrarily delimited text files.  See the
 Text::RecordParser manpage for arguments on how to parse the file
 (e.g., C<field_separator>, C<record_separator>).  Other arguments
 include:
 
+=head1 OPTIONS
+
 =over
 
 =item * scan_fields
@@ -51,22 +50,20 @@ and field sizes.  True by default.
 
 =item * trim_fields
 
-A shortcut to sending filters to Text::RecordParser, will create 
+A shortcut to sending filters to Text::RecordParser, will create
 callbacks that trim leading and trailing spaces from fields and headers.
 True by default.
 
 =back
 
-Field names will automatically be normalized by 
-C<SQL::Translator::Utils::normalize>.
+Field names will automatically be normalized by
+C<SQL::Translator::Utils::normalize_name>.
 
 =cut
 
-# -------------------------------------------------------------------
-
 use strict;
 use vars qw($VERSION @EXPORT);
-$VERSION = sprintf "%d.%02d", q$Revision: 1.10 $ =~ /(\d+)\.(\d+)/;
+$VERSION = '1.59';
 
 use Exporter;
 use Text::ParseWords qw(quotewords);
@@ -89,7 +86,7 @@ sub parse {
         header_filter    => \&normalize_name,
     );
 
-    $parser->field_filter( sub { $_ = shift; s/^\s+|\s+$//g; $_ } ) 
+    $parser->field_filter( sub { $_ = shift || ''; s/^\s+|\s+$//g; $_ } )
         unless defined $args->{'trim_fields'} && $args->{'trim_fields'} == 0;
 
     my $schema = $tr->schema;
@@ -120,7 +117,7 @@ sub parse {
     #
     # If directed, look at every field's values to guess size and type.
     #
-    unless ( 
+    unless (
         defined $args->{'scan_fields'} &&
         $args->{'scan_fields'} == 0
     ) {
@@ -134,16 +131,17 @@ sub parse {
                 if ( $data =~ /^-?\d+$/ ) {
                     $type = 'integer';
                 }
-                elsif ( 
-                    $data =~ /^-?[,\d]+\.[\d+]?$/ 
+                elsif (
+                    $data =~ /^-?[,\d]+\.[\d+]?$/
                     ||
-                    $data =~ /^-?[,\d]+?\.\d+$/  
+                    $data =~ /^-?[,\d]+?\.\d+$/
                     ||
-                    $data =~ /^-?\.\d+$/  
+                    $data =~ /^-?\.\d+$/
                 ) {
                     $type = 'float';
-                    my ( $w, $d ) = map { s/,//g; $_ } split( /\./, $data );
-                    $size = [ length $w, length $d ];
+                    my ( $w, $d ) =
+                        map { s/,//g; length $_ || 1 } split( /\./, $data );
+                    $size = [ $w + $d, $d ];
                 }
                 else {
                     $type = 'char';
@@ -162,10 +160,15 @@ sub parse {
         }
 
         for my $field ( keys %field_info ) {
-            my $size      = $field_info{ $field }{'size'};
-            my $data_type = 
-                $field_info{ $field }{'char'}  ? 'char'  : 
-                $field_info{ $field }{'float'} ? 'float' : 'integer';
+            my $size      = $field_info{ $field }{'size'} || [ 1 ];
+            my $data_type =
+                $field_info{ $field }{'char'}    ? 'char'  :
+                $field_info{ $field }{'float'}   ? 'float' :
+                $field_info{ $field }{'integer'} ? 'integer' : 'char';
+
+            if ( $data_type eq 'char' && scalar @$size == 2 ) {
+                $size = [ $size->[0] + $size->[1] ];
+            }
 
             my $field = $table->get_field( $field );
             $field->size( $size );
@@ -178,16 +181,15 @@ sub parse {
 
 1;
 
-# -------------------------------------------------------------------
 =pod
 
-=head1 AUTHOR
+=head1 AUTHORS
 
 Darren Chamberlain E<lt>darren@cpan.orgE<gt>,
 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
 
 =head1 SEE ALSO
 
-Text::RecordParser.
+Text::RecordParser, SQL::Translator.
 
 =cut