X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FxSV.pm;h=3e199b21faa48ba99f1f3275bfe701884f524e37;hb=92638f3246feb6a2ce7f61b68086453755918b62;hp=7813a9a5fafdf5ee1d8a2d6e4dc9692442a40112;hpb=8545fe447903d6ae98927c11d945d1c0a6a0241a;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Parser/xSV.pm b/lib/SQL/Translator/Parser/xSV.pm index 7813a9a..3e199b2 100644 --- a/lib/SQL/Translator/Parser/xSV.pm +++ b/lib/SQL/Translator/Parser/xSV.pm @@ -1,26 +1,5 @@ package SQL::Translator::Parser::xSV; -# ------------------------------------------------------------------- -# $Id: xSV.pm,v 1.13 2003-10-10 15:59:03 kycl4rk Exp $ -# ------------------------------------------------------------------- -# Copyright (C) 2003 Ken Y. Clark , -# darren chamberlain -# -# 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 @@ -37,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: @@ -53,22 +32,21 @@ 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.13 $ =~ /(\d+)\.(\d+)/; +use warnings; +our @EXPORT; +our $VERSION = '1.59'; use Exporter; use Text::ParseWords qw(quotewords); @@ -91,7 +69,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; @@ -122,7 +100,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 ) { @@ -136,16 +114,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, length $d ]; + my ( $w, $d ) = + map { s/,//g; length $_ || 1 } split( /\./, $data ); + $size = [ $w + $d, $d ]; } else { $type = 'char'; @@ -164,10 +143,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 ); @@ -180,10 +164,9 @@ sub parse { 1; -# ------------------------------------------------------------------- =pod -=head1 AUTHOR +=head1 AUTHORS Darren Chamberlain Edarren@cpan.orgE, Ken Y. Clark Ekclark@cpan.orgE.