package SQL::Translator::Parser::xSV;
-# -------------------------------------------------------------------
-# $Id: xSV.pm 1440 2009-01-17 16:31:57Z jawnsy $
-# -------------------------------------------------------------------
-# 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
-# published by the Free Software Foundation; version 2.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-# 02111-1307 USA
-# -------------------------------------------------------------------
-
=head1 NAME
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:
=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
+Field names will automatically be normalized by
C<SQL::Translator::Utils::normalize_name>.
=cut
-# -------------------------------------------------------------------
-
use strict;
-use vars qw(@EXPORT);
+use warnings;
+our @EXPORT;
+our $VERSION = '1.59';
use Exporter;
use Text::ParseWords qw(quotewords);
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;
#
# If directed, look at every field's values to guess size and type.
#
- unless (
+ unless (
defined $args->{'scan_fields'} &&
$args->{'scan_fields'} == 0
) {
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 ) =
+ my ( $w, $d ) =
map { s/,//g; length $_ || 1 } split( /\./, $data );
$size = [ $w + $d, $d ];
}
for my $field ( keys %field_info ) {
my $size = $field_info{ $field }{'size'} || [ 1 ];
- my $data_type =
- $field_info{ $field }{'char'} ? 'char' :
+ my $data_type =
+ $field_info{ $field }{'char'} ? 'char' :
$field_info{ $field }{'float'} ? 'float' :
$field_info{ $field }{'integer'} ? 'integer' : 'char';
1;
-# -------------------------------------------------------------------
=pod
=head1 AUTHORS