Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a54fc392

Von Sven Schöling vor etwa 12 Jahren hinzugefügt

  • ID a54fc3925496fe0cda2c6ba6d4a8d748d0035a50
  • Vorgänger 81fed283
  • Nachfolger f01bf635

Helper::Csv: Support für leere profile.path Angaben und case_insensitive_header

Unterschiede anzeigen:

SL/Helper/Csv.pm
10 10
use Rose::Object::MakeMethods::Generic scalar => [ qw(
11 11
  file encoding sep_char quote_char escape_char header profile class
12 12
  numberformat dateformat ignore_unknown_columns strict_profile _io _csv
13
  _objects _parsed _data _errors
13
  _objects _parsed _data _errors all_cvar_configs case_insensitive_header
14 14
) ];
15 15

  
16 16
use SL::Helper::Csv::Dispatcher;
......
33 33
    dateformat             => 0,
34 34
    ignore_unknown_columns => 0,
35 35
    strict_profile         => 0,
36
    case_insensitive_header => 0,
36 37
  });
37 38
  my $self = bless {}, $class;
38 39

  
......
120 121
  }
121 122

  
122 123
  return unless $header;
123
  return $self->header([ map { lc } @$header ]);
124

  
125
  # Special case: human stupidity
126
  # people insist that case sensitivity doesn't exist and try to enter all
127
  # sorts of stuff. at this point we've got a profile (with keys that represent
128
  # valid methods), and a header full of strings. if two of them match, the user
129
  # mopst likely meant that field, so rewrite the header
130
  if ($self->case_insensitive_header) {
131
    die 'case_insensitive_header is only possible with profile' unless $self->profile;
132
    my @names = (
133
      keys %{ $self->profile || {} },
134
    );
135
    for my $name (@names) {
136
      for my $i (0..$#$header) {
137
        $header->[$i] = $name if lc $header->[$i] eq lc $name;
138
      }
139
    }
140
  }
141

  
142
  return $self->header($header);
124 143
}
125 144

  
126 145
sub _parse_data {
......
345 364
will have to do that for yourself. Since you provided the profile, it is
346 365
assumed you know what to do in this case.
347 366

  
367
If no profile is given, any header field found will be taken as is.
368

  
369
If the path in a profile entry is empty, the field will be subjected to
370
C<strict_profile> and C<case_insensitive_header> checking, will be parsed into
371
C<get_data>, but will not be attempted to be dispatched into objects.
372

  
348 373
=item C<class>
349 374

  
350 375
If present, the line will be handed to the new sub of this class,
......
355 380
If set, the import will ignore unkown header columns. Useful for lazy imports,
356 381
but deactivated by default.
357 382

  
383
=item C<case_insensitive_header>
384

  
385
If set, header columns will be matched against profile entries case
386
insensitive, and on match the profile name will be taken.
387

  
388
Only works if a profile is given, will die otherwise.
389

  
390
If both C<case_insensitive_header> and C<strict_profile> is set, matched header
391
columns will be accepted.
392

  
358 393
=item C<strict_profile>
359 394

  
360 395
If set, all columns to be parsed must be specified in C<profile>. Every header
361 396
field not listed there will be treated like an unknown column.
362 397

  
398
If both C<case_insensitive_header> and C<strict_profile> is set, matched header
399
columns will be accepted.
400

  
363 401
=back
364 402

  
365 403
=head1 ERROR HANDLING

Auch abrufbar als: Unified diff