From: Sven Schöling Date: Tue, 22 Feb 2011 11:22:29 +0000 (+0100) Subject: dispatch -> profile. ausserdem mehr errorchecking. X-Git-Tag: release-2.7.0beta1~396^2~79 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=62add698fd647e1a26916c3456b405b1f3619f14;p=kivitendo-erp.git dispatch -> profile. ausserdem mehr errorchecking. --- diff --git a/SL/Helper/Csv.pm b/SL/Helper/Csv.pm index be4e9145b..621d13aa8 100644 --- a/SL/Helper/Csv.pm +++ b/SL/Helper/Csv.pm @@ -8,7 +8,7 @@ use IO::File; use Text::CSV; use Params::Validate qw(:all); use Rose::Object::MakeMethods::Generic scalar => [ qw( - file encoding sep_char quote_char escape_char header dispatch class + file encoding sep_char quote_char escape_char header profile class numberformat dateformat _io _csv _objects _parsed _data _errors ) ]; @@ -22,7 +22,7 @@ sub new { quote_char => { default => '"' }, escape_char => { default => '"' }, header => { type => ARRAYREF, optional => 1 }, - dispatch => { type => HASHREF, optional => 1 }, + profile => { type => HASHREF, optional => 1 }, file => 1, encoding => 0, class => 0, @@ -97,6 +97,12 @@ sub _check_header { my $header = $self->_csv->getline($self->_io); + $self->_push_error([ + $self->_csv->error_input, + $self->_csv->error_diag, + 0, + ]) unless $header; + $self->header($header); } @@ -178,7 +184,7 @@ sub _make_objects { sub _real_method { my ($self, $arg) = @_; - ($self->dispatch && $self->dispatch->{$arg}) || $arg; + ($self->profile && $self->profile->{$arg}) || $arg; } sub _guess_encoding { @@ -213,7 +219,7 @@ SL::Helper::Csv - take care of csv file uploads sep_char => ',', # default ';' quote_char => ''', # default '"' header => [qw(id text sellprice word)] # see later - dispatch => { sellprice => 'sellprice_as_number' } + profile => { sellprice => 'sellprice_as_number' } class => 'SL::DB::CsvLine', # if present, map lines to this ) @@ -288,7 +294,7 @@ Same as in L Can be an array of columns, in this case the first line is not used as a header. Empty header fields will be ignored in objects. -=item C \%ACCESSORS +=item C \%ACCESSORS May be used to map header fields to custom accessors. Example: @@ -342,7 +348,7 @@ Dispatch to child objects, like this: $csv = SL::Helper::Csv->new( file => ... class => SL::DB::Part, - dispatch => [ + profile => [ makemodel => { make_1 => make, model_1 => model,