X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FxSV.pm;h=e2439454cddde2317055c2c2493666997fbe6554;hb=df399712c8e458cbd2bf0389cb17666ce499dedd;hp=d270d6273fd9a3645d877d521e1ad99eb87fef70;hpb=900758666f4b53e9a670d84260d28b16f834f69d;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Parser/xSV.pm b/lib/SQL/Translator/Parser/xSV.pm index d270d62..e243945 100644 --- a/lib/SQL/Translator/Parser/xSV.pm +++ b/lib/SQL/Translator/Parser/xSV.pm @@ -1,25 +1,5 @@ package SQL::Translator::Parser::xSV; -# ------------------------------------------------------------------- -# $Id: xSV.pm,v 1.16 2004-02-09 22:23:40 kycl4rk Exp $ -# ------------------------------------------------------------------- -# Copyright (C) 2002-4 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 @@ -36,7 +16,7 @@ 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, C). Other arguments include: @@ -52,22 +32,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 +Field names will automatically be normalized by C. =cut -# ------------------------------------------------------------------- - use strict; use vars qw($VERSION @EXPORT); -$VERSION = sprintf "%d.%02d", q$Revision: 1.16 $ =~ /(\d+)\.(\d+)/; +$VERSION = '1.59'; use Exporter; use Text::ParseWords qw(quotewords); @@ -90,7 +68,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; @@ -121,7 +99,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 ) { @@ -135,15 +113,15 @@ 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 ) = + my ( $w, $d ) = map { s/,//g; length $_ || 1 } split( /\./, $data ); $size = [ $w + $d, $d ]; } @@ -165,8 +143,8 @@ sub parse { 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'; @@ -185,7 +163,6 @@ sub parse { 1; -# ------------------------------------------------------------------- =pod =head1 AUTHORS