Revision 90af0ce7
Von Sven Schöling vor mehr als 13 Jahren hinzugefügt
SL/Helper/Csv/Dispatcher.pm | ||
---|---|---|
32 | 32 |
return unless $value; |
33 | 33 |
|
34 | 34 |
for my $step (@{ $spec->{steps} }) { |
35 |
my ($acc, $class) = @$step; |
|
35 |
my ($acc, $class, $index) = @$step;
|
|
36 | 36 |
if ($class) { |
37 |
|
|
38 |
# autovifify |
|
37 | 39 |
eval "require $class; 1" or die "could not load class '$class'"; |
38 |
$obj->$acc($class->new) if ! $obj->$acc; |
|
39 |
$obj = $obj->$acc; |
|
40 |
if (defined $index) { |
|
41 |
if (! $obj->$acc || !$obj->$acc->[$index]) { |
|
42 |
my @objects = $obj->$acc; |
|
43 |
$obj->$acc(@objects, map { $class->new } 0 .. $index - @objects); |
|
44 |
} |
|
45 |
$obj = $obj->$acc->[$index]; |
|
46 |
} else { |
|
47 |
if (! $obj->$acc) { |
|
48 |
$obj->$acc($class->new); |
|
49 |
} |
|
50 |
$obj = $obj->$acc; |
|
51 |
} |
|
52 |
|
|
40 | 53 |
} else { |
41 | 54 |
$obj->$acc($value); |
42 | 55 |
} |
... | ... | |
71 | 84 |
my $spec = { key => $col, steps => [] }; |
72 | 85 |
my $cur_class = $self->_csv->class; |
73 | 86 |
|
74 |
for my $step ( split /\./, $path ) { |
|
87 |
for my $step_index ( split /\.(?!\d)/, $path ) { |
|
88 |
my ($step, $index) = split /\./, $step_index; |
|
75 | 89 |
if ($cur_class->can($step)) { |
76 | 90 |
if ($cur_class->meta->relationship($step)) { #a |
77 | 91 |
my $next_class = $cur_class->meta->relationship($step)->class; |
78 |
push @{ $spec->{steps} }, [ $step, $next_class ]; |
|
92 |
push @{ $spec->{steps} }, [ $step, $next_class, $index ];
|
|
79 | 93 |
$cur_class = $next_class; |
80 | 94 |
} else { # simple dispatch |
81 | 95 |
push @{ $spec->{steps} }, [ $step ]; |
Auch abrufbar als: Unified diff
Multiple Dispatch - one-to-many.