sub _parse_profile {
my ($self, %params) = @_;
- my $profile = $params{profile};
+ my $profile = $params{profile} // {};
my $class = $params{class};
my $header = $params{header};
my $mapping = $params{mapping};
next unless $col;
if (exists $mapping->{$col} && $profile->{$mapping->{$col}}) {
push @specs, $self->make_spec($col, $profile->{$mapping->{$col}}, $class);
- } elsif (exists $mapping->{$col}) {
+ } elsif (exists $mapping->{$col} && !%{ $profile }) {
push @specs, $self->make_spec($col, $mapping->{$col}, $class);
} elsif (exists $profile->{$col}) {
push @specs, $self->make_spec($col, $profile->{$col}, $class);
-use Test::More tests => 84;
+use Test::More tests => 86;
use lib 't';
use utf8;
is $csv->get_objects->[0]->sellprice, 4.99, 'case insensitive mapping with profile works';
+# self-mapping with profile
+$csv = SL::Helper::Csv->new(
+ file => \"sellprice\n4,99", # " # make emacs happy
+ case_insensitive_header => 1,
+ profile => [{
+ profile => { sellprice => 'sellprice_as_number' },
+ mapping => { sellprice => 'sellprice' },
+ class => 'SL::DB::Part',
+ }],
+);
+$csv->parse;
+is $csv->get_objects->[0]->sellprice, 4.99, 'self-mapping with profile works';
+
+# self-mapping without profile
+$csv = SL::Helper::Csv->new(
+ file => \"sellprice\n4.99", # " # make emacs happy
+ case_insensitive_header => 1,
+ profile => [{
+ mapping => { sellprice => 'sellprice' },
+ class => 'SL::DB::Part',
+ }],
+);
+$csv->parse;
+is $csv->get_objects->[0]->sellprice, 4.99, 'self-mapping without profile works';
+
# vim: ft=perl
# set emacs to perl mode
# Local Variables:
# mode: perl
# End:
-