Revision 7d9888e3
Von Sven Schöling vor mehr als 13 Jahren hinzugefügt
SL/Helper/Csv.pm | ||
---|---|---|
99 | 99 |
|
100 | 100 |
sub _check_header { |
101 | 101 |
my ($self, %params) = @_; |
102 |
return $self->header if $self->header;
|
|
102 |
my $header = $self->header;
|
|
103 | 103 |
|
104 |
my $header = $self->_csv->getline($self->_io); |
|
104 |
if (! $header) { |
|
105 |
$header = $self->_csv->getline($self->_io); |
|
105 | 106 |
|
106 |
$self->_push_error([ |
|
107 |
$self->_csv->error_input, |
|
108 |
$self->_csv->error_diag, |
|
109 |
0, |
|
110 |
]) unless $header; |
|
107 |
$self->_push_error([ |
|
108 |
$self->_csv->error_input, |
|
109 |
$self->_csv->error_diag, |
|
110 |
0, |
|
111 |
]) unless $header; |
|
112 |
} |
|
111 | 113 |
|
112 |
$self->header([ map { lc } @{ $header } ]); |
|
114 |
return unless $header; |
|
115 |
return $self->header([ map { lc } @$header ]); |
|
113 | 116 |
} |
114 | 117 |
|
115 | 118 |
sub _parse_data { |
t/helper/csv.t | ||
---|---|---|
1 |
use Test::More tests => 37;
|
|
1 |
use Test::More tests => 39;
|
|
2 | 2 |
use SL::Dispatcher; |
3 | 3 |
use Data::Dumper; |
4 | 4 |
use utf8; |
... | ... | |
274 | 274 |
$csv->parse; |
275 | 275 |
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'eol bug at the end of files'; |
276 | 276 |
|
277 |
##### |
|
278 |
|
|
279 |
$csv = SL::Helper::Csv->new( |
|
280 |
file => \"Description\nKaffee", |
|
281 |
class => 'SL::DB::Part', |
|
282 |
); |
|
283 |
$csv->parse; |
|
284 |
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header from csv works'; |
|
285 |
|
|
286 |
##### |
|
287 |
|
|
288 |
$csv = SL::Helper::Csv->new( |
|
289 |
file => \"Kaffee", |
|
290 |
header => [ 'Description' ], |
|
291 |
class => 'SL::DB::Part', |
|
292 |
); |
|
293 |
$csv->parse; |
|
294 |
is_deeply $csv->get_data, [ { description => 'Kaffee' } ], 'case insensitive header as param works'; |
|
295 |
|
|
277 | 296 |
# vim: ft=perl |
Auch abrufbar als: Unified diff
Case insensitive header waren nicht voll abgedeckt, und haben Fehler bei kaputten Headern unterdrückt.