projects
/
kivitendo-erp.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f9f7b56
)
dispatch -> profile. ausserdem mehr errorchecking.
author
Sven Schöling
<s.schoeling@linet-services.de>
Tue, 22 Feb 2011 11:22:29 +0000
(12:22 +0100)
committer
Moritz Bunkus
<m.bunkus@linet-services.de>
Thu, 16 Jun 2011 06:43:58 +0000
(08:43 +0200)
SL/Helper/Csv.pm
patch
|
blob
|
history
diff --git
a/SL/Helper/Csv.pm
b/SL/Helper/Csv.pm
index
be4e914
..
621d13a
100644
(file)
--- 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(
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
) ];
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 },
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,
file => 1,
encoding => 0,
class => 0,
@@
-97,6
+97,12
@@
sub _check_header {
my $header = $self->_csv->getline($self->_io);
my $header = $self->_csv->getline($self->_io);
+ $self->_push_error([
+ $self->_csv->error_input,
+ $self->_csv->error_diag,
+ 0,
+ ]) unless $header;
+
$self->header($header);
}
$self->header($header);
}
@@
-178,7
+184,7
@@
sub _make_objects {
sub _real_method {
my ($self, $arg) = @_;
sub _real_method {
my ($self, $arg) = @_;
- ($self->
dispatch && $self->dispatch
->{$arg}) || $arg;
+ ($self->
profile && $self->profile
->{$arg}) || $arg;
}
sub _guess_encoding {
}
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
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
)
class => 'SL::DB::CsvLine', # if present, map lines to this
)
@@
-288,7
+294,7
@@
Same as in L<Text::CSV>
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.
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<
dispatch
> \%ACCESSORS
+=item C<
profile
> \%ACCESSORS
May be used to map header fields to custom accessors. Example:
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,
$csv = SL::Helper::Csv->new(
file => ...
class => SL::DB::Part,
-
dispatch
=> [
+
profile
=> [
makemodel => {
make_1 => make,
model_1 => model,
makemodel => {
make_1 => make,
model_1 => model,